| OLD | NEW | 
|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "content/common/service_manager/service_manager_connection_impl.h" | 5 #include "content/common/service_manager/service_manager_connection_impl.h" | 
| 6 | 6 | 
| 7 #include <queue> | 7 #include <queue> | 
| 8 #include <utility> | 8 #include <utility> | 
| 9 #include <vector> | 9 #include <vector> | 
| 10 | 10 | 
| (...skipping 21 matching lines...) Expand all  Loading... | 
| 32 | 32 | 
| 33 ServiceManagerConnection::Factory* service_manager_connection_factory = nullptr; | 33 ServiceManagerConnection::Factory* service_manager_connection_factory = nullptr; | 
| 34 | 34 | 
| 35 }  // namespace | 35 }  // namespace | 
| 36 | 36 | 
| 37 // A ref-counted object which owns the IO thread state of a | 37 // A ref-counted object which owns the IO thread state of a | 
| 38 // ServiceManagerConnectionImpl. This includes Service and ServiceFactory | 38 // ServiceManagerConnectionImpl. This includes Service and ServiceFactory | 
| 39 // bindings. | 39 // bindings. | 
| 40 class ServiceManagerConnectionImpl::IOThreadContext | 40 class ServiceManagerConnectionImpl::IOThreadContext | 
| 41     : public base::RefCountedThreadSafe<IOThreadContext>, | 41     : public base::RefCountedThreadSafe<IOThreadContext>, | 
| 42       public shell::Service, | 42       public service_manager::Service, | 
| 43       public shell::InterfaceFactory<shell::mojom::ServiceFactory>, | 43       public service_manager::InterfaceFactory< | 
| 44       public shell::mojom::ServiceFactory { | 44           service_manager::mojom::ServiceFactory>, | 
|  | 45       public service_manager::mojom::ServiceFactory { | 
| 45  public: | 46  public: | 
| 46   using InitializeCallback = base::Callback<void(const shell::Identity&)>; | 47   using InitializeCallback = | 
|  | 48       base::Callback<void(const service_manager::Identity&)>; | 
| 47   using ServiceFactoryCallback = | 49   using ServiceFactoryCallback = | 
| 48       base::Callback<void(shell::mojom::ServiceRequest, const std::string&)>; | 50       base::Callback<void(service_manager::mojom::ServiceRequest, | 
|  | 51                           const std::string&)>; | 
| 49 | 52 | 
| 50   IOThreadContext(shell::mojom::ServiceRequest service_request, | 53   IOThreadContext( | 
| 51                   scoped_refptr<base::SequencedTaskRunner> io_task_runner, | 54       service_manager::mojom::ServiceRequest service_request, | 
| 52                   std::unique_ptr<shell::Connector> io_thread_connector, | 55       scoped_refptr<base::SequencedTaskRunner> io_task_runner, | 
| 53                   shell::mojom::ConnectorRequest connector_request) | 56       std::unique_ptr<service_manager::Connector> io_thread_connector, | 
|  | 57       service_manager::mojom::ConnectorRequest connector_request) | 
| 54       : pending_service_request_(std::move(service_request)), | 58       : pending_service_request_(std::move(service_request)), | 
| 55         io_task_runner_(io_task_runner), | 59         io_task_runner_(io_task_runner), | 
| 56         io_thread_connector_(std::move(io_thread_connector)), | 60         io_thread_connector_(std::move(io_thread_connector)), | 
| 57         pending_connector_request_(std::move(connector_request)), | 61         pending_connector_request_(std::move(connector_request)), | 
| 58         weak_factory_(this) { | 62         weak_factory_(this) { | 
| 59     // This will be reattached by any of the IO thread functions on first call. | 63     // This will be reattached by any of the IO thread functions on first call. | 
| 60     io_thread_checker_.DetachFromThread(); | 64     io_thread_checker_.DetachFromThread(); | 
| 61   } | 65   } | 
| 62 | 66 | 
| 63   // Safe to call from any thread. | 67   // Safe to call from any thread. | 
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 102 | 106 | 
| 103   void RemoveConnectionFilter(int filter_id) { | 107   void RemoveConnectionFilter(int filter_id) { | 
| 104     io_task_runner_->PostTask( | 108     io_task_runner_->PostTask( | 
| 105         FROM_HERE, | 109         FROM_HERE, | 
| 106         base::Bind(&IOThreadContext::RemoveConnectionFilterOnIOThread, this, | 110         base::Bind(&IOThreadContext::RemoveConnectionFilterOnIOThread, this, | 
| 107                    filter_id)); | 111                    filter_id)); | 
| 108   } | 112   } | 
| 109 | 113 | 
| 110   // Safe to call any time before Start() is called. | 114   // Safe to call any time before Start() is called. | 
| 111   void SetDefaultBinderForBrowserConnection( | 115   void SetDefaultBinderForBrowserConnection( | 
| 112       const shell::InterfaceRegistry::Binder& binder) { | 116       const service_manager::InterfaceRegistry::Binder& binder) { | 
| 113     DCHECK(!started_); | 117     DCHECK(!started_); | 
| 114     default_browser_binder_ = base::Bind( | 118     default_browser_binder_ = base::Bind( | 
| 115         &IOThreadContext::CallBinderOnTaskRunner, | 119         &IOThreadContext::CallBinderOnTaskRunner, | 
| 116         base::ThreadTaskRunnerHandle::Get(), binder); | 120         base::ThreadTaskRunnerHandle::Get(), binder); | 
| 117   } | 121   } | 
| 118 | 122 | 
| 119  private: | 123  private: | 
| 120   friend class base::RefCountedThreadSafe<IOThreadContext>; | 124   friend class base::RefCountedThreadSafe<IOThreadContext>; | 
| 121 | 125 | 
| 122   class MessageLoopObserver : public base::MessageLoop::DestructionObserver { | 126   class MessageLoopObserver : public base::MessageLoop::DestructionObserver { | 
| (...skipping 30 matching lines...) Expand all  Loading... | 
| 153     base::WeakPtr<IOThreadContext> context_; | 157     base::WeakPtr<IOThreadContext> context_; | 
| 154 | 158 | 
| 155     DISALLOW_COPY_AND_ASSIGN(MessageLoopObserver); | 159     DISALLOW_COPY_AND_ASSIGN(MessageLoopObserver); | 
| 156   }; | 160   }; | 
| 157 | 161 | 
| 158   ~IOThreadContext() override {} | 162   ~IOThreadContext() override {} | 
| 159 | 163 | 
| 160   void StartOnIOThread() { | 164   void StartOnIOThread() { | 
| 161     // Should bind |io_thread_checker_| to the context's thread. | 165     // Should bind |io_thread_checker_| to the context's thread. | 
| 162     DCHECK(io_thread_checker_.CalledOnValidThread()); | 166     DCHECK(io_thread_checker_.CalledOnValidThread()); | 
| 163     service_context_.reset(new shell::ServiceContext( | 167     service_context_.reset(new service_manager::ServiceContext( | 
| 164         this, std::move(pending_service_request_), | 168         this, std::move(pending_service_request_), | 
| 165         std::move(io_thread_connector_), | 169         std::move(io_thread_connector_), | 
| 166         std::move(pending_connector_request_))); | 170         std::move(pending_connector_request_))); | 
| 167 | 171 | 
| 168     // MessageLoopObserver owns itself. | 172     // MessageLoopObserver owns itself. | 
| 169     message_loop_observer_ = | 173     message_loop_observer_ = | 
| 170         new MessageLoopObserver(weak_factory_.GetWeakPtr()); | 174         new MessageLoopObserver(weak_factory_.GetWeakPtr()); | 
| 171   } | 175   } | 
| 172 | 176 | 
| 173   void ShutDownOnIOThread() { | 177   void ShutDownOnIOThread() { | 
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 205     DCHECK(it != connection_filters_.end()); | 209     DCHECK(it != connection_filters_.end()); | 
| 206     connection_filters_.erase(it); | 210     connection_filters_.erase(it); | 
| 207   } | 211   } | 
| 208 | 212 | 
| 209   void OnBrowserConnectionLost() { | 213   void OnBrowserConnectionLost() { | 
| 210     DCHECK(io_thread_checker_.CalledOnValidThread()); | 214     DCHECK(io_thread_checker_.CalledOnValidThread()); | 
| 211     has_browser_connection_ = false; | 215     has_browser_connection_ = false; | 
| 212   } | 216   } | 
| 213 | 217 | 
| 214   ///////////////////////////////////////////////////////////////////////////// | 218   ///////////////////////////////////////////////////////////////////////////// | 
| 215   // shell::Service implementation | 219   // service_manager::Service implementation | 
| 216 | 220 | 
| 217   void OnStart(const shell::Identity& identity) override { | 221   void OnStart(const service_manager::Identity& identity) override { | 
| 218     DCHECK(io_thread_checker_.CalledOnValidThread()); | 222     DCHECK(io_thread_checker_.CalledOnValidThread()); | 
| 219     DCHECK(!initialize_handler_.is_null()); | 223     DCHECK(!initialize_handler_.is_null()); | 
| 220     id_ = identity; | 224     id_ = identity; | 
| 221 | 225 | 
| 222     InitializeCallback handler = base::ResetAndReturn(&initialize_handler_); | 226     InitializeCallback handler = base::ResetAndReturn(&initialize_handler_); | 
| 223     callback_task_runner_->PostTask(FROM_HERE, base::Bind(handler, identity)); | 227     callback_task_runner_->PostTask(FROM_HERE, base::Bind(handler, identity)); | 
| 224   } | 228   } | 
| 225 | 229 | 
| 226   bool OnConnect(const shell::Identity& remote_identity, | 230   bool OnConnect(const service_manager::Identity& remote_identity, | 
| 227                  shell::InterfaceRegistry* registry) override { | 231                  service_manager::InterfaceRegistry* registry) override { | 
| 228     DCHECK(io_thread_checker_.CalledOnValidThread()); | 232     DCHECK(io_thread_checker_.CalledOnValidThread()); | 
| 229     std::string remote_service = remote_identity.name(); | 233     std::string remote_service = remote_identity.name(); | 
| 230     if (remote_service == "service:shell") { | 234     if (remote_service == "service:shell") { | 
| 231       // Only expose the SCF interface to the shell. | 235       // Only expose the SCF interface to the shell. | 
| 232       registry->AddInterface<shell::mojom::ServiceFactory>(this); | 236       registry->AddInterface<service_manager::mojom::ServiceFactory>(this); | 
| 233       return true; | 237       return true; | 
| 234     } | 238     } | 
| 235 | 239 | 
| 236     bool accept = false; | 240     bool accept = false; | 
| 237     { | 241     { | 
| 238       base::AutoLock lock(lock_); | 242       base::AutoLock lock(lock_); | 
| 239       for (auto& entry : connection_filters_) { | 243       for (auto& entry : connection_filters_) { | 
| 240         accept |= entry.second->OnConnect(remote_identity, registry, | 244         accept |= entry.second->OnConnect(remote_identity, registry, | 
| 241                                           service_context_->connector()); | 245                                           service_context_->connector()); | 
| 242       } | 246       } | 
| (...skipping 12 matching lines...) Expand all  Loading... | 
| 255     return accept; | 259     return accept; | 
| 256   } | 260   } | 
| 257 | 261 | 
| 258   bool OnStop() override { | 262   bool OnStop() override { | 
| 259     ClearConnectionFiltersOnIOThread(); | 263     ClearConnectionFiltersOnIOThread(); | 
| 260     callback_task_runner_->PostTask(FROM_HERE, stop_callback_); | 264     callback_task_runner_->PostTask(FROM_HERE, stop_callback_); | 
| 261     return true; | 265     return true; | 
| 262   } | 266   } | 
| 263 | 267 | 
| 264   ///////////////////////////////////////////////////////////////////////////// | 268   ///////////////////////////////////////////////////////////////////////////// | 
| 265   // shell::InterfaceFactory<shell::mojom::ServiceFactory> implementation | 269   // service_manager::InterfaceFactory<service_manager::mojom::ServiceFactory> | 
|  | 270   // implementation | 
| 266 | 271 | 
| 267   void Create(const shell::Identity& remote_identity, | 272   void Create(const service_manager::Identity& remote_identity, | 
| 268               shell::mojom::ServiceFactoryRequest request) override { | 273               service_manager::mojom::ServiceFactoryRequest request) override { | 
| 269     DCHECK(io_thread_checker_.CalledOnValidThread()); | 274     DCHECK(io_thread_checker_.CalledOnValidThread()); | 
| 270     factory_bindings_.AddBinding(this, std::move(request)); | 275     factory_bindings_.AddBinding(this, std::move(request)); | 
| 271   } | 276   } | 
| 272 | 277 | 
| 273   ///////////////////////////////////////////////////////////////////////////// | 278   ///////////////////////////////////////////////////////////////////////////// | 
| 274   // shell::mojom::ServiceFactory implementation | 279   // service_manager::mojom::ServiceFactory implementation | 
| 275 | 280 | 
| 276   void CreateService(shell::mojom::ServiceRequest request, | 281   void CreateService(service_manager::mojom::ServiceRequest request, | 
| 277                      const std::string& name) override { | 282                      const std::string& name) override { | 
| 278     DCHECK(io_thread_checker_.CalledOnValidThread()); | 283     DCHECK(io_thread_checker_.CalledOnValidThread()); | 
| 279     callback_task_runner_->PostTask( | 284     callback_task_runner_->PostTask( | 
| 280         FROM_HERE, | 285         FROM_HERE, | 
| 281         base::Bind(create_service_callback_, base::Passed(&request), name)); | 286         base::Bind(create_service_callback_, base::Passed(&request), name)); | 
| 282   } | 287   } | 
| 283 | 288 | 
| 284   static void CallBinderOnTaskRunner( | 289   static void CallBinderOnTaskRunner( | 
| 285       scoped_refptr<base::SequencedTaskRunner> task_runner, | 290       scoped_refptr<base::SequencedTaskRunner> task_runner, | 
| 286       const shell::InterfaceRegistry::Binder& binder, | 291       const service_manager::InterfaceRegistry::Binder& binder, | 
| 287       const std::string& interface_name, | 292       const std::string& interface_name, | 
| 288       mojo::ScopedMessagePipeHandle request_handle) { | 293       mojo::ScopedMessagePipeHandle request_handle) { | 
| 289     task_runner->PostTask(FROM_HERE, base::Bind(binder, interface_name, | 294     task_runner->PostTask(FROM_HERE, base::Bind(binder, interface_name, | 
| 290                                                 base::Passed(&request_handle))); | 295                                                 base::Passed(&request_handle))); | 
| 291   } | 296   } | 
| 292 | 297 | 
| 293   base::ThreadChecker io_thread_checker_; | 298   base::ThreadChecker io_thread_checker_; | 
| 294   bool started_ = false; | 299   bool started_ = false; | 
| 295 | 300 | 
| 296   // Temporary state established on construction and consumed on the IO thread | 301   // Temporary state established on construction and consumed on the IO thread | 
| 297   // once the connection is started. | 302   // once the connection is started. | 
| 298   shell::mojom::ServiceRequest pending_service_request_; | 303   service_manager::mojom::ServiceRequest pending_service_request_; | 
| 299   scoped_refptr<base::SequencedTaskRunner> io_task_runner_; | 304   scoped_refptr<base::SequencedTaskRunner> io_task_runner_; | 
| 300   std::unique_ptr<shell::Connector> io_thread_connector_; | 305   std::unique_ptr<service_manager::Connector> io_thread_connector_; | 
| 301   shell::mojom::ConnectorRequest pending_connector_request_; | 306   service_manager::mojom::ConnectorRequest pending_connector_request_; | 
| 302 | 307 | 
| 303   // TaskRunner on which to run our owner's callbacks, i.e. the ones passed to | 308   // TaskRunner on which to run our owner's callbacks, i.e. the ones passed to | 
| 304   // Start(). | 309   // Start(). | 
| 305   scoped_refptr<base::SequencedTaskRunner> callback_task_runner_; | 310   scoped_refptr<base::SequencedTaskRunner> callback_task_runner_; | 
| 306 | 311 | 
| 307   // Callback to run once Service::OnStart is invoked. | 312   // Callback to run once Service::OnStart is invoked. | 
| 308   InitializeCallback initialize_handler_; | 313   InitializeCallback initialize_handler_; | 
| 309 | 314 | 
| 310   // Callback to run when a new Service request is received. | 315   // Callback to run when a new Service request is received. | 
| 311   ServiceFactoryCallback create_service_callback_; | 316   ServiceFactoryCallback create_service_callback_; | 
| 312 | 317 | 
| 313   // Callback to run if the service is stopped by the service manager. | 318   // Callback to run if the service is stopped by the service manager. | 
| 314   base::Closure stop_callback_; | 319   base::Closure stop_callback_; | 
| 315 | 320 | 
| 316   // Called once a connection has been received from the browser process & the | 321   // Called once a connection has been received from the browser process & the | 
| 317   // default binder (below) has been set up. | 322   // default binder (below) has been set up. | 
| 318   bool has_browser_connection_ = false; | 323   bool has_browser_connection_ = false; | 
| 319 | 324 | 
| 320   shell::Identity id_; | 325   service_manager::Identity id_; | 
| 321 | 326 | 
| 322   // Default binder callback used for the browser connection's | 327   // Default binder callback used for the browser connection's | 
| 323   // InterfaceRegistry. | 328   // InterfaceRegistry. | 
| 324   // | 329   // | 
| 325   // TODO(rockot): Remove this once all interfaces exposed to the browser are | 330   // TODO(rockot): Remove this once all interfaces exposed to the browser are | 
| 326   // exposed via a ConnectionFilter. | 331   // exposed via a ConnectionFilter. | 
| 327   shell::InterfaceRegistry::Binder default_browser_binder_; | 332   service_manager::InterfaceRegistry::Binder default_browser_binder_; | 
| 328 | 333 | 
| 329   std::unique_ptr<shell::ServiceContext> service_context_; | 334   std::unique_ptr<service_manager::ServiceContext> service_context_; | 
| 330   mojo::BindingSet<shell::mojom::ServiceFactory> factory_bindings_; | 335   mojo::BindingSet<service_manager::mojom::ServiceFactory> factory_bindings_; | 
| 331   int next_filter_id_ = kInvalidConnectionFilterId; | 336   int next_filter_id_ = kInvalidConnectionFilterId; | 
| 332 | 337 | 
| 333   // Not owned. | 338   // Not owned. | 
| 334   MessageLoopObserver* message_loop_observer_ = nullptr; | 339   MessageLoopObserver* message_loop_observer_ = nullptr; | 
| 335 | 340 | 
| 336   // Guards |connection_filters_|. | 341   // Guards |connection_filters_|. | 
| 337   base::Lock lock_; | 342   base::Lock lock_; | 
| 338   std::map<int, std::unique_ptr<ConnectionFilter>> connection_filters_; | 343   std::map<int, std::unique_ptr<ConnectionFilter>> connection_filters_; | 
| 339 | 344 | 
| 340   base::WeakPtrFactory<IOThreadContext> weak_factory_; | 345   base::WeakPtrFactory<IOThreadContext> weak_factory_; | 
| (...skipping 23 matching lines...) Expand all  Loading... | 
| 364 } | 369 } | 
| 365 | 370 | 
| 366 // static | 371 // static | 
| 367 void ServiceManagerConnection::SetFactoryForTest(Factory* factory) { | 372 void ServiceManagerConnection::SetFactoryForTest(Factory* factory) { | 
| 368   DCHECK(!g_connection_for_process.Get()); | 373   DCHECK(!g_connection_for_process.Get()); | 
| 369   service_manager_connection_factory = factory; | 374   service_manager_connection_factory = factory; | 
| 370 } | 375 } | 
| 371 | 376 | 
| 372 // static | 377 // static | 
| 373 std::unique_ptr<ServiceManagerConnection> ServiceManagerConnection::Create( | 378 std::unique_ptr<ServiceManagerConnection> ServiceManagerConnection::Create( | 
| 374     shell::mojom::ServiceRequest request, | 379     service_manager::mojom::ServiceRequest request, | 
| 375     scoped_refptr<base::SequencedTaskRunner> io_task_runner) { | 380     scoped_refptr<base::SequencedTaskRunner> io_task_runner) { | 
| 376   if (service_manager_connection_factory) | 381   if (service_manager_connection_factory) | 
| 377     return service_manager_connection_factory->Run(); | 382     return service_manager_connection_factory->Run(); | 
| 378   return base::MakeUnique<ServiceManagerConnectionImpl>( | 383   return base::MakeUnique<ServiceManagerConnectionImpl>( | 
| 379       std::move(request), io_task_runner); | 384       std::move(request), io_task_runner); | 
| 380 } | 385 } | 
| 381 | 386 | 
| 382 ServiceManagerConnection::~ServiceManagerConnection() {} | 387 ServiceManagerConnection::~ServiceManagerConnection() {} | 
| 383 | 388 | 
| 384 //////////////////////////////////////////////////////////////////////////////// | 389 //////////////////////////////////////////////////////////////////////////////// | 
| 385 // ServiceManagerConnectionImpl, public: | 390 // ServiceManagerConnectionImpl, public: | 
| 386 | 391 | 
| 387 ServiceManagerConnectionImpl::ServiceManagerConnectionImpl( | 392 ServiceManagerConnectionImpl::ServiceManagerConnectionImpl( | 
| 388     shell::mojom::ServiceRequest request, | 393     service_manager::mojom::ServiceRequest request, | 
| 389     scoped_refptr<base::SequencedTaskRunner> io_task_runner) | 394     scoped_refptr<base::SequencedTaskRunner> io_task_runner) | 
| 390     : weak_factory_(this) { | 395     : weak_factory_(this) { | 
| 391   shell::mojom::ConnectorRequest connector_request; | 396   service_manager::mojom::ConnectorRequest connector_request; | 
| 392   connector_ = shell::Connector::Create(&connector_request); | 397   connector_ = service_manager::Connector::Create(&connector_request); | 
| 393 | 398 | 
| 394   std::unique_ptr<shell::Connector> io_thread_connector = connector_->Clone(); | 399   std::unique_ptr<service_manager::Connector> io_thread_connector = | 
|  | 400       connector_->Clone(); | 
| 395   context_ = new IOThreadContext( | 401   context_ = new IOThreadContext( | 
| 396       std::move(request), io_task_runner, std::move(io_thread_connector), | 402       std::move(request), io_task_runner, std::move(io_thread_connector), | 
| 397       std::move(connector_request)); | 403       std::move(connector_request)); | 
| 398 } | 404 } | 
| 399 | 405 | 
| 400 ServiceManagerConnectionImpl::~ServiceManagerConnectionImpl() { | 406 ServiceManagerConnectionImpl::~ServiceManagerConnectionImpl() { | 
| 401   context_->ShutDown(); | 407   context_->ShutDown(); | 
| 402 } | 408 } | 
| 403 | 409 | 
| 404 //////////////////////////////////////////////////////////////////////////////// | 410 //////////////////////////////////////////////////////////////////////////////// | 
| 405 // ServiceManagerConnectionImpl, ServiceManagerConnection implementation: | 411 // ServiceManagerConnectionImpl, ServiceManagerConnection implementation: | 
| 406 | 412 | 
| 407 void ServiceManagerConnectionImpl::Start() { | 413 void ServiceManagerConnectionImpl::Start() { | 
| 408   context_->Start( | 414   context_->Start( | 
| 409       base::Bind(&ServiceManagerConnectionImpl::OnContextInitialized, | 415       base::Bind(&ServiceManagerConnectionImpl::OnContextInitialized, | 
| 410                  weak_factory_.GetWeakPtr()), | 416                  weak_factory_.GetWeakPtr()), | 
| 411       base::Bind(&ServiceManagerConnectionImpl::CreateService, | 417       base::Bind(&ServiceManagerConnectionImpl::CreateService, | 
| 412                  weak_factory_.GetWeakPtr()), | 418                  weak_factory_.GetWeakPtr()), | 
| 413       base::Bind(&ServiceManagerConnectionImpl::OnConnectionLost, | 419       base::Bind(&ServiceManagerConnectionImpl::OnConnectionLost, | 
| 414                  weak_factory_.GetWeakPtr())); | 420                  weak_factory_.GetWeakPtr())); | 
| 415 } | 421 } | 
| 416 | 422 | 
| 417 void ServiceManagerConnectionImpl::SetInitializeHandler( | 423 void ServiceManagerConnectionImpl::SetInitializeHandler( | 
| 418     const base::Closure& handler) { | 424     const base::Closure& handler) { | 
| 419   DCHECK(initialize_handler_.is_null()); | 425   DCHECK(initialize_handler_.is_null()); | 
| 420   initialize_handler_ = handler; | 426   initialize_handler_ = handler; | 
| 421 } | 427 } | 
| 422 | 428 | 
| 423 shell::Connector* ServiceManagerConnectionImpl::GetConnector() { | 429 service_manager::Connector* ServiceManagerConnectionImpl::GetConnector() { | 
| 424   return connector_.get(); | 430   return connector_.get(); | 
| 425 } | 431 } | 
| 426 | 432 | 
| 427 const shell::Identity& ServiceManagerConnectionImpl::GetIdentity() const { | 433 const service_manager::Identity& ServiceManagerConnectionImpl::GetIdentity() | 
|  | 434     const { | 
| 428   return identity_; | 435   return identity_; | 
| 429 } | 436 } | 
| 430 | 437 | 
| 431 void ServiceManagerConnectionImpl::SetConnectionLostClosure( | 438 void ServiceManagerConnectionImpl::SetConnectionLostClosure( | 
| 432     const base::Closure& closure) { | 439     const base::Closure& closure) { | 
| 433   connection_lost_handler_ = closure; | 440   connection_lost_handler_ = closure; | 
| 434 } | 441 } | 
| 435 | 442 | 
| 436 void ServiceManagerConnectionImpl::SetupInterfaceRequestProxies( | 443 void ServiceManagerConnectionImpl::SetupInterfaceRequestProxies( | 
| 437     shell::InterfaceRegistry* registry, | 444     service_manager::InterfaceRegistry* registry, | 
| 438     shell::InterfaceProvider* provider) { | 445     service_manager::InterfaceProvider* provider) { | 
| 439   // It's safe to bind |registry| as a raw pointer because the caller must | 446   // It's safe to bind |registry| as a raw pointer because the caller must | 
| 440   // guarantee that it outlives |this|, and |this| is bound as a weak ptr here. | 447   // guarantee that it outlives |this|, and |this| is bound as a weak ptr here. | 
| 441   context_->SetDefaultBinderForBrowserConnection( | 448   context_->SetDefaultBinderForBrowserConnection( | 
| 442       base::Bind(&ServiceManagerConnectionImpl::GetInterface, | 449       base::Bind(&ServiceManagerConnectionImpl::GetInterface, | 
| 443                  weak_factory_.GetWeakPtr(), registry)); | 450                  weak_factory_.GetWeakPtr(), registry)); | 
| 444 | 451 | 
| 445   // TODO(beng): remove provider parameter. | 452   // TODO(beng): remove provider parameter. | 
| 446 } | 453 } | 
| 447 | 454 | 
| 448 int ServiceManagerConnectionImpl::AddConnectionFilter( | 455 int ServiceManagerConnectionImpl::AddConnectionFilter( | 
| (...skipping 18 matching lines...) Expand all  Loading... | 
| 467 } | 474 } | 
| 468 | 475 | 
| 469 void ServiceManagerConnectionImpl::AddServiceRequestHandler( | 476 void ServiceManagerConnectionImpl::AddServiceRequestHandler( | 
| 470     const std::string& name, | 477     const std::string& name, | 
| 471     const ServiceRequestHandler& handler) { | 478     const ServiceRequestHandler& handler) { | 
| 472   auto result = request_handlers_.insert(std::make_pair(name, handler)); | 479   auto result = request_handlers_.insert(std::make_pair(name, handler)); | 
| 473   DCHECK(result.second); | 480   DCHECK(result.second); | 
| 474 } | 481 } | 
| 475 | 482 | 
| 476 void ServiceManagerConnectionImpl::CreateService( | 483 void ServiceManagerConnectionImpl::CreateService( | 
| 477     shell::mojom::ServiceRequest request, | 484     service_manager::mojom::ServiceRequest request, | 
| 478     const std::string& name) { | 485     const std::string& name) { | 
| 479   auto it = request_handlers_.find(name); | 486   auto it = request_handlers_.find(name); | 
| 480   if (it != request_handlers_.end()) | 487   if (it != request_handlers_.end()) | 
| 481     it->second.Run(std::move(request)); | 488     it->second.Run(std::move(request)); | 
| 482 } | 489 } | 
| 483 | 490 | 
| 484 void ServiceManagerConnectionImpl::OnContextInitialized( | 491 void ServiceManagerConnectionImpl::OnContextInitialized( | 
| 485     const shell::Identity& identity) { | 492     const service_manager::Identity& identity) { | 
| 486   identity_ = identity; | 493   identity_ = identity; | 
| 487   if (!initialize_handler_.is_null()) | 494   if (!initialize_handler_.is_null()) | 
| 488     base::ResetAndReturn(&initialize_handler_).Run(); | 495     base::ResetAndReturn(&initialize_handler_).Run(); | 
| 489 } | 496 } | 
| 490 | 497 | 
| 491 void ServiceManagerConnectionImpl::OnConnectionLost() { | 498 void ServiceManagerConnectionImpl::OnConnectionLost() { | 
| 492   if (!connection_lost_handler_.is_null()) | 499   if (!connection_lost_handler_.is_null()) | 
| 493     connection_lost_handler_.Run(); | 500     connection_lost_handler_.Run(); | 
| 494 } | 501 } | 
| 495 | 502 | 
| 496 void ServiceManagerConnectionImpl::GetInterface( | 503 void ServiceManagerConnectionImpl::GetInterface( | 
| 497     shell::mojom::InterfaceProvider* provider, | 504     service_manager::mojom::InterfaceProvider* provider, | 
| 498     const std::string& interface_name, | 505     const std::string& interface_name, | 
| 499     mojo::ScopedMessagePipeHandle request_handle) { | 506     mojo::ScopedMessagePipeHandle request_handle) { | 
| 500   provider->GetInterface(interface_name, std::move(request_handle)); | 507   provider->GetInterface(interface_name, std::move(request_handle)); | 
| 501 } | 508 } | 
| 502 | 509 | 
| 503 }  // namespace content | 510 }  // namespace content | 
| 504 | 511 | 
| OLD | NEW | 
|---|