Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(7)

Side by Side Diff: content/public/common/mojo_shell_connection.h

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

Powered by Google App Engine
This is Rietveld 408576698