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