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

Side by Side Diff: mojo/shell/public/cpp/shell.h

Issue 1725353003: Eliminate mojo::Shell client lib class (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@15connector
Patch Set: . Created 4 years, 10 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
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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_SHELL_H_ 5 #ifndef MOJO_SHELL_PUBLIC_CPP_SHELL_H_
6 #define MOJO_SHELL_PUBLIC_CPP_SHELL_H_ 6 #define MOJO_SHELL_PUBLIC_CPP_SHELL_H_
7 7
8 #include "mojo/shell/public/cpp/connection.h"
9 #include "mojo/shell/public/cpp/connector.h" 8 #include "mojo/shell/public/cpp/connector.h"
10 #include "mojo/shell/public/interfaces/shell.mojom.h"
11 #include "url/gurl.h"
12 9
13 namespace mojo { 10 namespace mojo {
14 11
15 // An interface implementation can keep this object as a member variable to 12 using Shell = Connector;
16 // hold a reference to the ShellConnection, keeping it alive as long as the
17 // bound implementation exists.
18 // Since interface implementations can be bound on different threads than the
19 // ShellConnection, this class is safe to use on any thread. However, each
20 // instance should only be used on one thread at a time (otherwise there'll be
21 // races between the AddRef resulting from cloning and destruction).
22 class AppRefCount {
23 public:
24 virtual ~AppRefCount() {}
25
26 virtual scoped_ptr<AppRefCount> Clone() = 0;
27 };
28
29 // An interface that encapsulates the Mojo Shell's broker interface by which
30 // connections between applications are established. Implemented by
31 // ShellConnection, this is the primary interface exposed to clients.
32 class Shell {
33 public:
34 // Requests a new connection to an application. Returns a pointer to the
35 // connection if the connection is permitted by this application's delegate,
36 // or nullptr otherwise. Caller takes ownership.
37 virtual scoped_ptr<Connection> Connect(const std::string& url) = 0;
38 virtual scoped_ptr<Connection> Connect(Connector::ConnectParams* params) = 0;
39
40 // Connect to application identified by |request->url| and connect to the
41 // service implementation of the interface identified by |Interface|.
42 template <typename Interface>
43 void ConnectToInterface(Connector::ConnectParams* params,
44 InterfacePtr<Interface>* ptr) {
45 scoped_ptr<Connection> connection = Connect(params);
46 if (connection)
47 connection->GetInterface(ptr);
48 }
49 template <typename Interface>
50 void ConnectToInterface(const std::string& url,
51 InterfacePtr<Interface>* ptr) {
52 Connector::ConnectParams params(url);
53 return ConnectToInterface(&params, ptr);
54 }
55
56 // Returns a clone of the ShellConnection's Connector that can be passed to
57 // other threads.
58 virtual scoped_ptr<Connector> CloneConnector() const = 0;
59
60 // Quits the message loop run by the ApplicationRunner, which causes this
61 // object to be destructed and the application to quit.
62 virtual void Quit() = 0;
63
64 // Create an object that can be used to refcount the lifetime of the
65 // application. The returned object may be cloned, and when the refcount falls
66 // to zero Quit() is called.
67 virtual scoped_ptr<AppRefCount> CreateAppRefCount() = 0;
68 };
69 13
70 } // namespace mojo 14 } // namespace mojo
71 15
72 #endif // MOJO_SHELL_PUBLIC_CPP_SHELL_H_ 16 #endif // MOJO_SHELL_PUBLIC_CPP_SHELL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698