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_PUBLIC_COMMON_MOJO_SHELL_CONNECTION_H_ | 5 #ifndef CONTENT_PUBLIC_COMMON_MOJO_SHELL_CONNECTION_H_ |
6 #define CONTENT_PUBLIC_COMMON_MOJO_SHELL_CONNECTION_H_ | 6 #define CONTENT_PUBLIC_COMMON_MOJO_SHELL_CONNECTION_H_ |
7 | 7 |
8 #include <memory> | 8 #include <memory> |
9 | 9 |
10 #include "base/callback_forward.h" | 10 #include "base/callback_forward.h" |
| 11 #include "base/sequenced_task_runner.h" |
11 #include "content/common/content_export.h" | 12 #include "content/common/content_export.h" |
12 #include "content/public/common/mojo_application_info.h" | 13 #include "content/public/common/mojo_application_info.h" |
13 #include "services/shell/public/cpp/identity.h" | 14 #include "services/shell/public/cpp/identity.h" |
14 #include "services/shell/public/interfaces/service.mojom.h" | 15 #include "services/shell/public/interfaces/service.mojom.h" |
15 | 16 |
16 namespace shell { | 17 namespace shell { |
17 class Connection; | 18 class Connection; |
18 class Connector; | 19 class Connector; |
19 class ServiceContext; | 20 class InterfaceProvider; |
| 21 class InterfaceRegistry; |
20 } | 22 } |
21 | 23 |
22 namespace content { | 24 namespace content { |
23 | 25 |
| 26 class ConnectionFilter; |
| 27 |
24 // Encapsulates a connection to a //services/shell. | 28 // Encapsulates a connection to a //services/shell. |
25 // Access a global instance on the thread the ServiceContext was bound by | 29 // Access a global instance on the thread the ServiceContext was bound by |
26 // calling Holder::Get(). | 30 // calling Holder::Get(). |
27 // Clients can add shell::Service implementations whose exposed interfaces | 31 // Clients can add shell::Service implementations whose exposed interfaces |
28 // will be exposed to inbound connections to this object's Service. | 32 // will be exposed to inbound connections to this object's Service. |
29 // Alternatively clients can define named services that will be constructed when | 33 // Alternatively clients can define named services that will be constructed when |
30 // requests for those service names are received. | 34 // requests for those service names are received. |
31 // Clients must call any of the registration methods when receiving | 35 // Clients must call any of the registration methods when receiving |
32 // ContentBrowserClient::RegisterInProcessMojoApplications(). | 36 // ContentBrowserClient::RegisterInProcessMojoApplications(). |
33 class CONTENT_EXPORT MojoShellConnection { | 37 class CONTENT_EXPORT MojoShellConnection { |
(...skipping 14 matching lines...) Expand all Loading... |
48 // Destroys the per-process instance. Must be called on the thread the | 52 // Destroys the per-process instance. Must be called on the thread the |
49 // connection was created on. | 53 // connection was created on. |
50 static void DestroyForProcess(); | 54 static void DestroyForProcess(); |
51 | 55 |
52 virtual ~MojoShellConnection(); | 56 virtual ~MojoShellConnection(); |
53 | 57 |
54 // Sets the factory used to create the MojoShellConnection. This must be | 58 // Sets the factory used to create the MojoShellConnection. This must be |
55 // called before the MojoShellConnection has been created. | 59 // called before the MojoShellConnection has been created. |
56 static void SetFactoryForTest(Factory* factory); | 60 static void SetFactoryForTest(Factory* factory); |
57 | 61 |
58 // Creates a MojoShellConnection from |request|. | 62 // Creates a MojoShellConnection from |request|. The connection binds |
| 63 // its interfaces and accept new connections on |io_task_runner| only. Note |
| 64 // that no incoming connections are accepted until Start() is called. |
59 static std::unique_ptr<MojoShellConnection> Create( | 65 static std::unique_ptr<MojoShellConnection> Create( |
60 shell::mojom::ServiceRequest request); | 66 shell::mojom::ServiceRequest request, |
| 67 scoped_refptr<base::SequencedTaskRunner> io_task_runner); |
61 | 68 |
62 // Returns the bound shell::ServiceContext object. | 69 // Begins accepting incoming connections. Connection filters MUST be added |
63 // TODO(rockot): remove. | 70 // before calling this in order to avoid races. See AddConnectionFilter() |
64 virtual shell::ServiceContext* GetShellConnection() = 0; | 71 // below. |
| 72 virtual void Start() = 0; |
| 73 |
| 74 // Sets a closure to be invoked once the connection receives an Initialize() |
| 75 // request from the shell. |
| 76 virtual void SetInitializeHandler(const base::Closure& handler) = 0; |
65 | 77 |
66 // Returns the shell::Connector received via this connection's Service | 78 // Returns the shell::Connector received via this connection's Service |
67 // implementation. Use this to initiate connections as this object's Identity. | 79 // implementation. Use this to initiate connections as this object's Identity. |
68 virtual shell::Connector* GetConnector() = 0; | 80 virtual shell::Connector* GetConnector() = 0; |
69 | 81 |
70 // Returns this connection's identity with the shell. Connections initiated | 82 // Returns this connection's identity with the shell. Connections initiated |
71 // via the shell::Connector returned by GetConnector() will use this. | 83 // via the shell::Connector returned by GetConnector() will use this. |
72 virtual const shell::Identity& GetIdentity() const = 0; | 84 virtual const shell::Identity& GetIdentity() const = 0; |
73 | 85 |
74 // Sets a closure that is called when the connection is lost. Note that | 86 // Sets a closure that is called when the connection is lost. Note that |
75 // connection may already have been closed, in which case |closure| will be | 87 // connection may already have been closed, in which case |closure| will be |
76 // run immediately before returning from this function. | 88 // run immediately before returning from this function. |
77 virtual void SetConnectionLostClosure(const base::Closure& closure) = 0; | 89 virtual void SetConnectionLostClosure(const base::Closure& closure) = 0; |
78 | 90 |
79 // Allows the caller to expose interfaces to the caller using the identity of | 91 // Provides an InterfaceRegistry to forward incoming interface requests to |
80 // this object's Service. As distinct from MergeService() and | 92 // on the MojoShellConnection's own thread if they aren't bound by the |
81 // AddServiceRequestHandler() which specify unique identities for the | 93 // connection's internal InterfaceRegistry on the IO thread. |
82 // registered services. | 94 // |
83 virtual void MergeService(std::unique_ptr<shell::Service> service) = 0; | 95 // Also configures |interface_provider| to forward all of its outgoing |
84 virtual void MergeService(shell::Service* service) = 0; | 96 // interface requests to the connection's internal remote interface provider. |
| 97 // |
| 98 // Note that neither |interface_registry| or |interface_provider| is owned |
| 99 // and both MUST outlive the MojoShellConnection. |
| 100 // |
| 101 // TODO(rockot): Remove this. It's a temporary solution to avoid porting all |
| 102 // relevant code to ConnectionFilters at once. |
| 103 virtual void SetupInterfaceRequestProxies( |
| 104 shell::InterfaceRegistry* registry, |
| 105 shell::InterfaceProvider* provider) = 0; |
| 106 |
| 107 // Allows the caller to filter inbound connections and/or expose interfaces |
| 108 // on them. |filter| may be created on any thread, but will be used and |
| 109 // destroyed exclusively on the IO thread (the thread corresponding to |
| 110 // |io_task_runner| passed to Create() above.) |
| 111 // |
| 112 // Connection filters MUST be added before calling Start() in order to avoid |
| 113 // races. |
| 114 virtual void AddConnectionFilter( |
| 115 std::unique_ptr<ConnectionFilter> filter) = 0; |
85 | 116 |
86 // Adds an embedded service to this connection's ServiceFactory. | 117 // Adds an embedded service to this connection's ServiceFactory. |
87 // |info| provides details on how to construct new instances of the | 118 // |info| provides details on how to construct new instances of the |
88 // service when an incoming connection is made to |name|. | 119 // service when an incoming connection is made to |name|. |
89 virtual void AddEmbeddedService(const std::string& name, | 120 virtual void AddEmbeddedService(const std::string& name, |
90 const MojoApplicationInfo& info) = 0; | 121 const MojoApplicationInfo& info) = 0; |
91 | 122 |
92 // Adds a generic ServiceRequestHandler for a given service name. This | 123 // Adds a generic ServiceRequestHandler for a given service name. This |
93 // will be used to satisfy any incoming calls to CreateService() which | 124 // will be used to satisfy any incoming calls to CreateService() which |
94 // reference the given name. | 125 // reference the given name. |
95 // | 126 // |
96 // For in-process services, it is preferable to use |AddEmbeddedService()| as | 127 // For in-process services, it is preferable to use |AddEmbeddedService()| as |
97 // defined above. | 128 // defined above. |
98 virtual void AddServiceRequestHandler( | 129 virtual void AddServiceRequestHandler( |
99 const std::string& name, | 130 const std::string& name, |
100 const ServiceRequestHandler& handler) = 0; | 131 const ServiceRequestHandler& handler) = 0; |
101 }; | 132 }; |
102 | 133 |
103 } // namespace content | 134 } // namespace content |
104 | 135 |
105 #endif // CONTENT_PUBLIC_COMMON_MOJO_SHELL_CONNECTION_H_ | 136 #endif // CONTENT_PUBLIC_COMMON_MOJO_SHELL_CONNECTION_H_ |
OLD | NEW |