| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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_CONNECTION_H_ | 5 #ifndef MOJO_SHELL_PUBLIC_CPP_SHELL_CONNECTION_H_ |
| 6 #define MOJO_SHELL_PUBLIC_CPP_SHELL_CONNECTION_H_ | 6 #define MOJO_SHELL_PUBLIC_CPP_SHELL_CONNECTION_H_ |
| 7 | 7 |
| 8 #include <utility> | 8 #include <utility> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 42 // | 42 // |
| 43 // Instances of this class are constructed with an implementation of the Shell | 43 // Instances of this class are constructed with an implementation of the Shell |
| 44 // Client Lib's mojo::ShellClient interface. See documentation in shell_client.h | 44 // Client Lib's mojo::ShellClient interface. See documentation in shell_client.h |
| 45 // for details. | 45 // for details. |
| 46 // | 46 // |
| 47 // Though this class provides the canonical implementation of the Shell Client | 47 // Though this class provides the canonical implementation of the Shell Client |
| 48 // lib's mojo::Shell interface, this interface should not be reached through | 48 // lib's mojo::Shell interface, this interface should not be reached through |
| 49 // pointers to this type. | 49 // pointers to this type. |
| 50 class ShellConnection : public Shell, public shell::mojom::ShellClient { | 50 class ShellConnection : public Shell, public shell::mojom::ShellClient { |
| 51 public: | 51 public: |
| 52 class TestApi { | |
| 53 public: | |
| 54 explicit TestApi(ShellConnection* shell_connection) | |
| 55 : shell_connection_(shell_connection) {} | |
| 56 | |
| 57 void UnbindConnections( | |
| 58 InterfaceRequest<shell::mojom::ShellClient>* request, | |
| 59 shell::mojom::ShellPtr* shell) { | |
| 60 shell_connection_->UnbindConnections(request, shell); | |
| 61 } | |
| 62 | |
| 63 private: | |
| 64 ShellConnection* shell_connection_; | |
| 65 }; | |
| 66 | |
| 67 // Does not take ownership of |delegate|, which must remain valid for the | 52 // Does not take ownership of |delegate|, which must remain valid for the |
| 68 // lifetime of ShellConnection. | 53 // lifetime of ShellConnection. |
| 69 ShellConnection(mojo::ShellClient* client, | 54 ShellConnection(mojo::ShellClient* client, |
| 70 InterfaceRequest<shell::mojom::ShellClient> request); | 55 InterfaceRequest<shell::mojom::ShellClient> request); |
| 71 // Constructs an ShellConnection with a custom termination closure. This | |
| 72 // closure is invoked on Quit() instead of the default behavior of quitting | |
| 73 // the current base::MessageLoop. | |
| 74 ShellConnection(mojo::ShellClient* client, | |
| 75 InterfaceRequest<shell::mojom::ShellClient> request, | |
| 76 const Closure& termination_closure); | |
| 77 ~ShellConnection() override; | 56 ~ShellConnection() override; |
| 78 | 57 |
| 79 // Block the calling thread until the Initialize() method is called by the | 58 // Block the calling thread until the Initialize() method is called by the |
| 80 // shell. | 59 // shell. |
| 81 void WaitForInitialize(); | 60 void WaitForInitialize(); |
| 82 | 61 |
| 83 private: | 62 private: |
| 84 friend AppRefCountImpl; | 63 friend AppRefCountImpl; |
| 85 | 64 |
| 86 // Shell: | 65 // Shell: |
| 87 scoped_ptr<Connection> Connect(const std::string& url) override; | 66 scoped_ptr<Connection> Connect(const std::string& url) override; |
| 88 scoped_ptr<Connection> Connect(Connector::ConnectParams* params) override; | 67 scoped_ptr<Connection> Connect(Connector::ConnectParams* params) override; |
| 89 scoped_ptr<Connector> CloneConnector() const override; | 68 scoped_ptr<Connector> CloneConnector() const override; |
| 69 scoped_ptr<AppRefCount> CreateAppRefCount() override; |
| 90 void Quit() override; | 70 void Quit() override; |
| 91 scoped_ptr<AppRefCount> CreateAppRefCount() override; | |
| 92 | 71 |
| 93 // shell::mojom::ShellClient: | 72 // shell::mojom::ShellClient: |
| 94 void Initialize(shell::mojom::ShellPtr shell, | 73 void Initialize(shell::mojom::ConnectorPtr connector, |
| 95 const mojo::String& url, | 74 const mojo::String& url, |
| 96 uint32_t id, | 75 uint32_t id, |
| 97 uint32_t user_id) override; | 76 uint32_t user_id) override; |
| 98 void AcceptConnection( | 77 void AcceptConnection( |
| 99 const String& requestor_url, | 78 const String& requestor_url, |
| 100 uint32_t requestor_id, | 79 uint32_t requestor_id, |
| 101 uint32_t requestor_user_id, | 80 uint32_t requestor_user_id, |
| 102 shell::mojom::InterfaceProviderRequest remote_interfaces, | 81 shell::mojom::InterfaceProviderRequest remote_interfaces, |
| 103 shell::mojom::InterfaceProviderPtr local_interfaces, | 82 shell::mojom::InterfaceProviderPtr local_interfaces, |
| 104 Array<String> allowed_interfaces, | 83 Array<String> allowed_interfaces, |
| 105 const String& url) override; | 84 const String& url) override; |
| 106 void OnQuitRequested(const Callback<void(bool)>& callback) override; | |
| 107 | 85 |
| 108 void OnConnectionError(); | 86 void OnConnectionError(); |
| 109 | 87 |
| 110 // Called from Quit() when there is no Shell connection, or asynchronously | |
| 111 // from Quit() once the Shell has OK'ed shutdown. | |
| 112 void QuitNow(); | |
| 113 | |
| 114 // Unbinds the Shell and Application connections. Can be used to re-bind the | |
| 115 // handles to another implementation of ShellConnection, for instance when | |
| 116 // running apptests. | |
| 117 void UnbindConnections(InterfaceRequest<shell::mojom::ShellClient>* request, | |
| 118 shell::mojom::ShellPtr* shell); | |
| 119 | |
| 120 // Called from AppRefCountImpl. | 88 // Called from AppRefCountImpl. |
| 121 void AddRef(); | 89 void AddRef(); |
| 122 void Release(); | 90 void Release(); |
| 123 | 91 |
| 124 // We track the lifetime of incoming connection registries as it more | 92 // We track the lifetime of incoming connection registries as it more |
| 125 // convenient for the client. | 93 // convenient for the client. |
| 126 ScopedVector<Connection> incoming_connections_; | 94 ScopedVector<Connection> incoming_connections_; |
| 127 mojo::ShellClient* client_; | 95 mojo::ShellClient* client_; |
| 128 Binding<shell::mojom::ShellClient> binding_; | 96 Binding<shell::mojom::ShellClient> binding_; |
| 129 shell::mojom::ShellPtr shell_; | |
| 130 scoped_ptr<Connector> connector_; | 97 scoped_ptr<Connector> connector_; |
| 131 Closure termination_closure_; | |
| 132 bool quit_requested_; | |
| 133 int ref_count_; | 98 int ref_count_; |
| 134 base::WeakPtrFactory<ShellConnection> weak_factory_; | 99 base::WeakPtrFactory<ShellConnection> weak_factory_; |
| 135 | 100 |
| 136 MOJO_DISALLOW_COPY_AND_ASSIGN(ShellConnection); | 101 MOJO_DISALLOW_COPY_AND_ASSIGN(ShellConnection); |
| 137 }; | 102 }; |
| 138 | 103 |
| 139 } // namespace mojo | 104 } // namespace mojo |
| 140 | 105 |
| 141 #endif // MOJO_SHELL_PUBLIC_CPP_SHELL_CONNECTION_H_ | 106 #endif // MOJO_SHELL_PUBLIC_CPP_SHELL_CONNECTION_H_ |
| OLD | NEW |