Chromium Code Reviews| OLD | NEW |
|---|---|
| (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 class Connector { | |
| 27 public: | |
| 28 class ConnectParams { | |
| 29 public: | |
| 30 explicit ConnectParams(const std::string& url); | |
|
sky
2016/02/24 17:08:07
How come this takes a string rather than a GURL?
| |
| 31 ~ConnectParams(); | |
| 32 | |
| 33 const GURL& url() { return url_; } | |
| 34 shell::mojom::CapabilityFilterPtr TakeFilter() { | |
| 35 return std::move(filter_); | |
| 36 } | |
| 37 void set_filter(shell::mojom::CapabilityFilterPtr filter) { | |
| 38 filter_ = std::move(filter); | |
| 39 } | |
| 40 void set_user_id(uint32_t user_id) { user_id_ = user_id; } | |
| 41 uint32_t user_id() const { return user_id_; } | |
| 42 | |
| 43 private: | |
| 44 GURL url_; | |
| 45 shell::mojom::CapabilityFilterPtr filter_; | |
| 46 uint32_t user_id_; | |
| 47 | |
| 48 DISALLOW_COPY_AND_ASSIGN(ConnectParams); | |
| 49 }; | |
| 50 | |
| 51 // Requests a new connection to an application. Returns a pointer to the | |
| 52 // connection if the connection is permitted by this application's delegate, | |
| 53 // or nullptr otherwise. Caller takes ownership. | |
| 54 // Once this method is called, this object is bound to the thread on which the | |
| 55 // call took place. To pass to another thread, call Clone() and pass the | |
| 56 // result. | |
| 57 virtual scoped_ptr<Connection> Connect(const std::string& url) = 0; | |
|
sky
2016/02/24 17:08:07
Similar comment about string vs GURL.
| |
| 58 virtual scoped_ptr<Connection> Connect(ConnectParams* params) = 0; | |
| 59 | |
| 60 // Connect to application identified by |request->url| and connect to the | |
| 61 // service implementation of the interface identified by |Interface|. | |
| 62 template <typename Interface> | |
| 63 void ConnectToInterface(ConnectParams* params, InterfacePtr<Interface>* ptr) { | |
| 64 scoped_ptr<Connection> connection = Connect(params); | |
| 65 if (connection) | |
| 66 connection->GetInterface(ptr); | |
| 67 } | |
| 68 template <typename Interface> | |
| 69 void ConnectToInterface(const std::string& url, | |
| 70 InterfacePtr<Interface>* ptr) { | |
| 71 ConnectParams params(url); | |
| 72 params.set_filter(CreatePermissiveCapabilityFilter()); | |
| 73 return ConnectToInterface(¶ms, ptr); | |
| 74 } | |
| 75 | |
| 76 // Creates a new instance of this class which may be passed to another thread. | |
| 77 // The returned object may be passed multiple times until Connect() is called, | |
| 78 // at which point this method must be called again to pass again. | |
| 79 virtual scoped_ptr<Connector> Clone() = 0; | |
| 80 }; | |
| 81 | |
| 82 } // namespace mojo | |
| 83 | |
| 84 #endif // MOJO_SHELL_PUBLIC_CPP_CONNECTOR_H_ | |
| OLD | NEW |