Chromium Code Reviews| 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 |
| 11 #include "base/macros.h" | 11 #include "base/macros.h" |
| 12 #include "base/memory/scoped_vector.h" | 12 #include "base/memory/scoped_vector.h" |
| 13 #include "base/memory/weak_ptr.h" | |
| 14 #include "mojo/public/cpp/bindings/binding.h" | 13 #include "mojo/public/cpp/bindings/binding.h" |
| 15 #include "mojo/public/cpp/bindings/callback.h" | 14 #include "mojo/public/cpp/bindings/callback.h" |
| 16 #include "mojo/public/cpp/system/core.h" | 15 #include "mojo/public/cpp/system/core.h" |
| 17 #include "mojo/shell/public/cpp/shell_client.h" | 16 #include "mojo/shell/public/cpp/shell_client.h" |
| 18 #include "mojo/shell/public/interfaces/connector.mojom.h" | 17 #include "mojo/shell/public/interfaces/connector.mojom.h" |
| 19 #include "mojo/shell/public/interfaces/shell_client.mojom.h" | 18 #include "mojo/shell/public/interfaces/shell_client.mojom.h" |
| 20 | 19 |
| 21 namespace mojo { | 20 namespace mojo { |
| 22 | 21 |
| 23 class Connector; | 22 class Connector; |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 37 // - In an implementation of mojo::shell::mojom::ContentHandler to bind the | 36 // - In an implementation of mojo::shell::mojom::ContentHandler to bind the |
| 38 // mojo::shell::mojom::ShellClientRequest passed via StartApplication. In this | 37 // mojo::shell::mojom::ShellClientRequest passed via StartApplication. In this |
| 39 // scenario there can be many instances of this class per process. | 38 // scenario there can be many instances of this class per process. |
| 40 // | 39 // |
| 41 // Instances of this class are constructed with an implementation of the Shell | 40 // Instances of this class are constructed with an implementation of the Shell |
| 42 // Client Lib's mojo::ShellClient interface. See documentation in shell_client.h | 41 // Client Lib's mojo::ShellClient interface. See documentation in shell_client.h |
| 43 // for details. | 42 // for details. |
| 44 // | 43 // |
| 45 class ShellConnection : public shell::mojom::ShellClient { | 44 class ShellConnection : public shell::mojom::ShellClient { |
| 46 public: | 45 public: |
| 47 // Does not take ownership of |delegate|, which must remain valid for the | 46 // Creates a new ShellConnection to eventually be bound to a |
| 47 // ShellClientRequest (see BindToRequest()). This connection may be used | |
| 48 // immediately to begin making outgoing connections via connector(). | |
| 49 // | |
| 50 // Does not take ownership of |client|, which must remain valid for the | |
| 48 // lifetime of ShellConnection. | 51 // lifetime of ShellConnection. |
| 52 explicit ShellConnection(mojo::ShellClient* client); | |
| 53 | |
| 54 // Like above but binds to |request| upon construction. | |
| 49 ShellConnection(mojo::ShellClient* client, | 55 ShellConnection(mojo::ShellClient* client, |
| 50 InterfaceRequest<shell::mojom::ShellClient> request); | 56 shell::mojom::ShellClientRequest request); |
| 57 | |
| 51 ~ShellConnection() override; | 58 ~ShellConnection() override; |
| 52 | 59 |
| 53 // Block the calling thread until the Initialize() method is called by the | |
| 54 // shell. | |
| 55 void WaitForInitialize(); | |
| 56 | |
| 57 Connector* connector() { return connector_.get(); } | 60 Connector* connector() { return connector_.get(); } |
| 58 | 61 |
| 62 // Binds this ShellConnection to a client request if one was not available at | |
| 63 // construction time. | |
| 64 void BindToRequest(shell::mojom::ShellClientRequest request); | |
| 65 | |
| 66 // TODO(rockot): Remove this once we get rid of app tests. | |
|
Ben Goodger (Google)
2016/03/13 04:16:24
I sent a note to chromium-mojo deprecating apptest
Ken Rockot(use gerrit already)
2016/03/13 16:14:25
Cool, I was going to try to do some conversions to
| |
| 67 void SetAppTestConnectorForTesting(shell::mojom::ConnectorPtr connector); | |
| 68 | |
| 59 private: | 69 private: |
| 60 // shell::mojom::ShellClient: | 70 // shell::mojom::ShellClient: |
| 61 void Initialize(shell::mojom::ConnectorPtr connector, | 71 void Initialize(shell::mojom::IdentityPtr identity, |
| 62 shell::mojom::IdentityPtr identity, | 72 uint32_t id, |
| 63 uint32_t id) override; | 73 const InitializeCallback& callback) override; |
| 64 void AcceptConnection( | 74 void AcceptConnection( |
| 65 shell::mojom::IdentityPtr source, | 75 shell::mojom::IdentityPtr source, |
| 66 uint32_t source_id, | 76 uint32_t source_id, |
| 67 shell::mojom::InterfaceProviderRequest remote_interfaces, | 77 shell::mojom::InterfaceProviderRequest remote_interfaces, |
| 68 shell::mojom::InterfaceProviderPtr local_interfaces, | 78 shell::mojom::InterfaceProviderPtr local_interfaces, |
| 69 shell::mojom::CapabilityRequestPtr allowed_capabilities, | 79 shell::mojom::CapabilityRequestPtr allowed_capabilities, |
| 70 const String& name) override; | 80 const String& name) override; |
| 71 | 81 |
| 72 void OnConnectionError(); | 82 void OnConnectionError(); |
| 73 | 83 |
| 74 // We track the lifetime of incoming connection registries as it more | 84 // We track the lifetime of incoming connection registries as it more |
| 75 // convenient for the client. | 85 // convenient for the client. |
| 76 ScopedVector<Connection> incoming_connections_; | 86 ScopedVector<Connection> incoming_connections_; |
| 87 | |
| 88 // A pending Connector request which will eventually be passed to the shell. | |
| 89 shell::mojom::ConnectorRequest pending_connector_request_; | |
| 90 | |
| 77 mojo::ShellClient* client_; | 91 mojo::ShellClient* client_; |
| 78 Binding<shell::mojom::ShellClient> binding_; | 92 Binding<shell::mojom::ShellClient> binding_; |
| 79 scoped_ptr<Connector> connector_; | 93 scoped_ptr<Connector> connector_; |
| 80 base::WeakPtrFactory<ShellConnection> weak_factory_; | |
| 81 | 94 |
| 82 DISALLOW_COPY_AND_ASSIGN(ShellConnection); | 95 DISALLOW_COPY_AND_ASSIGN(ShellConnection); |
| 83 }; | 96 }; |
| 84 | 97 |
| 85 } // namespace mojo | 98 } // namespace mojo |
| 86 | 99 |
| 87 #endif // MOJO_SHELL_PUBLIC_CPP_SHELL_CONNECTION_H_ | 100 #endif // MOJO_SHELL_PUBLIC_CPP_SHELL_CONNECTION_H_ |
| OLD | NEW |