Chromium Code Reviews| 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 |
| 143 protected: | |
| 141 // Returns the InterfaceRegistry that encapsulates the pair of | 144 // Returns the InterfaceRegistry that encapsulates the pair of |
| 142 // InterfaceProviders between this application and the remote. | 145 // InterfaceProviders between this application and the remote. |
|
Ken Rockot(use gerrit already)
2016/06/16 23:48:58
nit: update comment
| |
| 143 virtual InterfaceRegistry* GetInterfaceRegistry() = 0; | 146 virtual InterfaceRegistry* GetInterfaceRegistry() = 0; |
| 144 | 147 |
| 145 protected: | 148 // Returns an object encapsulating a remote InterfaceProvider. |
| 149 virtual RemoteInterfaceRegistry* GetRemoteInterfaceRegistry() = 0; | |
| 150 | |
| 146 virtual base::WeakPtr<Connection> GetWeakPtr() = 0; | 151 virtual base::WeakPtr<Connection> GetWeakPtr() = 0; |
| 147 }; | 152 }; |
| 148 | 153 |
| 149 } // namespace shell | 154 } // namespace shell |
| 150 | 155 |
| 151 #endif // SERVICES_SHELL_PUBLIC_CPP_CONNECTION_H_ | 156 #endif // SERVICES_SHELL_PUBLIC_CPP_CONNECTION_H_ |
| OLD | NEW |