Index: content/common/service_manager/service_manager_connection_impl.cc |
diff --git a/content/common/service_manager/service_manager_connection_impl.cc b/content/common/service_manager/service_manager_connection_impl.cc |
index 0ba66da6f680fe94ec9ea2fe8625635a6cce106c..d8a69f1e60ca02472f67e4ba033ad984c4d8daa6 100644 |
--- a/content/common/service_manager/service_manager_connection_impl.cc |
+++ b/content/common/service_manager/service_manager_connection_impl.cc |
@@ -65,14 +65,17 @@ class ServiceManagerConnectionImpl::IOThreadContext |
} |
// Safe to call from any thread. |
- void Start(const InitializeCallback& initialize_callback, |
- const ServiceFactoryCallback& create_service_callback, |
- const base::Closure& stop_callback) { |
+ void Start( |
+ const InitializeCallback& initialize_callback, |
+ const ServiceManagerConnection::OnConnectHandler& on_connect_callback, |
+ const ServiceFactoryCallback& create_service_callback, |
+ const base::Closure& stop_callback) { |
DCHECK(!started_); |
started_ = true; |
callback_task_runner_ = base::ThreadTaskRunnerHandle::Get(); |
initialize_handler_ = initialize_callback; |
+ on_connect_callback_ = on_connect_callback; |
create_service_callback_ = create_service_callback; |
stop_callback_ = stop_callback; |
io_task_runner_->PostTask( |
@@ -221,15 +224,20 @@ class ServiceManagerConnectionImpl::IOThreadContext |
void OnStart(const service_manager::ServiceInfo& info) override { |
DCHECK(io_thread_checker_.CalledOnValidThread()); |
DCHECK(!initialize_handler_.is_null()); |
- id_ = info.identity; |
+ local_info_ = info; |
InitializeCallback handler = base::ResetAndReturn(&initialize_handler_); |
- callback_task_runner_->PostTask(FROM_HERE, base::Bind(handler, id_)); |
+ callback_task_runner_->PostTask(FROM_HERE, |
+ base::Bind(handler, local_info_.identity)); |
} |
bool OnConnect(const service_manager::ServiceInfo& remote_info, |
service_manager::InterfaceRegistry* registry) override { |
DCHECK(io_thread_checker_.CalledOnValidThread()); |
+ |
+ callback_task_runner_->PostTask( |
+ FROM_HERE, base::Bind(on_connect_callback_, local_info_, remote_info)); |
+ |
std::string remote_service = remote_info.identity.name(); |
if (remote_service == "service:service_manager") { |
// Only expose the ServiceFactory interface to the Service Manager. |
@@ -312,6 +320,9 @@ class ServiceManagerConnectionImpl::IOThreadContext |
// Callback to run once Service::OnStart is invoked. |
InitializeCallback initialize_handler_; |
+ // Callback to run when a connection request is received. |
+ ServiceManagerConnection::OnConnectHandler on_connect_callback_; |
+ |
// Callback to run when a new Service request is received. |
ServiceFactoryCallback create_service_callback_; |
@@ -322,7 +333,7 @@ class ServiceManagerConnectionImpl::IOThreadContext |
// default binder (below) has been set up. |
bool has_browser_connection_ = false; |
- service_manager::Identity id_; |
+ service_manager::ServiceInfo local_info_; |
// Default binder callback used for the browser connection's |
// InterfaceRegistry. |
@@ -414,6 +425,8 @@ void ServiceManagerConnectionImpl::Start() { |
context_->Start( |
base::Bind(&ServiceManagerConnectionImpl::OnContextInitialized, |
weak_factory_.GetWeakPtr()), |
+ base::Bind(&ServiceManagerConnectionImpl::OnConnect, |
+ weak_factory_.GetWeakPtr()), |
base::Bind(&ServiceManagerConnectionImpl::CreateService, |
weak_factory_.GetWeakPtr()), |
base::Bind(&ServiceManagerConnectionImpl::OnConnectionLost, |
@@ -480,6 +493,19 @@ void ServiceManagerConnectionImpl::AddServiceRequestHandler( |
DCHECK(result.second); |
} |
+int ServiceManagerConnectionImpl::AddOnConnectHandler( |
+ const OnConnectHandler& handler) { |
+ int id = ++next_on_connect_handler_id_; |
+ on_connect_handlers_[id] = handler; |
+ return id; |
+} |
+ |
+void ServiceManagerConnectionImpl::RemoveOnConnectHandler(int id) { |
+ auto it = on_connect_handlers_.find(id); |
+ DCHECK(it != on_connect_handlers_.end()); |
+ on_connect_handlers_.erase(it); |
+} |
+ |
void ServiceManagerConnectionImpl::CreateService( |
service_manager::mojom::ServiceRequest request, |
const std::string& name) { |
@@ -500,6 +526,14 @@ void ServiceManagerConnectionImpl::OnConnectionLost() { |
connection_lost_handler_.Run(); |
} |
+void ServiceManagerConnectionImpl::OnConnect( |
+ const service_manager::ServiceInfo& local_info, |
+ const service_manager::ServiceInfo& remote_info) { |
+ local_info_ = local_info; |
+ for (auto& handler : on_connect_handlers_) |
+ handler.second.Run(local_info, remote_info); |
+} |
+ |
void ServiceManagerConnectionImpl::GetInterface( |
service_manager::mojom::InterfaceProvider* provider, |
const std::string& interface_name, |