Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(190)

Side by Side Diff: services/shell/public/cpp/connection.h

Issue 2419723002: Move services/shell to services/service_manager (Closed)
Patch Set: rebase Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « services/shell/public/cpp/connect.h ('k') | services/shell/public/cpp/connector.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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_SHELL_PUBLIC_CPP_CONNECTION_H_
6 #define SERVICES_SHELL_PUBLIC_CPP_CONNECTION_H_
7
8 #include "base/memory/weak_ptr.h"
9 #include "services/shell/public/cpp/identity.h"
10 #include "services/shell/public/cpp/interface_provider.h"
11 #include "services/shell/public/interfaces/connector.mojom.h"
12
13 namespace shell {
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 shell has not yet processed the connection.
25 PENDING,
26
27 // The shell processed the connection and it was established. GetResult()
28 // returns mojom::ConnectionResult::SUCCESS.
29 CONNECTED,
30
31 // The shell processed the connection and establishment was prevented by
32 // 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 shell.
62 // Call AddConnectionCompletedClosure() to schedule a closure to be run when
63 // 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 shell.
74 virtual mojom::ConnectResult GetResult() const = 0;
75
76 // Returns true if the connection has not yet been processed by the shell.
77 virtual bool IsPending() const = 0;
78
79 // Register a closure to be run when the connection has been completed by the
80 // shell and remote metadata is available. Useful only for connections created
81 // via Connector::Connect(). Once the connection is complete, metadata is
82 // available immediately.
83 virtual void AddConnectionCompletedClosure(const base::Closure& callback) = 0;
84
85 // Returns an object encapsulating a remote InterfaceProvider.
86 virtual InterfaceProvider* GetRemoteInterfaces() = 0;
87
88 protected:
89 virtual base::WeakPtr<Connection> GetWeakPtr() = 0;
90 };
91
92 } // namespace shell
93
94 #endif // SERVICES_SHELL_PUBLIC_CPP_CONNECTION_H_
OLDNEW
« no previous file with comments | « services/shell/public/cpp/connect.h ('k') | services/shell/public/cpp/connector.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698