Colin Blundell | 285e5bb | 2017-07-04 09:10:32 | [diff] [blame] | 1 | // Copyright 2017 The Chromium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #ifndef IOS_WEB_SERVICE_MANAGER_SERVICE_MANAGER_CONNECTION_IMPL_H_ |
| 6 | #define IOS_WEB_SERVICE_MANAGER_SERVICE_MANAGER_CONNECTION_IMPL_H_ |
| 7 | |
| 8 | #include <memory> |
| 9 | |
| 10 | #include "base/macros.h" |
| 11 | #include "base/memory/ref_counted.h" |
| 12 | #include "base/memory/weak_ptr.h" |
| 13 | #include "base/sequenced_task_runner.h" |
| 14 | #include "ios/web/public/service_manager_connection.h" |
| 15 | #include "mojo/public/cpp/system/message_pipe.h" |
| 16 | #include "services/service_manager/public/cpp/identity.h" |
| 17 | #include "services/service_manager/public/interfaces/service.mojom.h" |
| 18 | |
| 19 | namespace service_manager { |
| 20 | class Connector; |
| 21 | } |
| 22 | |
| 23 | namespace web { |
| 24 | |
| 25 | class ServiceManagerConnectionImpl : public ServiceManagerConnection { |
| 26 | public: |
| 27 | ServiceManagerConnectionImpl( |
| 28 | service_manager::mojom::ServiceRequest request, |
| 29 | scoped_refptr<base::SequencedTaskRunner> io_task_runner); |
| 30 | ~ServiceManagerConnectionImpl() override; |
| 31 | |
| 32 | private: |
| 33 | class IOThreadContext; |
| 34 | |
| 35 | // ServiceManagerConnection: |
| 36 | void Start() override; |
| 37 | service_manager::Connector* GetConnector() override; |
| 38 | void AddEmbeddedService( |
| 39 | const std::string& name, |
| 40 | const service_manager::EmbeddedServiceInfo& info) override; |
| 41 | |
| 42 | // Invoked when the connection to the Service Manager is lost. |
| 43 | void OnConnectionLost(); |
| 44 | |
| 45 | // Binds |request_handle| to an instance of |interface_name| provided by |
| 46 | // |interface_provider|. |
| 47 | void GetInterface(service_manager::mojom::InterfaceProvider* provider, |
| 48 | const std::string& interface_name, |
| 49 | mojo::ScopedMessagePipeHandle request_handle); |
| 50 | |
| 51 | std::unique_ptr<service_manager::Connector> connector_; |
| 52 | |
| 53 | scoped_refptr<IOThreadContext> context_; |
| 54 | |
| 55 | base::WeakPtrFactory<ServiceManagerConnectionImpl> weak_factory_; |
| 56 | |
| 57 | DISALLOW_COPY_AND_ASSIGN(ServiceManagerConnectionImpl); |
| 58 | }; |
| 59 | |
| 60 | } // namespace web |
| 61 | |
| 62 | #endif // IOS_WEB_SERVICE_MANAGER_SERVICE_MANAGER_CONNECTION_IMPL_H_ |