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/callback_forward.h" | 13 #include "base/callback_forward.h" |
14 #include "base/memory/weak_ptr.h" | 14 #include "base/memory/weak_ptr.h" |
15 #include "services/shell/public/cpp/connect.h" | 15 #include "services/shell/public/cpp/connect.h" |
16 #include "services/shell/public/cpp/identity.h" | 16 #include "services/shell/public/cpp/identity.h" |
| 17 #include "services/shell/public/cpp/interface_provider.h" |
17 #include "services/shell/public/cpp/interface_registry.h" | 18 #include "services/shell/public/cpp/interface_registry.h" |
18 #include "services/shell/public/cpp/remote_interface_registry.h" | |
19 #include "services/shell/public/interfaces/connector.mojom.h" | 19 #include "services/shell/public/interfaces/connector.mojom.h" |
20 #include "services/shell/public/interfaces/interface_provider.mojom.h" | 20 #include "services/shell/public/interfaces/interface_provider.mojom.h" |
21 | 21 |
22 namespace shell { | 22 namespace shell { |
23 | 23 |
24 class InterfaceBinder; | 24 class InterfaceBinder; |
25 class RemoteInterfaceRegistry; | 25 class InterfaceProvider; |
26 | 26 |
27 // Represents a connection to another application. An instance of this class is | 27 // Represents a connection to another application. An instance of this class is |
28 // returned from Shell's ConnectToApplication(), and passed to ShellClient's | 28 // returned from Shell's ConnectToApplication(), and passed to ShellClient's |
29 // AcceptConnection() each time an incoming connection is received. | 29 // AcceptConnection() each time an incoming connection is received. |
30 // | 30 // |
31 // Call AddService<T>(factory) to expose an interface to the remote application, | 31 // Call AddService<T>(factory) to expose an interface to the remote application, |
32 // and GetInterface(&interface_ptr) to consume an interface exposed by the | 32 // and GetInterface(&interface_ptr) to consume an interface exposed by the |
33 // remote application. | 33 // remote application. |
34 // | 34 // |
35 // Internally, this class wraps an InterfaceRegistry that accepts interfaces | 35 // Internally, this class wraps an InterfaceRegistry that accepts interfaces |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
82 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner) { | 82 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner) { |
83 return GetInterfaceRegistry()->AddInterface<Interface>( | 83 return GetInterfaceRegistry()->AddInterface<Interface>( |
84 callback, task_runner); | 84 callback, task_runner); |
85 } | 85 } |
86 | 86 |
87 // Binds |ptr| to an implementation of Interface in the remote application. | 87 // Binds |ptr| to an implementation of Interface in the remote application. |
88 // |ptr| can immediately be used to start sending requests to the remote | 88 // |ptr| can immediately be used to start sending requests to the remote |
89 // interface. | 89 // interface. |
90 template <typename Interface> | 90 template <typename Interface> |
91 void GetInterface(mojo::InterfacePtr<Interface>* ptr) { | 91 void GetInterface(mojo::InterfacePtr<Interface>* ptr) { |
92 GetRemoteInterfaceRegistry()->GetInterface(ptr); | 92 GetRemoteInterfaces()->GetInterface(ptr); |
93 } | 93 } |
94 | 94 |
95 // Returns true if the remote application has the specified capability class | 95 // Returns true if the remote application has the specified capability class |
96 // specified in its manifest. Only valid for inbound connections. Will return | 96 // specified in its manifest. Only valid for inbound connections. Will return |
97 // false for outbound connections. | 97 // false for outbound connections. |
98 virtual bool HasCapabilityClass(const std::string& class_name) const = 0; | 98 virtual bool HasCapabilityClass(const std::string& class_name) const = 0; |
99 | 99 |
100 // Returns the name that was used by the source application to establish a | 100 // Returns the name that was used by the source application to establish a |
101 // connection to the destination application. | 101 // connection to the destination application. |
102 // | 102 // |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
143 | 143 |
144 // Returns a raw pointer to the InterfaceProvider at the remote end. | 144 // Returns a raw pointer to the InterfaceProvider at the remote end. |
145 virtual mojom::InterfaceProvider* GetRemoteInterfaceProvider() = 0; | 145 virtual mojom::InterfaceProvider* GetRemoteInterfaceProvider() = 0; |
146 | 146 |
147 protected: | 147 protected: |
148 // Returns the InterfaceRegistry that implements the mojom::InterfaceProvider | 148 // Returns the InterfaceRegistry that implements the mojom::InterfaceProvider |
149 // exposed to the remote application. | 149 // exposed to the remote application. |
150 virtual InterfaceRegistry* GetInterfaceRegistry() = 0; | 150 virtual InterfaceRegistry* GetInterfaceRegistry() = 0; |
151 | 151 |
152 // Returns an object encapsulating a remote InterfaceProvider. | 152 // Returns an object encapsulating a remote InterfaceProvider. |
153 virtual RemoteInterfaceRegistry* GetRemoteInterfaceRegistry() = 0; | 153 virtual InterfaceProvider* GetRemoteInterfaces() = 0; |
154 | 154 |
155 virtual base::WeakPtr<Connection> GetWeakPtr() = 0; | 155 virtual base::WeakPtr<Connection> GetWeakPtr() = 0; |
156 }; | 156 }; |
157 | 157 |
158 } // namespace shell | 158 } // namespace shell |
159 | 159 |
160 #endif // SERVICES_SHELL_PUBLIC_CPP_CONNECTION_H_ | 160 #endif // SERVICES_SHELL_PUBLIC_CPP_CONNECTION_H_ |
OLD | NEW |