| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 SHELL_APPLICATION_MANAGER_SHELL_IMPL_H_ | 5 #ifndef SHELL_APPLICATION_MANAGER_SHELL_IMPL_H_ |
| 6 #define SHELL_APPLICATION_MANAGER_SHELL_IMPL_H_ | 6 #define SHELL_APPLICATION_MANAGER_SHELL_IMPL_H_ |
| 7 | 7 |
| 8 #include "base/callback.h" | 8 #include "base/callback.h" |
| 9 #include "base/macros.h" |
| 10 #include "mojo/common/binding_set.h" |
| 9 #include "mojo/public/cpp/bindings/binding.h" | 11 #include "mojo/public/cpp/bindings/binding.h" |
| 10 #include "mojo/public/interfaces/application/application.mojom.h" | 12 #include "mojo/public/interfaces/application/application.mojom.h" |
| 13 #include "mojo/public/interfaces/application/application_connector.mojom.h" |
| 11 #include "mojo/public/interfaces/application/shell.mojom.h" | 14 #include "mojo/public/interfaces/application/shell.mojom.h" |
| 12 #include "shell/application_manager/identity.h" | 15 #include "shell/application_manager/identity.h" |
| 13 #include "url/gurl.h" | 16 #include "url/gurl.h" |
| 14 | 17 |
| 15 namespace shell { | 18 namespace shell { |
| 16 | 19 |
| 17 class ApplicationManager; | 20 class ApplicationManager; |
| 18 | 21 |
| 22 // TODO(vtl): This both implements the |Shell| interface and holds the |
| 23 // |ApplicationPtr| (from back when they were paired interfaces on the same |
| 24 // message pipe). The way it manages lifetime is dubious/wrong. We should have |
| 25 // an object holding stuff associated to an application, namely its "real" |
| 26 // |ShellImpl|, its |ApplicationPtr|, and tracking its |ApplicationConnector|s. |
| 19 class ShellImpl : public mojo::Shell { | 27 class ShellImpl : public mojo::Shell { |
| 20 public: | 28 public: |
| 21 ShellImpl(mojo::ApplicationPtr application, | 29 ShellImpl(mojo::ApplicationPtr application, |
| 22 ApplicationManager* manager, | 30 ApplicationManager* manager, |
| 23 const Identity& resolved_identity, | 31 const Identity& resolved_identity, |
| 24 const base::Closure& on_application_end); | 32 const base::Closure& on_application_end); |
| 25 | 33 |
| 26 ~ShellImpl() override; | 34 ~ShellImpl() override; |
| 27 | 35 |
| 28 void InitializeApplication(mojo::Array<mojo::String> args); | 36 void InitializeApplication(mojo::Array<mojo::String> args); |
| 29 | 37 |
| 30 void ConnectToClient(const GURL& requested_url, | 38 void ConnectToClient(const GURL& requested_url, |
| 31 const GURL& requestor_url, | 39 const GURL& requestor_url, |
| 32 mojo::InterfaceRequest<mojo::ServiceProvider> services, | 40 mojo::InterfaceRequest<mojo::ServiceProvider> services, |
| 33 mojo::ServiceProviderPtr exposed_services); | 41 mojo::ServiceProviderPtr exposed_services); |
| 34 | 42 |
| 35 mojo::Application* application() { return application_.get(); } | 43 mojo::Application* application() { return application_.get(); } |
| 36 const Identity& identity() const { return identity_; } | 44 const Identity& identity() const { return identity_; } |
| 37 base::Closure on_application_end() const { return on_application_end_; } | 45 base::Closure on_application_end() const { return on_application_end_; } |
| 38 | 46 |
| 39 private: | 47 private: |
| 48 class ApplicationConnectorImpl : public mojo::ApplicationConnector { |
| 49 public: |
| 50 explicit ApplicationConnectorImpl(mojo::Shell* shell) : shell_(shell) {} |
| 51 ~ApplicationConnectorImpl() override {} |
| 52 |
| 53 void ConnectToApplication( |
| 54 const mojo::String& app_url, |
| 55 mojo::InterfaceRequest<mojo::ServiceProvider> services, |
| 56 mojo::ServiceProviderPtr exposed_services) override { |
| 57 shell_->ConnectToApplication(app_url, services.Pass(), |
| 58 exposed_services.Pass()); |
| 59 } |
| 60 |
| 61 private: |
| 62 mojo::Shell* const shell_; |
| 63 DISALLOW_COPY_AND_ASSIGN(ApplicationConnectorImpl); |
| 64 }; |
| 65 |
| 40 // mojo::Shell implementation: | 66 // mojo::Shell implementation: |
| 41 void ConnectToApplication( | 67 void ConnectToApplication( |
| 42 const mojo::String& app_url, | 68 const mojo::String& app_url, |
| 43 mojo::InterfaceRequest<mojo::ServiceProvider> services, | 69 mojo::InterfaceRequest<mojo::ServiceProvider> services, |
| 44 mojo::ServiceProviderPtr exposed_services) override; | 70 mojo::ServiceProviderPtr exposed_services) override; |
| 71 void CreateApplicationConnector( |
| 72 mojo::InterfaceRequest<mojo::ApplicationConnector> |
| 73 application_connector_request) override; |
| 45 | 74 |
| 46 ApplicationManager* const manager_; | 75 ApplicationManager* const manager_; |
| 47 const Identity identity_; | 76 const Identity identity_; |
| 48 base::Closure on_application_end_; | 77 base::Closure on_application_end_; |
| 49 mojo::ApplicationPtr application_; | 78 mojo::ApplicationPtr application_; |
| 50 mojo::Binding<mojo::Shell> binding_; | 79 mojo::Binding<mojo::Shell> binding_; |
| 51 | 80 |
| 81 ApplicationConnectorImpl application_connector_impl_; |
| 82 mojo::BindingSet<mojo::ApplicationConnector> application_connectors_; |
| 83 |
| 52 DISALLOW_COPY_AND_ASSIGN(ShellImpl); | 84 DISALLOW_COPY_AND_ASSIGN(ShellImpl); |
| 53 }; | 85 }; |
| 54 | 86 |
| 55 } // namespace shell | 87 } // namespace shell |
| 56 | 88 |
| 57 #endif // SHELL_APPLICATION_MANAGER_SHELL_IMPL_H_ | 89 #endif // SHELL_APPLICATION_MANAGER_SHELL_IMPL_H_ |
| OLD | NEW |