blob: eabcfb2c26f50bab67f04752993e9e314a5b1a07 [file] [log] [blame]
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "services/identity/identity_service.h"
#include <utility>
#include "base/bind.h"
#include "services/identity/identity_accessor_impl.h"
#include "services/identity/public/cpp/identity_manager.h"
namespace identity {
IdentityService::IdentityService(IdentityManager* identity_manager,
service_manager::mojom::ServiceRequest request)
: service_binding_(this, std::move(request)),
identity_manager_(identity_manager) {
registry_.AddInterface<mojom::IdentityAccessor>(
base::Bind(&IdentityService::Create, base::Unretained(this)));
}
IdentityService::~IdentityService() {
ShutDown();
}
void IdentityService::OnBindInterface(
const service_manager::BindSourceInfo& source_info,
const std::string& interface_name,
mojo::ScopedMessagePipeHandle interface_pipe) {
registry_.BindInterface(interface_name, std::move(interface_pipe));
}
void IdentityService::ShutDown() {
if (IsShutDown())
return;
identity_manager_ = nullptr;
}
bool IdentityService::IsShutDown() {
return (identity_manager_ == nullptr);
}
void IdentityService::Create(mojom::IdentityAccessorRequest request) {
// This instance cannot service requests if it has already been shut down.
if (IsShutDown())
return;
IdentityAccessorImpl::Create(std::move(request), identity_manager_);
}
} // namespace identity