| 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 MOJO_SHELL_PUBLIC_CPP_CONNECTION_H_ | 5 #ifndef MOJO_SHELL_PUBLIC_CPP_CONNECTION_H_ |
| 6 #define MOJO_SHELL_PUBLIC_CPP_CONNECTION_H_ | 6 #define MOJO_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 "mojo/shell/public/cpp/lib/interface_factory_binder.h" | 14 #include "mojo/shell/public/cpp/lib/interface_factory_binder.h" |
| 15 #include "mojo/shell/public/interfaces/interface_provider.mojom.h" | 15 #include "mojo/shell/public/interfaces/interface_provider.mojom.h" |
| 16 | 16 |
| 17 namespace mojo { | 17 namespace mojo { |
| 18 | 18 |
| 19 class InterfaceBinder; | 19 class InterfaceBinder; |
| 20 | 20 |
| 21 // Represents a connection to another application. An instance of this class is | 21 // Represents a connection to another application. An instance of this class is |
| 22 // passed to ShellClient's AcceptConnection() method each | 22 // returned from Shell's ConnectToApplication(), and passed to ShellClient's |
| 23 // time a connection is made to this app. | 23 // AcceptConnection() each time an incoming connection is received. |
| 24 // | 24 // |
| 25 // To use, define a class that implements your specific interface. Then | 25 // To use, define a class that implements your specific interface. Then |
| 26 // implement an InterfaceFactory<Foo> that binds instances of FooImpl to | 26 // implement an InterfaceFactory<Foo> that binds instances of FooImpl to |
| 27 // InterfaceRequest<Foo>s and register that on the connection like this: | 27 // InterfaceRequest<Foo>s and register that on the connection like this: |
| 28 // | 28 // |
| 29 // connection->AddInterface(&factory); | 29 // connection->AddInterface(&factory); |
| 30 // | 30 // |
| 31 // Or, if you have multiple factories implemented by the same type, explicitly | 31 // Or, if you have multiple factories implemented by the same type, explicitly |
| 32 // specify the interface to register the factory for: | 32 // specify the interface to register the factory for: |
| 33 // | 33 // |
| 34 // connection->AddInterface<Foo>(&my_foo_and_bar_factory_); | 34 // connection->AddInterface<Foo>(&my_foo_and_bar_factory_); |
| 35 // connection->AddInterface<Bar>(&my_foo_and_bar_factory_); | 35 // connection->AddInterface<Bar>(&my_foo_and_bar_factory_); |
| 36 // | 36 // |
| 37 // The InterfaceFactory must outlive the Connection. | 37 // The InterfaceFactory must outlive the Connection. |
| 38 // | 38 // |
| 39 // Additionally you specify a InterfaceBinder. If a InterfaceBinder has | 39 // Additionally you may specify a default InterfaceBinder to handle requests for |
| 40 // been set and an InterfaceFactory has not been registered for the interface | 40 // interfaces unhandled by any registered InterfaceFactory. Just as with |
| 41 // request, than the interface request is sent to the InterfaceBinder. | 41 // InterfaceFactory, the default InterfaceBinder supplied must outlive |
| 42 // Connection. |
| 42 // | 43 // |
| 43 // Just as with InterfaceFactory, InterfaceBinder must outlive Connection. | 44 // A Connection returned via Shell::ConnectToApplication() is owned by the |
| 44 // | 45 // caller. |
| 45 // An Connection's lifetime is managed by an ShellConnection. To close a | 46 // An Connection received via AcceptConnection is owned by the ShellConnection. |
| 46 // connection, call CloseConnection which will destroy this object. | 47 // To close a connection, call CloseConnection which will destroy this object. |
| 47 class Connection { | 48 class Connection { |
| 48 public: | 49 public: |
| 49 virtual ~Connection() {} | 50 virtual ~Connection() {} |
| 50 | 51 |
| 51 class TestApi { | 52 class TestApi { |
| 52 public: | 53 public: |
| 53 explicit TestApi(Connection* connection) : connection_(connection) {} | 54 explicit TestApi(Connection* connection) : connection_(connection) {} |
| 54 base::WeakPtr<Connection> GetWeakPtr() { | 55 base::WeakPtr<Connection> GetWeakPtr() { |
| 55 return connection_->GetWeakPtr(); | 56 return connection_->GetWeakPtr(); |
| 56 } | 57 } |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 138 // some filtering policy preventing this interface from being exposed). | 139 // some filtering policy preventing this interface from being exposed). |
| 139 virtual bool SetInterfaceBinderForName(InterfaceBinder* binder, | 140 virtual bool SetInterfaceBinderForName(InterfaceBinder* binder, |
| 140 const std::string& name) = 0; | 141 const std::string& name) = 0; |
| 141 | 142 |
| 142 virtual base::WeakPtr<Connection> GetWeakPtr() = 0; | 143 virtual base::WeakPtr<Connection> GetWeakPtr() = 0; |
| 143 }; | 144 }; |
| 144 | 145 |
| 145 } // namespace mojo | 146 } // namespace mojo |
| 146 | 147 |
| 147 #endif // MOJO_SHELL_PUBLIC_CPP_CONNECTION_H_ | 148 #endif // MOJO_SHELL_PUBLIC_CPP_CONNECTION_H_ |
| OLD | NEW |