| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef MOJO_SHELL_PUBLIC_CPP_SHELL_CONNECTION_H_ | |
| 6 #define MOJO_SHELL_PUBLIC_CPP_SHELL_CONNECTION_H_ | |
| 7 | |
| 8 #include <utility> | |
| 9 #include <vector> | |
| 10 | |
| 11 #include "base/callback.h" | |
| 12 #include "base/macros.h" | |
| 13 #include "base/memory/scoped_vector.h" | |
| 14 #include "mojo/public/cpp/bindings/binding.h" | |
| 15 #include "mojo/public/cpp/bindings/callback.h" | |
| 16 #include "mojo/public/cpp/system/core.h" | |
| 17 #include "mojo/shell/public/cpp/shell_client.h" | |
| 18 #include "mojo/shell/public/interfaces/connector.mojom.h" | |
| 19 #include "mojo/shell/public/interfaces/shell_client.mojom.h" | |
| 20 | |
| 21 namespace mojo { | |
| 22 | |
| 23 class Connector; | |
| 24 | |
| 25 // Encapsulates a connection to the Mojo Shell in two parts: | |
| 26 // - a bound InterfacePtr to mojo::shell::mojom::Shell, the primary mechanism | |
| 27 // by which the instantiating application interacts with other services | |
| 28 // brokered by the Mojo Shell. | |
| 29 // - a bound InterfaceRequest of mojo::shell::mojom::ShellClient, an interface | |
| 30 // used by the Mojo Shell to inform this application of lifecycle events and | |
| 31 // inbound connections brokered by it. | |
| 32 // | |
| 33 // This class should be used in two scenarios: | |
| 34 // - During early startup to bind the mojo::shell::mojom::ShellClientRequest | |
| 35 // obtained from the Mojo Shell. This is typically in response to either | |
| 36 // MojoMain() or main(). | |
| 37 // - In an implementation of mojo::shell::mojom::ContentHandler to bind the | |
| 38 // mojo::shell::mojom::ShellClientRequest passed via StartApplication. In this | |
| 39 // scenario there can be many instances of this class per process. | |
| 40 // | |
| 41 // 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 | |
| 43 // for details. | |
| 44 // | |
| 45 class ShellConnection : public shell::mojom::ShellClient { | |
| 46 public: | |
| 47 // Creates a new ShellConnection bound to |request|. This connection may be | |
| 48 // used immediately to make outgoing connections via connector(). Does not | |
| 49 // take ownership of |client|, which must remain valid for the lifetime of | |
| 50 // ShellConnection. | |
| 51 ShellConnection(mojo::ShellClient* client, | |
| 52 shell::mojom::ShellClientRequest request); | |
| 53 | |
| 54 ~ShellConnection() override; | |
| 55 | |
| 56 Connector* connector() { return connector_.get(); } | |
| 57 | |
| 58 // TODO(rockot): Remove this. http://crbug.com/594852. | |
| 59 void set_initialize_handler(const base::Closure& callback); | |
| 60 | |
| 61 // TODO(rockot): Remove this once we get rid of app tests. | |
| 62 void SetAppTestConnectorForTesting(shell::mojom::ConnectorPtr connector); | |
| 63 | |
| 64 // Specify a function to be called when the connection to the shell is lost. | |
| 65 void set_connection_lost_closure(const base::Closure& closure) { | |
| 66 connection_lost_closure_ = closure; | |
| 67 } | |
| 68 | |
| 69 private: | |
| 70 // shell::mojom::ShellClient: | |
| 71 void Initialize(shell::mojom::IdentityPtr identity, | |
| 72 uint32_t id, | |
| 73 const InitializeCallback& callback) override; | |
| 74 void AcceptConnection( | |
| 75 shell::mojom::IdentityPtr source, | |
| 76 uint32_t source_id, | |
| 77 shell::mojom::InterfaceProviderRequest remote_interfaces, | |
| 78 shell::mojom::InterfaceProviderPtr local_interfaces, | |
| 79 shell::mojom::CapabilityRequestPtr allowed_capabilities, | |
| 80 const String& name) override; | |
| 81 | |
| 82 void OnConnectionError(); | |
| 83 | |
| 84 // A callback called when Initialize() is run. | |
| 85 base::Closure initialize_handler_; | |
| 86 | |
| 87 // We track the lifetime of incoming connection registries as it more | |
| 88 // convenient for the client. | |
| 89 ScopedVector<Connection> incoming_connections_; | |
| 90 | |
| 91 // A pending Connector request which will eventually be passed to the shell. | |
| 92 shell::mojom::ConnectorRequest pending_connector_request_; | |
| 93 | |
| 94 mojo::ShellClient* client_; | |
| 95 Binding<shell::mojom::ShellClient> binding_; | |
| 96 scoped_ptr<Connector> connector_; | |
| 97 | |
| 98 base::Closure connection_lost_closure_; | |
| 99 | |
| 100 DISALLOW_COPY_AND_ASSIGN(ShellConnection); | |
| 101 }; | |
| 102 | |
| 103 } // namespace mojo | |
| 104 | |
| 105 #endif // MOJO_SHELL_PUBLIC_CPP_SHELL_CONNECTION_H_ | |
| OLD | NEW |