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

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

Issue 1728083002: Extract a Connector interface from Shell that can be cloned & passed to other threads (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@12uid
Patch Set: . Created 4 years, 9 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 | « mojo/shell/public/cpp/BUILD.gn ('k') | mojo/shell/public/cpp/lib/application_test_base.cc » ('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 2016 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 MOJO_SHELL_PUBLIC_CPP_CONNECTOR_H_
6 #define MOJO_SHELL_PUBLIC_CPP_CONNECTOR_H_
7
8 #include "mojo/shell/public/cpp/connection.h"
9 #include "mojo/shell/public/interfaces/shell.mojom.h"
10 #include "url/gurl.h"
11
12 namespace mojo {
13
14 shell::mojom::CapabilityFilterPtr CreatePermissiveCapabilityFilter();
15
16 // An interface that encapsulates the Mojo Shell's broker interface by which
17 // connections between applications are established. Once Connect() is called,
18 // this class is bound to the thread the call was made on and it cannot be
19 // passed to another thread without calling Clone().
20 // An instance of this class is created internally by ShellConnection for use
21 // on the thread ShellConnection is instantiated on, and this interface is
22 // wrapped by the Shell interface.
23 // To use this interface on other threads, call Shell::CloneConnector() and
24 // pass the result to another thread. To pass to subsequent threads, call
25 // Clone() on instances of this object.
26 // While instances of this object are owned by the caller, the underlying
27 // connection with the shell is bound to the lifetime of the instance that
28 // created it, i.e. when the application is terminated the Connector pipe is
29 // closed.
30 class Connector {
31 public:
32 class ConnectParams {
33 public:
34 explicit ConnectParams(const std::string& url);
35 ~ConnectParams();
36
37 const GURL& url() { return url_; }
38 shell::mojom::CapabilityFilterPtr TakeFilter() {
39 return std::move(filter_);
40 }
41 void set_filter(shell::mojom::CapabilityFilterPtr filter) {
42 filter_ = std::move(filter);
43 }
44 void set_user_id(uint32_t user_id) { user_id_ = user_id; }
45 uint32_t user_id() const { return user_id_; }
46
47 private:
48 GURL url_;
49 shell::mojom::CapabilityFilterPtr filter_;
50 uint32_t user_id_;
51
52 DISALLOW_COPY_AND_ASSIGN(ConnectParams);
53 };
54
55 // Requests a new connection to an application. Returns a pointer to the
56 // connection if the connection is permitted by this application's delegate,
57 // or nullptr otherwise. Caller takes ownership.
58 // Once this method is called, this object is bound to the thread on which the
59 // call took place. To pass to another thread, call Clone() and pass the
60 // result.
61 virtual scoped_ptr<Connection> Connect(const std::string& url) = 0;
62 virtual scoped_ptr<Connection> Connect(ConnectParams* params) = 0;
63
64 // Connect to application identified by |request->url| and connect to the
65 // service implementation of the interface identified by |Interface|.
66 template <typename Interface>
67 void ConnectToInterface(ConnectParams* params, InterfacePtr<Interface>* ptr) {
68 scoped_ptr<Connection> connection = Connect(params);
69 if (connection)
70 connection->GetInterface(ptr);
71 }
72 template <typename Interface>
73 void ConnectToInterface(const std::string& url,
74 InterfacePtr<Interface>* ptr) {
75 ConnectParams params(url);
76 params.set_filter(CreatePermissiveCapabilityFilter());
77 return ConnectToInterface(&params, ptr);
78 }
79
80 // Creates a new instance of this class which may be passed to another thread.
81 // The returned object may be passed multiple times until Connect() is called,
82 // at which point this method must be called again to pass again.
83 virtual scoped_ptr<Connector> Clone() = 0;
84 };
85
86 } // namespace mojo
87
88 #endif // MOJO_SHELL_PUBLIC_CPP_CONNECTOR_H_
OLDNEW
« no previous file with comments | « mojo/shell/public/cpp/BUILD.gn ('k') | mojo/shell/public/cpp/lib/application_test_base.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698