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

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/shell_client.mojom.h" 15 #include "services/shell/public/interfaces/shell_client.mojom.h"
15 16
16 namespace shell { 17 namespace shell {
17 class Connection; 18 class Connection;
18 class Connector; 19 class Connector;
19 class ShellConnection; 20 class ShellConnection;
20 } 21 }
21 22
22 namespace content { 23 namespace content {
23 24
24 // Encapsulates a connection to a //services/shell. 25 // Encapsulates a connection to a //services/shell.
25 // Access a global instance on the thread the ShellConnection was bound by 26 // Access a global instance on the thread the ShellConnection was bound by
26 // calling Holder::Get(). 27 // calling Holder::Get().
27 // Clients can add shell::ShellClient implementations whose exposed interfaces 28 // Clients can add shell::ShellClient implementations whose exposed interfaces
28 // will be exposed to inbound connections to this object's ShellClient. 29 // will be exposed to inbound connections to this object's ShellClient.
29 // Alternatively clients can define named services that will be constructed when 30 // Alternatively clients can define named services that will be constructed when
30 // requests for those service names are received. 31 // requests for those service names are received.
31 // Clients must call any of the registration methods when receiving 32 // Clients must call any of the registration methods when receiving
32 // ContentBrowserClient::RegisterInProcessMojoApplications(). 33 // ContentBrowserClient::RegisterInProcessMojoApplications().
33 class CONTENT_EXPORT MojoShellConnection { 34 class CONTENT_EXPORT MojoShellConnection {
34 public: 35 public:
35 using ShellClientRequestHandler = 36 using ShellClientRequestHandler =
36 base::Callback<void(shell::mojom::ShellClientRequest)>; 37 base::Callback<void(shell::mojom::ShellClientRequest)>;
37 using Factory = base::Callback<std::unique_ptr<MojoShellConnection>(void)>; 38 using Factory = base::Callback<std::unique_ptr<MojoShellConnection>(void)>;
39 using ConnectionFilter =
40 base::Callback<bool(shell::Connection*, shell::Connector*)>;
38 41
39 // Stores an instance of |connection| in TLS for the current process. Must be 42 // Stores an instance of |connection| in TLS for the current process. Must be
40 // called on the thread the connection was created on. 43 // called on the thread the connection was created on.
41 static void SetForProcess(std::unique_ptr<MojoShellConnection> connection); 44 static void SetForProcess(std::unique_ptr<MojoShellConnection> connection);
42 45
43 // Returns the per-process instance, or nullptr if the Shell connection has 46 // Returns the per-process instance, or nullptr if the Shell connection has
44 // not yet been bound. Must be called on the thread the connection was created 47 // not yet been bound. Must be called on the thread the connection was created
45 // on. 48 // on.
46 static MojoShellConnection* GetForProcess(); 49 static MojoShellConnection* GetForProcess();
47 50
48 // Destroys the per-process instance. Must be called on the thread the 51 // Destroys the per-process instance. Must be called on the thread the
49 // connection was created on. 52 // connection was created on.
50 static void DestroyForProcess(); 53 static void DestroyForProcess();
51 54
52 virtual ~MojoShellConnection(); 55 virtual ~MojoShellConnection();
53 56
54 // Sets the factory used to create the MojoShellConnection. This must be 57 // Sets the factory used to create the MojoShellConnection. This must be
55 // called before the MojoShellConnection has been created. 58 // called before the MojoShellConnection has been created.
56 static void SetFactoryForTest(Factory* factory); 59 static void SetFactoryForTest(Factory* factory);
57 60
58 // Creates a MojoShellConnection from |request|. 61 // Creates a MojoShellConnection from |request|. The connection bind
62 // its interfaces and accept new connections on |io_task_runner| only.
59 static std::unique_ptr<MojoShellConnection> Create( 63 static std::unique_ptr<MojoShellConnection> Create(
60 shell::mojom::ShellClientRequest request); 64 shell::mojom::ShellClientRequest request,
65 scoped_refptr<base::SequencedTaskRunner> io_task_runner);
61 66
62 // Returns the bound shell::ShellConnection object. 67 // Sets a closure to be invoked once the connection receives an Initialize()
63 // TODO(rockot): remove. 68 // request from the shell.
64 virtual shell::ShellConnection* GetShellConnection() = 0; 69 virtual void SetInitializeHandler(const base::Closure& handler) = 0;
65 70
66 // Returns the shell::Connector received via this connection's ShellClient 71 // Returns the shell::Connector received via this connection's ShellClient
67 // implementation. Use this to initiate connections as this object's Identity. 72 // implementation. Use this to initiate connections as this object's Identity.
68 virtual shell::Connector* GetConnector() = 0; 73 virtual shell::Connector* GetConnector() = 0;
69 74
70 // Returns this connection's identity with the shell. Connections initiated 75 // Returns this connection's identity with the shell. Connections initiated
71 // via the shell::Connector returned by GetConnector() will use this. 76 // via the shell::Connector returned by GetConnector() will use this.
72 virtual const shell::Identity& GetIdentity() const = 0; 77 virtual const shell::Identity& GetIdentity() const = 0;
73 78
74 // Sets a closure that is called when the connection is lost. Note that 79 // 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 80 // connection may already have been closed, in which case |closure| will be
76 // run immediately before returning from this function. 81 // run immediately before returning from this function.
77 virtual void SetConnectionLostClosure(const base::Closure& closure) = 0; 82 virtual void SetConnectionLostClosure(const base::Closure& closure) = 0;
78 83
79 // Allows the caller to expose interfaces to the caller using the identity of 84 // Allows the caller to filter inbound connections and/or expose interfaces
80 // this object's ShellClient. As distinct from AddEmbeddedService() and 85 // on them. Note that ConnectionFilters are always invoked on the
81 // AddShellClientRequestHandler() which specify unique identities for the 86 // |io_task_runner| (see Create above.)
82 // registered services. 87 virtual void AddConnectionFilter(const ConnectionFilter& filter) = 0;
83 virtual void AddEmbeddedShellClient(
84 std::unique_ptr<shell::ShellClient> shell_client) = 0;
85 virtual void AddEmbeddedShellClient(shell::ShellClient* shell_client) = 0;
86 88
87 // Adds an embedded service to this connection's ShellClientFactory. 89 // Adds an embedded service to this connection's ShellClientFactory.
88 // |info| provides details on how to construct new instances of the 90 // |info| provides details on how to construct new instances of the
89 // service when an incoming connection is made to |name|. 91 // service when an incoming connection is made to |name|.
90 virtual void AddEmbeddedService(const std::string& name, 92 virtual void AddEmbeddedService(const std::string& name,
91 const MojoApplicationInfo& info) = 0; 93 const MojoApplicationInfo& info) = 0;
92 94
93 // Adds a generic ShellClientRequestHandler for a given service name. This 95 // Adds a generic ShellClientRequestHandler for a given service name. This
94 // will be used to satisfy any incoming calls to CreateShellClient() which 96 // will be used to satisfy any incoming calls to CreateShellClient() which
95 // reference the given name. 97 // reference the given name.
96 // 98 //
97 // For in-process services, it is preferable to use |AddEmbeddedService()| as 99 // For in-process services, it is preferable to use |AddEmbeddedService()| as
98 // defined above. 100 // defined above.
99 virtual void AddShellClientRequestHandler( 101 virtual void AddShellClientRequestHandler(
100 const std::string& name, 102 const std::string& name,
101 const ShellClientRequestHandler& handler) = 0; 103 const ShellClientRequestHandler& handler) = 0;
102 }; 104 };
103 105
104 } // namespace content 106 } // namespace content
105 107
106 #endif // CONTENT_PUBLIC_COMMON_MOJO_SHELL_CONNECTION_H_ 108 #endif // CONTENT_PUBLIC_COMMON_MOJO_SHELL_CONNECTION_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698