| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef SERVICES_SERVICE_MANAGER_PUBLIC_CPP_CONNECTION_H_ | |
| 6 #define SERVICES_SERVICE_MANAGER_PUBLIC_CPP_CONNECTION_H_ | |
| 7 | |
| 8 #include "base/memory/weak_ptr.h" | |
| 9 #include "services/service_manager/public/cpp/identity.h" | |
| 10 #include "services/service_manager/public/cpp/interface_provider.h" | |
| 11 #include "services/service_manager/public/interfaces/connector.mojom.h" | |
| 12 | |
| 13 namespace service_manager { | |
| 14 | |
| 15 class InterfaceProvider; | |
| 16 | |
| 17 // Represents a connection to another application. An implementation of this | |
| 18 // interface is returned from Connector::Connect(). | |
| 19 class Connection { | |
| 20 public: | |
| 21 virtual ~Connection() {} | |
| 22 | |
| 23 enum class State { | |
| 24 // The service manager has not yet processed the connection. | |
| 25 PENDING, | |
| 26 | |
| 27 // The service manager processed the connection and it was established. | |
| 28 // GetResult() returns mojom::ConnectionResult::SUCCESS. | |
| 29 CONNECTED, | |
| 30 | |
| 31 // The service manager processed the connection and establishment was | |
| 32 // prevented by an error, call GetResult(). | |
| 33 DISCONNECTED | |
| 34 }; | |
| 35 | |
| 36 class TestApi { | |
| 37 public: | |
| 38 explicit TestApi(Connection* connection) : connection_(connection) {} | |
| 39 base::WeakPtr<Connection> GetWeakPtr() { | |
| 40 return connection_->GetWeakPtr(); | |
| 41 } | |
| 42 | |
| 43 private: | |
| 44 Connection* connection_; | |
| 45 }; | |
| 46 | |
| 47 // Binds |ptr| to an implementation of Interface in the remote application. | |
| 48 // |ptr| can immediately be used to start sending requests to the remote | |
| 49 // interface. | |
| 50 template <typename Interface> | |
| 51 void GetInterface(mojo::InterfacePtr<Interface>* ptr) { | |
| 52 GetRemoteInterfaces()->GetInterface(ptr); | |
| 53 } | |
| 54 template <typename Interface> | |
| 55 void GetInterface(mojo::InterfaceRequest<Interface> request) { | |
| 56 GetRemoteInterfaces()->GetInterface(std::move(request)); | |
| 57 } | |
| 58 | |
| 59 // Returns the remote identity. While the connection is in the pending state, | |
| 60 // the user_id() field will be the value passed via Connect(). After the | |
| 61 // connection is completed, it will change to the value assigned by the | |
| 62 // service manager. Call AddConnectionCompletedClosure() to schedule a closure | |
| 63 // to be run when the resolved user id is available. | |
| 64 virtual const Identity& GetRemoteIdentity() const = 0; | |
| 65 | |
| 66 // Register a handler to receive an error notification on the pipe to the | |
| 67 // remote application's InterfaceProvider. | |
| 68 virtual void SetConnectionLostClosure(const base::Closure& handler) = 0; | |
| 69 | |
| 70 // Returns the result of the connection. This function should only be called | |
| 71 // when the connection state is not pending. Call | |
| 72 // AddConnectionCompletedClosure() to schedule a closure to be run when the | |
| 73 // connection is processed by the service manager. | |
| 74 virtual mojom::ConnectResult GetResult() const = 0; | |
| 75 | |
| 76 // Returns true if the connection has not yet been processed by the service | |
| 77 // manager. | |
| 78 virtual bool IsPending() const = 0; | |
| 79 | |
| 80 // Register a closure to be run when the connection has been completed by the | |
| 81 // service manager and remote metadata is available. Useful only for | |
| 82 // connections created | |
| 83 // via Connector::Connect(). Once the connection is complete, metadata is | |
| 84 // available immediately. | |
| 85 virtual void AddConnectionCompletedClosure(const base::Closure& callback) = 0; | |
| 86 | |
| 87 // Returns an object encapsulating a remote InterfaceProvider. | |
| 88 virtual InterfaceProvider* GetRemoteInterfaces() = 0; | |
| 89 | |
| 90 protected: | |
| 91 virtual base::WeakPtr<Connection> GetWeakPtr() = 0; | |
| 92 }; | |
| 93 | |
| 94 } // namespace service_manager | |
| 95 | |
| 96 #endif // SERVICES_SERVICE_MANAGER_PUBLIC_CPP_CONNECTION_H_ | |
| OLD | NEW |