| OLD | NEW | 
|    1 // Copyright 2014 The Chromium Authors. All rights reserved. |    1 // Copyright 2014 The Chromium Authors. All rights reserved. | 
|    2 // Use of this source code is governed by a BSD-style license that can be |    2 // Use of this source code is governed by a BSD-style license that can be | 
|    3 // found in the LICENSE file. |    3 // found in the LICENSE file. | 
|    4  |    4  | 
|    5 #include "services/service_manager/public/cpp/service_context.h" |    5 #include "services/service_manager/public/cpp/service_context.h" | 
|    6  |    6  | 
|    7 #include <utility> |    7 #include <utility> | 
|    8  |    8  | 
|    9 #include "base/bind.h" |    9 #include "base/bind.h" | 
|   10 #include "base/callback_helpers.h" |   10 #include "base/callback_helpers.h" | 
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|   44  |   44  | 
|   45 ServiceContext::~ServiceContext() {} |   45 ServiceContext::~ServiceContext() {} | 
|   46  |   46  | 
|   47 void ServiceContext::SetConnectionLostClosure(const base::Closure& closure) { |   47 void ServiceContext::SetConnectionLostClosure(const base::Closure& closure) { | 
|   48   connection_lost_closure_ = closure; |   48   connection_lost_closure_ = closure; | 
|   49   if (service_quit_) |   49   if (service_quit_) | 
|   50     QuitNow(); |   50     QuitNow(); | 
|   51 } |   51 } | 
|   52  |   52  | 
|   53 void ServiceContext::RequestQuit() { |   53 void ServiceContext::RequestQuit() { | 
|   54   DCHECK(service_control_.is_bound()); |   54   // TODO(rockot): Implement this. | 
|   55   service_control_->RequestQuit(); |  | 
|   56 } |   55 } | 
|   57  |   56  | 
|   58 void ServiceContext::DisconnectFromServiceManager() { |   57 void ServiceContext::DisconnectFromServiceManager() { | 
|   59   if (binding_.is_bound()) |   58   if (binding_.is_bound()) | 
|   60     binding_.Close(); |   59     binding_.Close(); | 
|   61   connector_.reset(); |   60   connector_.reset(); | 
|   62 } |   61 } | 
|   63  |   62  | 
|   64 void ServiceContext::QuitNow() { |   63 void ServiceContext::QuitNow() { | 
|   65   if (binding_.is_bound()) |   64   if (binding_.is_bound()) | 
|   66     binding_.Close(); |   65     binding_.Close(); | 
|   67   if (!connection_lost_closure_.is_null()) |   66   if (!connection_lost_closure_.is_null()) | 
|   68     base::ResetAndReturn(&connection_lost_closure_).Run(); |   67     base::ResetAndReturn(&connection_lost_closure_).Run(); | 
|   69 } |   68 } | 
|   70  |   69  | 
|   71 void ServiceContext::DestroyService() { |   70 void ServiceContext::DestroyService() { | 
|   72   QuitNow(); |   71   QuitNow(); | 
|   73   service_.reset(); |   72   service_.reset(); | 
|   74 } |   73 } | 
|   75  |   74  | 
|   76 //////////////////////////////////////////////////////////////////////////////// |   75 //////////////////////////////////////////////////////////////////////////////// | 
|   77 // ServiceContext, mojom::Service implementation: |   76 // ServiceContext, mojom::Service implementation: | 
|   78  |   77  | 
|   79 void ServiceContext::OnStart(const ServiceInfo& info, |   78 void ServiceContext::OnStart(const ServiceInfo& info, | 
|   80                              const OnStartCallback& callback) { |   79                              const OnStartCallback& callback) { | 
|   81   local_info_ = info; |   80   local_info_ = info; | 
|   82   callback.Run(std::move(pending_connector_request_), |   81   callback.Run(std::move(pending_connector_request_)); | 
|   83                mojo::GetProxy(&service_control_, binding_.associated_group())); |  | 
|   84   service_->OnStart(this); |   82   service_->OnStart(this); | 
|   85 } |   83 } | 
|   86  |   84  | 
|   87 void ServiceContext::OnConnect( |   85 void ServiceContext::OnConnect( | 
|   88     const ServiceInfo& source_info, |   86     const ServiceInfo& source_info, | 
|   89     mojom::InterfaceProviderRequest interfaces, |   87     mojom::InterfaceProviderRequest interfaces) { | 
|   90     const OnConnectCallback& callback) { |  | 
|   91   InterfaceProviderSpec source_spec, target_spec; |   88   InterfaceProviderSpec source_spec, target_spec; | 
|   92   GetInterfaceProviderSpec(mojom::kServiceManager_ConnectorSpec, |   89   GetInterfaceProviderSpec(mojom::kServiceManager_ConnectorSpec, | 
|   93                            local_info_.interface_provider_specs, &target_spec); |   90                            local_info_.interface_provider_specs, &target_spec); | 
|   94   GetInterfaceProviderSpec(mojom::kServiceManager_ConnectorSpec, |   91   GetInterfaceProviderSpec(mojom::kServiceManager_ConnectorSpec, | 
|   95                            source_info.interface_provider_specs, &source_spec); |   92                            source_info.interface_provider_specs, &source_spec); | 
|   96   auto registry = |   93   auto registry = | 
|   97       base::MakeUnique<InterfaceRegistry>(mojom::kServiceManager_ConnectorSpec); |   94       base::MakeUnique<InterfaceRegistry>(mojom::kServiceManager_ConnectorSpec); | 
|   98   registry->Bind(std::move(interfaces), local_info_.identity, target_spec, |   95   registry->Bind(std::move(interfaces), local_info_.identity, target_spec, | 
|   99                  source_info.identity, source_spec); |   96                  source_info.identity, source_spec); | 
|  100  |   97  | 
|  101   // Acknowledge the request regardless of whether it's accepted. |  | 
|  102   callback.Run(); |  | 
|  103  |  | 
|  104   if (!service_->OnConnect(source_info, registry.get())) |   98   if (!service_->OnConnect(source_info, registry.get())) | 
|  105     return; |   99     return; | 
|  106  |  100  | 
|  107   InterfaceRegistry* raw_registry = registry.get(); |  101   InterfaceRegistry* raw_registry = registry.get(); | 
|  108   registry->AddConnectionLostClosure(base::Bind( |  102   registry->AddConnectionLostClosure(base::Bind( | 
|  109       &ServiceContext::OnRegistryConnectionError, base::Unretained(this), |  103       &ServiceContext::OnRegistryConnectionError, base::Unretained(this), | 
|  110       raw_registry)); |  104       raw_registry)); | 
|  111   connection_interface_registries_.insert( |  105   connection_interface_registries_.insert( | 
|  112       std::make_pair(raw_registry, std::move(registry))); |  106       std::make_pair(raw_registry, std::move(registry))); | 
|  113 } |  107 } | 
| (...skipping 28 matching lines...) Expand all  Loading... | 
|  142 } |  136 } | 
|  143  |  137  | 
|  144 void ServiceContext::DestroyConnectionInterfaceRegistry( |  138 void ServiceContext::DestroyConnectionInterfaceRegistry( | 
|  145     InterfaceRegistry* registry) { |  139     InterfaceRegistry* registry) { | 
|  146   auto it = connection_interface_registries_.find(registry); |  140   auto it = connection_interface_registries_.find(registry); | 
|  147   CHECK(it != connection_interface_registries_.end()); |  141   CHECK(it != connection_interface_registries_.end()); | 
|  148   connection_interface_registries_.erase(it); |  142   connection_interface_registries_.erase(it); | 
|  149 } |  143 } | 
|  150  |  144  | 
|  151 }  // namespace service_manager |  145 }  // namespace service_manager | 
| OLD | NEW |