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 #ifndef CONTENT_COMMON_MOJO_SHELL_CONNECTION_IMPL_H_ | 5 #ifndef CONTENT_COMMON_MOJO_SHELL_CONNECTION_IMPL_H_ |
6 #define CONTENT_COMMON_MOJO_SHELL_CONNECTION_IMPL_H_ | 6 #define CONTENT_COMMON_MOJO_SHELL_CONNECTION_IMPL_H_ |
7 | 7 |
8 #include <memory> | 8 #include <memory> |
9 #include <vector> | |
10 | 9 |
11 #include "base/macros.h" | 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" |
12 #include "content/public/common/mojo_shell_connection.h" | 14 #include "content/public/common/mojo_shell_connection.h" |
13 #include "mojo/public/cpp/bindings/binding_set.h" | 15 #include "mojo/public/cpp/bindings/string.h" |
14 #include "mojo/public/cpp/system/message_pipe.h" | 16 #include "mojo/public/cpp/system/message_pipe.h" |
15 #include "services/shell/public/cpp/service.h" | 17 #include "services/shell/public/cpp/identity.h" |
16 #include "services/shell/public/cpp/service_context.h" | 18 #include "services/shell/public/interfaces/service.mojom.h" |
17 #include "services/shell/public/interfaces/service_factory.mojom.h" | 19 |
| 20 namespace shell { |
| 21 class Connector; |
| 22 } |
18 | 23 |
19 namespace content { | 24 namespace content { |
20 | 25 |
21 class EmbeddedApplicationRunner; | 26 class EmbeddedApplicationRunner; |
22 | 27 |
23 class MojoShellConnectionImpl | 28 class MojoShellConnectionImpl : public MojoShellConnection { |
24 : public MojoShellConnection, | |
25 public shell::Service, | |
26 public shell::InterfaceFactory<shell::mojom::ServiceFactory>, | |
27 public shell::mojom::ServiceFactory { | |
28 | |
29 public: | 29 public: |
30 explicit MojoShellConnectionImpl(shell::mojom::ServiceRequest request); | 30 explicit MojoShellConnectionImpl( |
| 31 shell::mojom::ServiceRequest request, |
| 32 scoped_refptr<base::SequencedTaskRunner> io_task_runner); |
31 ~MojoShellConnectionImpl() override; | 33 ~MojoShellConnectionImpl() override; |
32 | 34 |
33 private: | 35 private: |
| 36 class IOThreadContext; |
| 37 |
34 // MojoShellConnection: | 38 // MojoShellConnection: |
35 shell::ServiceContext* GetShellConnection() override; | 39 void Start() override; |
| 40 void SetInitializeHandler(const base::Closure& handler) override; |
36 shell::Connector* GetConnector() override; | 41 shell::Connector* GetConnector() override; |
37 const shell::Identity& GetIdentity() const override; | 42 const shell::Identity& GetIdentity() const override; |
38 void SetConnectionLostClosure(const base::Closure& closure) override; | 43 void SetConnectionLostClosure(const base::Closure& closure) override; |
39 void MergeService(std::unique_ptr<shell::Service> service) override; | 44 void SetupInterfaceRequestProxies( |
40 void MergeService(shell::Service* service) override; | 45 shell::InterfaceRegistry* registry, |
| 46 shell::InterfaceProvider* provider) override; |
| 47 void AddConnectionFilter(std::unique_ptr<ConnectionFilter> filter) override; |
41 void AddEmbeddedService(const std::string& name, | 48 void AddEmbeddedService(const std::string& name, |
42 const MojoApplicationInfo& info) override; | 49 const MojoApplicationInfo& info) override; |
43 void AddServiceRequestHandler( | 50 void AddServiceRequestHandler( |
44 const std::string& name, | 51 const std::string& name, |
45 const ServiceRequestHandler& handler) override; | 52 const ServiceRequestHandler& handler) override; |
46 | 53 |
47 // shell::Service: | 54 void OnContextInitialized(const shell::Identity& identity); |
48 void OnStart(shell::Connector* connector, | 55 void OnConnectionLost(); |
49 const shell::Identity& identity, | 56 void CreateService(shell::mojom::ServiceRequest request, |
50 uint32_t id) override; | 57 const mojo::String& name); |
51 bool OnConnect(shell::Connection* connection) override; | 58 void GetInterface(shell::mojom::InterfaceProvider* provider, |
52 shell::InterfaceRegistry* GetInterfaceRegistryForConnection() override; | 59 const mojo::String& interface_name, |
53 shell::InterfaceProvider* GetInterfaceProviderForConnection() override; | 60 mojo::ScopedMessagePipeHandle request_handle); |
54 | 61 |
55 // shell::InterfaceFactory<shell::mojom::ServiceFactory>: | 62 shell::Identity identity_; |
56 void Create(shell::Connection* connection, | |
57 shell::mojom::ServiceFactoryRequest request) override; | |
58 | 63 |
59 // shell::mojom::ServiceFactory: | 64 std::unique_ptr<shell::Connector> connector_; |
60 void CreateService(shell::mojom::ServiceRequest request, | 65 scoped_refptr<IOThreadContext> context_; |
61 const mojo::String& name) override; | |
62 | 66 |
63 std::unique_ptr<shell::ServiceContext> shell_connection_; | 67 base::Closure initialize_handler_; |
64 mojo::BindingSet<shell::mojom::ServiceFactory> factory_bindings_; | 68 base::Closure connection_lost_handler_; |
65 std::vector<shell::Service*> embedded_services_; | 69 |
66 std::vector<std::unique_ptr<shell::Service>> owned_services_; | |
67 std::unordered_map<std::string, std::unique_ptr<EmbeddedApplicationRunner>> | 70 std::unordered_map<std::string, std::unique_ptr<EmbeddedApplicationRunner>> |
68 embedded_apps_; | 71 embedded_apps_; |
69 std::unordered_map<std::string, ServiceRequestHandler> request_handlers_; | 72 std::unordered_map<std::string, ServiceRequestHandler> request_handlers_; |
70 | 73 |
| 74 base::WeakPtrFactory<MojoShellConnectionImpl> weak_factory_; |
| 75 |
71 DISALLOW_COPY_AND_ASSIGN(MojoShellConnectionImpl); | 76 DISALLOW_COPY_AND_ASSIGN(MojoShellConnectionImpl); |
72 }; | 77 }; |
73 | 78 |
74 } // namespace content | 79 } // namespace content |
75 | 80 |
76 #endif // CONTENT_COMMON_MOJO_SHELL_CONNECTION_IMPL_H_ | 81 #endif // CONTENT_COMMON_MOJO_SHELL_CONNECTION_IMPL_H_ |
OLD | NEW |