OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 SERVICES_SHELL_PUBLIC_CPP_CONNECTION_H_ | 5 #ifndef SERVICES_SHELL_PUBLIC_CPP_CONNECTION_H_ |
6 #define SERVICES_SHELL_PUBLIC_CPP_CONNECTION_H_ | 6 #define SERVICES_SHELL_PUBLIC_CPP_CONNECTION_H_ |
7 | 7 |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <string> | 10 #include <string> |
11 #include <utility> | 11 #include <utility> |
12 | 12 |
13 #include "base/memory/weak_ptr.h" | 13 #include "base/memory/weak_ptr.h" |
14 #include "services/shell/public/cpp/connect.h" | 14 #include "services/shell/public/cpp/connect.h" |
15 #include "services/shell/public/cpp/identity.h" | 15 #include "services/shell/public/cpp/identity.h" |
16 #include "services/shell/public/cpp/interface_registry.h" | 16 #include "services/shell/public/cpp/interface_registry.h" |
| 17 #include "services/shell/public/cpp/remote_interface_registry.h" |
17 #include "services/shell/public/interfaces/connector.mojom.h" | 18 #include "services/shell/public/interfaces/connector.mojom.h" |
18 #include "services/shell/public/interfaces/interface_provider.mojom.h" | 19 #include "services/shell/public/interfaces/interface_provider.mojom.h" |
19 | 20 |
20 namespace shell { | 21 namespace shell { |
21 | 22 |
22 class InterfaceBinder; | 23 class InterfaceBinder; |
| 24 class RemoteInterfaceRegistry; |
23 | 25 |
24 // Represents a connection to another application. An instance of this class is | 26 // Represents a connection to another application. An instance of this class is |
25 // returned from Shell's ConnectToApplication(), and passed to ShellClient's | 27 // returned from Shell's ConnectToApplication(), and passed to ShellClient's |
26 // AcceptConnection() each time an incoming connection is received. | 28 // AcceptConnection() each time an incoming connection is received. |
27 // | 29 // |
28 // Call AddService<T>(factory) to expose an interface to the remote application, | 30 // Call AddService<T>(factory) to expose an interface to the remote application, |
29 // and GetInterface(&interface_ptr) to consume an interface exposed by the | 31 // and GetInterface(&interface_ptr) to consume an interface exposed by the |
30 // remote application. | 32 // remote application. |
31 // | 33 // |
32 // Internally, this class wraps an InterfaceRegistry that accepts interfaces | 34 // Internally, this class wraps an InterfaceRegistry that accepts interfaces |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
79 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner) { | 81 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner) { |
80 return GetInterfaceRegistry()->AddInterface<Interface>( | 82 return GetInterfaceRegistry()->AddInterface<Interface>( |
81 callback, task_runner); | 83 callback, task_runner); |
82 } | 84 } |
83 | 85 |
84 // Binds |ptr| to an implementation of Interface in the remote application. | 86 // Binds |ptr| to an implementation of Interface in the remote application. |
85 // |ptr| can immediately be used to start sending requests to the remote | 87 // |ptr| can immediately be used to start sending requests to the remote |
86 // interface. | 88 // interface. |
87 template <typename Interface> | 89 template <typename Interface> |
88 void GetInterface(mojo::InterfacePtr<Interface>* ptr) { | 90 void GetInterface(mojo::InterfacePtr<Interface>* ptr) { |
89 GetInterfaceRegistry()->GetInterface(ptr); | 91 GetRemoteInterfaceRegistry()->GetInterface(ptr); |
90 } | 92 } |
91 | 93 |
92 // Returns true if the remote application has the specified capability class | 94 // Returns true if the remote application has the specified capability class |
93 // specified in its manifest. Only valid for inbound connections. Will return | 95 // specified in its manifest. Only valid for inbound connections. Will return |
94 // false for outbound connections. | 96 // false for outbound connections. |
95 virtual bool HasCapabilityClass(const std::string& class_name) const = 0; | 97 virtual bool HasCapabilityClass(const std::string& class_name) const = 0; |
96 | 98 |
97 // Returns the name that was used by the source application to establish a | 99 // Returns the name that was used by the source application to establish a |
98 // connection to the destination application. | 100 // connection to the destination application. |
99 // | 101 // |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
131 // Register a closure to be run when the connection has been completed by the | 133 // Register a closure to be run when the connection has been completed by the |
132 // shell and remote metadata is available. Useful only for connections created | 134 // shell and remote metadata is available. Useful only for connections created |
133 // via Connector::Connect(). Once the connection is complete, metadata is | 135 // via Connector::Connect(). Once the connection is complete, metadata is |
134 // available immediately. | 136 // available immediately. |
135 virtual void AddConnectionCompletedClosure(const mojo::Closure& callback) = 0; | 137 virtual void AddConnectionCompletedClosure(const mojo::Closure& callback) = 0; |
136 | 138 |
137 // Returns true if the Shell allows |interface_name| to be exposed to the | 139 // Returns true if the Shell allows |interface_name| to be exposed to the |
138 // remote application. | 140 // remote application. |
139 virtual bool AllowsInterface(const std::string& interface_name) const = 0; | 141 virtual bool AllowsInterface(const std::string& interface_name) const = 0; |
140 | 142 |
141 // Returns the InterfaceRegistry that encapsulates the pair of | 143 // Returns a raw pointer to the InterfaceProvider at the remote end. |
142 // InterfaceProviders between this application and the remote. | 144 virtual mojom::InterfaceProvider* GetRemoteInterfaceProvider() = 0; |
| 145 |
| 146 protected: |
| 147 // Returns the InterfaceRegistry that implements the mojom::InterfaceProvider |
| 148 // exposed to the remote application. |
143 virtual InterfaceRegistry* GetInterfaceRegistry() = 0; | 149 virtual InterfaceRegistry* GetInterfaceRegistry() = 0; |
144 | 150 |
145 protected: | 151 // Returns an object encapsulating a remote InterfaceProvider. |
| 152 virtual RemoteInterfaceRegistry* GetRemoteInterfaceRegistry() = 0; |
| 153 |
146 virtual base::WeakPtr<Connection> GetWeakPtr() = 0; | 154 virtual base::WeakPtr<Connection> GetWeakPtr() = 0; |
147 }; | 155 }; |
148 | 156 |
149 } // namespace shell | 157 } // namespace shell |
150 | 158 |
151 #endif // SERVICES_SHELL_PUBLIC_CPP_CONNECTION_H_ | 159 #endif // SERVICES_SHELL_PUBLIC_CPP_CONNECTION_H_ |
OLD | NEW |