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

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

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

Powered by Google App Engine
This is Rietveld 408576698