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" | 22 #include "mojo/shell/public/cpp/application_connection.h" |
23 #include "mojo/shell/public/cpp/application_impl.h" | |
24 #include "mojo/shell/public/cpp/application_runner.h" | 23 #include "mojo/shell/public/cpp/application_runner.h" |
25 #include "url/gurl.h" | 24 #include "url/gurl.h" |
26 | 25 |
27 namespace core_services { | 26 namespace core_services { |
28 | 27 |
29 // 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. |
30 class ApplicationThread : public base::SimpleThread { | 29 class ApplicationThread : public base::SimpleThread { |
31 public: | 30 public: |
32 ApplicationThread(const base::WeakPtr<CoreServicesApplicationDelegate> | 31 ApplicationThread( |
33 core_services_application, | 32 const base::WeakPtr<CoreServicesApplicationDelegate> |
34 const std::string& url, | 33 core_services_application, |
35 scoped_ptr<mojo::ApplicationDelegate> delegate, | 34 const std::string& url, |
36 mojo::ApplicationRequest request, | 35 scoped_ptr<mojo::ApplicationDelegate> delegate, |
37 const mojo::Callback<void()>& destruct_callback) | 36 mojo::InterfaceRequest<mojo::shell::mojom::Application> request, |
| 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) {} |
46 | 46 |
47 ~ApplicationThread() override { | 47 ~ApplicationThread() override { |
(...skipping 18 matching lines...) Expand all Loading... |
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::ApplicationDelegate> delegate_; |
76 mojo::ApplicationRequest 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 |
86 CoreServicesApplicationDelegate::~CoreServicesApplicationDelegate() { | 86 CoreServicesApplicationDelegate::~CoreServicesApplicationDelegate() { |
87 application_threads_.clear(); | 87 application_threads_.clear(); |
88 } | 88 } |
89 | 89 |
90 void CoreServicesApplicationDelegate::ApplicationThreadDestroyed( | 90 void CoreServicesApplicationDelegate::ApplicationThreadDestroyed( |
91 ApplicationThread* thread) { | 91 ApplicationThread* thread) { |
92 ScopedVector<ApplicationThread>::iterator iter = | 92 ScopedVector<ApplicationThread>::iterator iter = |
93 std::find(application_threads_.begin(), | 93 std::find(application_threads_.begin(), |
94 application_threads_.end(), | 94 application_threads_.end(), |
95 thread); | 95 thread); |
96 DCHECK(iter != application_threads_.end()); | 96 DCHECK(iter != application_threads_.end()); |
97 application_threads_.erase(iter); | 97 application_threads_.erase(iter); |
98 } | 98 } |
99 | 99 |
100 void CoreServicesApplicationDelegate::Initialize(mojo::ApplicationImpl* app) { | 100 void CoreServicesApplicationDelegate::Initialize(mojo::Shell* shell, |
| 101 const std::string& url, |
| 102 uint32_t id) { |
101 mojo::InitLogging(); | 103 mojo::InitLogging(); |
102 tracing_.Initialize(app); | 104 tracing_.Initialize(shell, url); |
103 } | 105 } |
104 | 106 |
105 bool CoreServicesApplicationDelegate::AcceptConnection( | 107 bool CoreServicesApplicationDelegate::AcceptConnection( |
106 mojo::ApplicationConnection* connection) { | 108 mojo::ApplicationConnection* connection) { |
107 connection->AddService(this); | 109 connection->AddService(this); |
108 return true; | 110 return true; |
109 } | 111 } |
110 | 112 |
111 void CoreServicesApplicationDelegate::Quit() { | 113 void CoreServicesApplicationDelegate::Quit() { |
112 // 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 |
113 // for the threads to end. | 115 // for the threads to end. |
114 application_threads_.clear(); | 116 application_threads_.clear(); |
115 weak_factory_.InvalidateWeakPtrs(); | 117 weak_factory_.InvalidateWeakPtrs(); |
116 } | 118 } |
117 | 119 |
118 void CoreServicesApplicationDelegate::Create( | 120 void CoreServicesApplicationDelegate::Create( |
119 mojo::ApplicationConnection* connection, | 121 mojo::ApplicationConnection* connection, |
120 mojo::InterfaceRequest<mojo::shell::mojom::ContentHandler> request) { | 122 mojo::InterfaceRequest<mojo::shell::mojom::ContentHandler> request) { |
121 handler_bindings_.AddBinding(this, std::move(request)); | 123 handler_bindings_.AddBinding(this, std::move(request)); |
122 } | 124 } |
123 | 125 |
124 void CoreServicesApplicationDelegate::StartApplication( | 126 void CoreServicesApplicationDelegate::StartApplication( |
125 mojo::ApplicationRequest request, | 127 mojo::InterfaceRequest<mojo::shell::mojom::Application> request, |
126 mojo::URLResponsePtr response, | 128 mojo::URLResponsePtr response, |
127 const mojo::Callback<void()>& destruct_callback) { | 129 const mojo::Callback<void()>& destruct_callback) { |
128 const std::string url = response->url; | 130 const std::string url = response->url; |
129 | 131 |
130 scoped_ptr<mojo::ApplicationDelegate> delegate; | 132 scoped_ptr<mojo::ApplicationDelegate> delegate; |
131 if (url == "mojo://clipboard/") { | 133 if (url == "mojo://clipboard/") { |
132 delegate.reset(new clipboard::ClipboardApplicationDelegate); | 134 delegate.reset(new clipboard::ClipboardApplicationDelegate); |
133 } else if (url == "mojo://filesystem/") { | 135 } else if (url == "mojo://filesystem/") { |
134 delegate.reset(new filesystem::FileSystemApp); | 136 delegate.reset(new filesystem::FileSystemApp); |
135 } else if (url == "mojo://tracing/") { | 137 } else if (url == "mojo://tracing/") { |
(...skipping 13 matching lines...) Expand all Loading... |
149 } | 151 } |
150 | 152 |
151 scoped_ptr<ApplicationThread> thread(new ApplicationThread( | 153 scoped_ptr<ApplicationThread> thread(new ApplicationThread( |
152 weak_factory_.GetWeakPtr(), url, std::move(delegate), std::move(request), | 154 weak_factory_.GetWeakPtr(), url, std::move(delegate), std::move(request), |
153 destruct_callback)); | 155 destruct_callback)); |
154 thread->Start(); | 156 thread->Start(); |
155 application_threads_.push_back(std::move(thread)); | 157 application_threads_.push_back(std::move(thread)); |
156 } | 158 } |
157 | 159 |
158 } // namespace core_services | 160 } // namespace core_services |
OLD | NEW |