Chromium Code Reviews| Index: services/service_manager/public/cpp/connector.cc |
| diff --git a/services/service_manager/public/cpp/lib/connector_impl.cc b/services/service_manager/public/cpp/connector.cc |
| similarity index 56% |
| rename from services/service_manager/public/cpp/lib/connector_impl.cc |
| rename to services/service_manager/public/cpp/connector.cc |
| index 4549e5cc33fb3323ce5ae6f8eda763550382a72c..7c1e77dad36870d92de482558a9f644ad57e256b 100644 |
| --- a/services/service_manager/public/cpp/lib/connector_impl.cc |
| +++ b/services/service_manager/public/cpp/connector.cc |
| @@ -1,47 +1,50 @@ |
| -// Copyright 2016 The Chromium Authors. All rights reserved. |
| +// 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/service_manager/public/cpp/lib/connector_impl.h" |
| +#include "services/service_manager/public/cpp/connector.h" |
| #include "base/memory/ptr_util.h" |
| #include "services/service_manager/public/cpp/identity.h" |
| namespace service_manager { |
| -ConnectorImpl::ConnectorImpl(mojom::ConnectorPtrInfo unbound_state) |
| +//////////////////////////////////////////////////////////////////////////////// |
| +// Connector, public: |
|
Ken Rockot(use gerrit already)
2017/05/04 03:53:34
nit: I'd kinda prefer to omit comments like this u
|
| + |
| +Connector::Connector(mojom::ConnectorPtrInfo unbound_state) |
| : unbound_state_(std::move(unbound_state)), weak_factory_(this) { |
| thread_checker_.DetachFromThread(); |
| } |
| -ConnectorImpl::ConnectorImpl(mojom::ConnectorPtr connector) |
| +Connector::Connector(mojom::ConnectorPtr connector) |
| : connector_(std::move(connector)), weak_factory_(this) { |
| connector_.set_connection_error_handler( |
| - base::Bind(&ConnectorImpl::OnConnectionError, base::Unretained(this))); |
| + base::Bind(&Connector::OnConnectionError, base::Unretained(this))); |
| } |
| -ConnectorImpl::~ConnectorImpl() {} |
| +Connector::~Connector() = default; |
| -void ConnectorImpl::OnConnectionError() { |
| - DCHECK(thread_checker_.CalledOnValidThread()); |
| - connector_.reset(); |
| +std::unique_ptr<Connector> Connector::Create(mojom::ConnectorRequest* request) { |
| + mojom::ConnectorPtr proxy; |
| + *request = mojo::MakeRequest(&proxy); |
| + return base::MakeUnique<Connector>(proxy.PassInterface()); |
| } |
| -void ConnectorImpl::StartService(const Identity& identity) { |
| +void Connector::StartService(const Identity& identity) { |
| if (BindConnectorIfNecessary()) |
| connector_->StartService(identity, |
| - base::Bind(&ConnectorImpl::StartServiceCallback, |
| + base::Bind(&Connector::RunStartServiceCallback, |
| weak_factory_.GetWeakPtr())); |
| } |
| -void ConnectorImpl::StartService(const std::string& name) { |
| +void Connector::StartService(const std::string& name) { |
| StartService(Identity(name, mojom::kInheritUserID)); |
| } |
| -void ConnectorImpl::StartService( |
| - const Identity& identity, |
| - mojom::ServicePtr service, |
| - mojom::PIDReceiverRequest pid_receiver_request) { |
| +void Connector::StartService(const Identity& identity, |
| + mojom::ServicePtr service, |
| + mojom::PIDReceiverRequest pid_receiver_request) { |
| if (!BindConnectorIfNecessary()) |
| return; |
| @@ -49,14 +52,13 @@ void ConnectorImpl::StartService( |
| connector_->StartServiceWithProcess( |
| identity, service.PassInterface().PassHandle(), |
| std::move(pid_receiver_request), |
| - base::Bind(&ConnectorImpl::StartServiceCallback, |
| + base::Bind(&Connector::RunStartServiceCallback, |
| weak_factory_.GetWeakPtr())); |
| } |
| -void ConnectorImpl::BindInterface( |
| - const Identity& target, |
| - const std::string& interface_name, |
| - mojo::ScopedMessagePipeHandle interface_pipe) { |
| +void Connector::BindInterface(const Identity& target, |
| + const std::string& interface_name, |
| + mojo::ScopedMessagePipeHandle interface_pipe) { |
| if (!BindConnectorIfNecessary()) |
| return; |
| @@ -70,60 +72,68 @@ void ConnectorImpl::BindInterface( |
| } |
| connector_->BindInterface(target, interface_name, std::move(interface_pipe), |
| - base::Bind(&ConnectorImpl::StartServiceCallback, |
| + base::Bind(&Connector::RunStartServiceCallback, |
| weak_factory_.GetWeakPtr())); |
| } |
| -std::unique_ptr<Connector> ConnectorImpl::Clone() { |
| +std::unique_ptr<Connector> Connector::Clone() { |
| if (!BindConnectorIfNecessary()) |
| return nullptr; |
| mojom::ConnectorPtr connector; |
| mojom::ConnectorRequest request(&connector); |
| connector_->Clone(std::move(request)); |
| - return base::MakeUnique<ConnectorImpl>(connector.PassInterface()); |
| + return base::MakeUnique<Connector>(connector.PassInterface()); |
| } |
| -void ConnectorImpl::FilterInterfaces(const std::string& spec, |
| - const Identity& source_identity, |
| - mojom::InterfaceProviderRequest request, |
| - mojom::InterfaceProviderPtr target) { |
| +void Connector::FilterInterfaces(const std::string& spec, |
| + const Identity& source_identity, |
| + mojom::InterfaceProviderRequest request, |
| + mojom::InterfaceProviderPtr target) { |
| if (!BindConnectorIfNecessary()) |
| return; |
| connector_->FilterInterfaces(spec, source_identity, std::move(request), |
| std::move(target)); |
| } |
| -void ConnectorImpl::BindConnectorRequest(mojom::ConnectorRequest request) { |
| +void Connector::BindConnectorRequest(mojom::ConnectorRequest request) { |
| if (!BindConnectorIfNecessary()) |
| return; |
| connector_->Clone(std::move(request)); |
| } |
| -base::WeakPtr<Connector> ConnectorImpl::GetWeakPtr() { |
| +base::WeakPtr<Connector> Connector::GetWeakPtr() { |
| return weak_factory_.GetWeakPtr(); |
| } |
| -void ConnectorImpl::OverrideBinderForTesting(const std::string& service_name, |
| - const std::string& interface_name, |
| - const TestApi::Binder& binder) { |
| +//////////////////////////////////////////////////////////////////////////////// |
| +// Connector, private: |
| + |
| +void Connector::OnConnectionError() { |
| + DCHECK(thread_checker_.CalledOnValidThread()); |
| + connector_.reset(); |
| +} |
| + |
| +void Connector::OverrideBinderForTesting(const std::string& service_name, |
| + const std::string& interface_name, |
| + const TestApi::Binder& binder) { |
| local_binder_overrides_[service_name][interface_name] = binder; |
| } |
| -void ConnectorImpl::ClearBinderOverrides() { |
| +void Connector::ClearBinderOverrides() { |
| local_binder_overrides_.clear(); |
| } |
| -void ConnectorImpl::SetStartServiceCallback( |
| +void Connector::SetStartServiceCallback( |
| const Connector::StartServiceCallback& callback) { |
| start_service_callback_ = callback; |
| } |
| -void ConnectorImpl::ResetStartServiceCallback() { |
| +void Connector::ResetStartServiceCallback() { |
| start_service_callback_.Reset(); |
| } |
| -bool ConnectorImpl::BindConnectorIfNecessary() { |
| +bool Connector::BindConnectorIfNecessary() { |
| // Bind this object to the current thread the first time it is used to |
| // connect. |
| if (!connector_.is_bound()) { |
| @@ -140,22 +150,16 @@ bool ConnectorImpl::BindConnectorIfNecessary() { |
| connector_.Bind(std::move(unbound_state_)); |
| connector_.set_connection_error_handler( |
| - base::Bind(&ConnectorImpl::OnConnectionError, base::Unretained(this))); |
| + base::Bind(&Connector::OnConnectionError, base::Unretained(this))); |
| } |
| return true; |
| } |
| -void ConnectorImpl::StartServiceCallback(mojom::ConnectResult result, |
| - const Identity& user_id) { |
| +void Connector::RunStartServiceCallback(mojom::ConnectResult result, |
| + const Identity& user_id) { |
| if (!start_service_callback_.is_null()) |
| start_service_callback_.Run(result, user_id); |
| } |
| -std::unique_ptr<Connector> Connector::Create(mojom::ConnectorRequest* request) { |
| - mojom::ConnectorPtr proxy; |
| - *request = mojo::MakeRequest(&proxy); |
| - return base::MakeUnique<ConnectorImpl>(proxy.PassInterface()); |
| -} |
| - |
| } // namespace service_manager |