| 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 #include "mandoline/services/core_services/core_services_application_delegate.h" | 5 #include "mandoline/services/core_services/core_services_application_delegate.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| 11 #include "base/single_thread_task_runner.h" | 11 #include "base/single_thread_task_runner.h" |
| 12 #include "base/threading/platform_thread.h" | 12 #include "base/threading/platform_thread.h" |
| 13 #include "base/threading/simple_thread.h" | 13 #include "base/threading/simple_thread.h" |
| 14 #include "components/clipboard/clipboard_application_delegate.h" | 14 #include "components/clipboard/clipboard_application_delegate.h" |
| 15 #include "components/filesystem/file_system_app.h" | 15 #include "components/filesystem/file_system_app.h" |
| 16 #include "components/web_view/web_view_application_delegate.h" | 16 #include "components/web_view/web_view_application_delegate.h" |
| 17 #include "mandoline/services/core_services/application_delegate_factory.h" | 17 #include "mandoline/services/core_services/application_delegate_factory.h" |
| 18 #include "mojo/logging/init_logging.h" | 18 #include "mojo/logging/init_logging.h" |
| 19 #include "mojo/message_pump/message_pump_mojo.h" | 19 #include "mojo/message_pump/message_pump_mojo.h" |
| 20 #include "mojo/services/tracing/public/cpp/tracing_impl.h" | 20 #include "mojo/services/tracing/public/cpp/tracing_impl.h" |
| 21 #include "mojo/services/tracing/tracing_app.h" | 21 #include "mojo/services/tracing/tracing_app.h" |
| 22 #include "mojo/shell/public/cpp/application_connection.h" | |
| 23 #include "mojo/shell/public/cpp/application_runner.h" | 22 #include "mojo/shell/public/cpp/application_runner.h" |
| 23 #include "mojo/shell/public/cpp/connection.h" |
| 24 #include "url/gurl.h" | 24 #include "url/gurl.h" |
| 25 | 25 |
| 26 namespace core_services { | 26 namespace core_services { |
| 27 | 27 |
| 28 // A helper class for hosting a mojo::ApplicationImpl on its own thread. | 28 // A helper class for hosting a mojo::ApplicationImpl on its own thread. |
| 29 class ApplicationThread : public base::SimpleThread { | 29 class ApplicationThread : public base::SimpleThread { |
| 30 public: | 30 public: |
| 31 ApplicationThread( | 31 ApplicationThread( |
| 32 const base::WeakPtr<CoreServicesApplicationDelegate> | 32 const base::WeakPtr<CoreServicesApplicationDelegate> |
| 33 core_services_application, | 33 core_services_application, |
| 34 const std::string& url, | 34 const std::string& url, |
| 35 scoped_ptr<mojo::ApplicationDelegate> delegate, | 35 scoped_ptr<mojo::ShellClient> delegate, |
| 36 mojo::InterfaceRequest<mojo::shell::mojom::Application> request, | 36 mojo::InterfaceRequest<mojo::shell::mojom::Application> request, |
| 37 const mojo::Callback<void()>& destruct_callback) | 37 const mojo::Callback<void()>& destruct_callback) |
| 38 : base::SimpleThread(url), | 38 : base::SimpleThread(url), |
| 39 core_services_application_(core_services_application), | 39 core_services_application_(core_services_application), |
| 40 core_services_application_task_runner_(base::MessageLoop::current() | 40 core_services_application_task_runner_(base::MessageLoop::current() |
| 41 ->task_runner()), | 41 ->task_runner()), |
| 42 url_(url), | 42 url_(url), |
| 43 delegate_(std::move(delegate)), | 43 delegate_(std::move(delegate)), |
| 44 request_(std::move(request)), | 44 request_(std::move(request)), |
| 45 destruct_callback_(destruct_callback) {} | 45 destruct_callback_(destruct_callback) {} |
| (...skipping 19 matching lines...) Expand all Loading... |
| 65 base::Bind(&CoreServicesApplicationDelegate::ApplicationThreadDestroyed, | 65 base::Bind(&CoreServicesApplicationDelegate::ApplicationThreadDestroyed, |
| 66 core_services_application_, | 66 core_services_application_, |
| 67 this)); | 67 this)); |
| 68 } | 68 } |
| 69 | 69 |
| 70 private: | 70 private: |
| 71 base::WeakPtr<CoreServicesApplicationDelegate> core_services_application_; | 71 base::WeakPtr<CoreServicesApplicationDelegate> core_services_application_; |
| 72 scoped_refptr<base::SingleThreadTaskRunner> | 72 scoped_refptr<base::SingleThreadTaskRunner> |
| 73 core_services_application_task_runner_; | 73 core_services_application_task_runner_; |
| 74 std::string url_; | 74 std::string url_; |
| 75 scoped_ptr<mojo::ApplicationDelegate> delegate_; | 75 scoped_ptr<mojo::ShellClient> delegate_; |
| 76 mojo::InterfaceRequest<mojo::shell::mojom::Application> request_; | 76 mojo::InterfaceRequest<mojo::shell::mojom::Application> request_; |
| 77 mojo::Callback<void()> destruct_callback_; | 77 mojo::Callback<void()> destruct_callback_; |
| 78 | 78 |
| 79 DISALLOW_COPY_AND_ASSIGN(ApplicationThread); | 79 DISALLOW_COPY_AND_ASSIGN(ApplicationThread); |
| 80 }; | 80 }; |
| 81 | 81 |
| 82 CoreServicesApplicationDelegate::CoreServicesApplicationDelegate() | 82 CoreServicesApplicationDelegate::CoreServicesApplicationDelegate() |
| 83 : weak_factory_(this) { | 83 : weak_factory_(this) { |
| 84 } | 84 } |
| 85 | 85 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 98 } | 98 } |
| 99 | 99 |
| 100 void CoreServicesApplicationDelegate::Initialize(mojo::Shell* shell, | 100 void CoreServicesApplicationDelegate::Initialize(mojo::Shell* shell, |
| 101 const std::string& url, | 101 const std::string& url, |
| 102 uint32_t id) { | 102 uint32_t id) { |
| 103 mojo::InitLogging(); | 103 mojo::InitLogging(); |
| 104 tracing_.Initialize(shell, url); | 104 tracing_.Initialize(shell, url); |
| 105 } | 105 } |
| 106 | 106 |
| 107 bool CoreServicesApplicationDelegate::AcceptConnection( | 107 bool CoreServicesApplicationDelegate::AcceptConnection( |
| 108 mojo::ApplicationConnection* connection) { | 108 mojo::Connection* connection) { |
| 109 connection->AddService(this); | 109 connection->AddService(this); |
| 110 return true; | 110 return true; |
| 111 } | 111 } |
| 112 | 112 |
| 113 void CoreServicesApplicationDelegate::Quit() { | 113 void CoreServicesApplicationDelegate::Quit() { |
| 114 // This will delete all threads. This also performs a blocking join, waiting | 114 // This will delete all threads. This also performs a blocking join, waiting |
| 115 // for the threads to end. | 115 // for the threads to end. |
| 116 application_threads_.clear(); | 116 application_threads_.clear(); |
| 117 weak_factory_.InvalidateWeakPtrs(); | 117 weak_factory_.InvalidateWeakPtrs(); |
| 118 } | 118 } |
| 119 | 119 |
| 120 void CoreServicesApplicationDelegate::Create( | 120 void CoreServicesApplicationDelegate::Create( |
| 121 mojo::ApplicationConnection* connection, | 121 mojo::Connection* connection, |
| 122 mojo::InterfaceRequest<mojo::shell::mojom::ContentHandler> request) { | 122 mojo::InterfaceRequest<mojo::shell::mojom::ContentHandler> request) { |
| 123 handler_bindings_.AddBinding(this, std::move(request)); | 123 handler_bindings_.AddBinding(this, std::move(request)); |
| 124 } | 124 } |
| 125 | 125 |
| 126 void CoreServicesApplicationDelegate::StartApplication( | 126 void CoreServicesApplicationDelegate::StartApplication( |
| 127 mojo::InterfaceRequest<mojo::shell::mojom::Application> request, | 127 mojo::InterfaceRequest<mojo::shell::mojom::Application> request, |
| 128 mojo::URLResponsePtr response, | 128 mojo::URLResponsePtr response, |
| 129 const mojo::Callback<void()>& destruct_callback) { | 129 const mojo::Callback<void()>& destruct_callback) { |
| 130 const std::string url = response->url; | 130 const std::string url = response->url; |
| 131 | 131 |
| 132 scoped_ptr<mojo::ApplicationDelegate> delegate; | 132 scoped_ptr<mojo::ShellClient> delegate; |
| 133 if (url == "mojo://clipboard/") { | 133 if (url == "mojo://clipboard/") { |
| 134 delegate.reset(new clipboard::ClipboardApplicationDelegate); | 134 delegate.reset(new clipboard::ClipboardApplicationDelegate); |
| 135 } else if (url == "mojo://filesystem/") { | 135 } else if (url == "mojo://filesystem/") { |
| 136 delegate.reset(new filesystem::FileSystemApp); | 136 delegate.reset(new filesystem::FileSystemApp); |
| 137 } else if (url == "mojo://tracing/") { | 137 } else if (url == "mojo://tracing/") { |
| 138 delegate.reset(new tracing::TracingApp); | 138 delegate.reset(new tracing::TracingApp); |
| 139 } else if (url == "mojo://web_view/") { | 139 } else if (url == "mojo://web_view/") { |
| 140 delegate.reset(new web_view::WebViewApplicationDelegate); | 140 delegate.reset(new web_view::WebViewApplicationDelegate); |
| 141 } else { | 141 } else { |
| 142 #if !defined(OS_ANDROID) | 142 #if !defined(OS_ANDROID) |
| 143 if (!delegate) | 143 if (!delegate) |
| 144 delegate = CreateApplicationDelegateNotAndroid(url); | 144 delegate = CreateApplicationDelegateNotAndroid(url); |
| 145 #endif | 145 #endif |
| 146 if (!delegate) | 146 if (!delegate) |
| 147 delegate = CreatePlatformSpecificApplicationDelegate(url); | 147 delegate = CreatePlatformSpecificApplicationDelegate(url); |
| 148 | 148 |
| 149 if (!delegate) | 149 if (!delegate) |
| 150 NOTREACHED() << "This application package does not support " << url; | 150 NOTREACHED() << "This application package does not support " << url; |
| 151 } | 151 } |
| 152 | 152 |
| 153 scoped_ptr<ApplicationThread> thread(new ApplicationThread( | 153 scoped_ptr<ApplicationThread> thread(new ApplicationThread( |
| 154 weak_factory_.GetWeakPtr(), url, std::move(delegate), std::move(request), | 154 weak_factory_.GetWeakPtr(), url, std::move(delegate), std::move(request), |
| 155 destruct_callback)); | 155 destruct_callback)); |
| 156 thread->Start(); | 156 thread->Start(); |
| 157 application_threads_.push_back(std::move(thread)); | 157 application_threads_.push_back(std::move(thread)); |
| 158 } | 158 } |
| 159 | 159 |
| 160 } // namespace core_services | 160 } // namespace core_services |
| OLD | NEW |