OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "mojo/shell/standalone/context.h" | 5 #include "mojo/shell/standalone/context.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <utility> | 10 #include <utility> |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
82 const size_t kMaxBlockingPoolThreads = 3; | 82 const size_t kMaxBlockingPoolThreads = 3; |
83 | 83 |
84 scoped_ptr<base::Thread> CreateIOThread(const char* name) { | 84 scoped_ptr<base::Thread> CreateIOThread(const char* name) { |
85 scoped_ptr<base::Thread> thread(new base::Thread(name)); | 85 scoped_ptr<base::Thread> thread(new base::Thread(name)); |
86 base::Thread::Options options; | 86 base::Thread::Options options; |
87 options.message_loop_type = base::MessageLoop::TYPE_IO; | 87 options.message_loop_type = base::MessageLoop::TYPE_IO; |
88 thread->StartWithOptions(options); | 88 thread->StartWithOptions(options); |
89 return thread; | 89 return thread; |
90 } | 90 } |
91 | 91 |
92 void OnInstanceQuit(const GURL& url, const Identity& identity) { | |
93 if (url == identity.url()) | |
94 base::MessageLoop::current()->QuitWhenIdle(); | |
sky
2016/02/19 05:20:51
Ick, quitting arbitrary messageloop is error prone
| |
95 } | |
96 | |
92 } // namespace | 97 } // namespace |
93 | 98 |
94 Context::Context() | 99 Context::Context() |
95 : main_entry_time_(base::Time::Now()), | 100 : main_entry_time_(base::Time::Now()), |
96 io_thread_(CreateIOThread("io_thread")) {} | 101 io_thread_(CreateIOThread("io_thread")) {} |
97 | 102 |
98 Context::~Context() { | 103 Context::~Context() { |
99 DCHECK(!base::MessageLoop::current()); | 104 DCHECK(!base::MessageLoop::current()); |
100 blocking_pool_->Shutdown(); | 105 blocking_pool_->Shutdown(); |
101 } | 106 } |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
135 << "supported because statics in apps interact. Use static build" | 140 << "supported because statics in apps interact. Use static build" |
136 << " or don't pass --single-process."; | 141 << " or don't pass --single-process."; |
137 #endif | 142 #endif |
138 runner_factory.reset( | 143 runner_factory.reset( |
139 new InProcessNativeRunnerFactory(blocking_pool_.get())); | 144 new InProcessNativeRunnerFactory(blocking_pool_.get())); |
140 } else { | 145 } else { |
141 runner_factory.reset( | 146 runner_factory.reset( |
142 new OutOfProcessNativeRunnerFactory(blocking_pool_.get())); | 147 new OutOfProcessNativeRunnerFactory(blocking_pool_.get())); |
143 } | 148 } |
144 application_manager_.reset(new ApplicationManager( | 149 application_manager_.reset(new ApplicationManager( |
145 std::move(runner_factory), blocking_pool_.get(), true)); | 150 std::move(runner_factory), blocking_pool_.get(), true)); |
146 | 151 |
147 shell::mojom::InterfaceProviderPtr tracing_remote_interfaces; | 152 shell::mojom::InterfaceProviderPtr tracing_remote_interfaces; |
148 shell::mojom::InterfaceProviderPtr tracing_local_interfaces; | 153 shell::mojom::InterfaceProviderPtr tracing_local_interfaces; |
149 new TracingInterfaceProvider(&tracer_, GetProxy(&tracing_local_interfaces)); | 154 new TracingInterfaceProvider(&tracer_, GetProxy(&tracing_local_interfaces)); |
150 | 155 |
151 scoped_ptr<ConnectParams> params(new ConnectParams); | 156 scoped_ptr<ConnectParams> params(new ConnectParams); |
152 params->set_source(Identity(GURL("mojo:shell"), std::string(), | 157 params->set_source(Identity(GURL("mojo:shell"), std::string(), |
153 GetPermissiveCapabilityFilter())); | 158 GetPermissiveCapabilityFilter())); |
154 params->set_target(Identity(GURL("mojo:tracing"), std::string(), | 159 params->set_target(Identity(GURL("mojo:tracing"), std::string(), |
155 GetPermissiveCapabilityFilter())); | 160 GetPermissiveCapabilityFilter())); |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
194 base::Bind(edk::ShutdownIPCSupport)); | 199 base::Bind(edk::ShutdownIPCSupport)); |
195 // We'll quit when we get OnShutdownComplete(). | 200 // We'll quit when we get OnShutdownComplete(). |
196 base::MessageLoop::current()->Run(); | 201 base::MessageLoop::current()->Run(); |
197 } | 202 } |
198 | 203 |
199 void Context::OnShutdownComplete() { | 204 void Context::OnShutdownComplete() { |
200 DCHECK_EQ(base::MessageLoop::current()->task_runner(), shell_runner_); | 205 DCHECK_EQ(base::MessageLoop::current()->task_runner(), shell_runner_); |
201 base::MessageLoop::current()->QuitWhenIdle(); | 206 base::MessageLoop::current()->QuitWhenIdle(); |
202 } | 207 } |
203 | 208 |
209 void Context::RunCommandLineApplication() { | |
210 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); | |
211 base::CommandLine::StringVector args = command_line->GetArgs(); | |
212 for (size_t i = 0; i < args.size(); ++i) { | |
213 GURL possible_app(args[i]); | |
214 if (possible_app.SchemeIs("mojo")) { | |
215 Run(possible_app); | |
216 break; | |
217 } | |
218 } | |
219 } | |
220 | |
204 void Context::Run(const GURL& url) { | 221 void Context::Run(const GURL& url) { |
205 DCHECK(app_complete_callback_.is_null()); | 222 application_manager_->SetInstanceQuitCallback( |
sky
2016/02/19 05:20:51
If Run() is called multiple-times doesn't the new
| |
223 base::Bind(&OnInstanceQuit, url)); | |
224 | |
206 shell::mojom::InterfaceProviderPtr remote_interfaces; | 225 shell::mojom::InterfaceProviderPtr remote_interfaces; |
207 shell::mojom::InterfaceProviderPtr local_interfaces; | 226 shell::mojom::InterfaceProviderPtr local_interfaces; |
208 | 227 |
209 app_urls_.insert(url); | |
210 | |
211 scoped_ptr<ConnectParams> params(new ConnectParams); | 228 scoped_ptr<ConnectParams> params(new ConnectParams); |
212 params->set_target( | 229 params->set_target( |
213 Identity(url, std::string(), GetPermissiveCapabilityFilter())); | 230 Identity(url, std::string(), GetPermissiveCapabilityFilter())); |
214 params->set_remote_interfaces(GetProxy(&remote_interfaces)); | 231 params->set_remote_interfaces(GetProxy(&remote_interfaces)); |
215 params->set_local_interfaces(std::move(local_interfaces)); | 232 params->set_local_interfaces(std::move(local_interfaces)); |
216 params->set_on_application_end( | |
217 base::Bind(&Context::OnApplicationEnd, base::Unretained(this), url)); | |
218 application_manager_->Connect(std::move(params)); | 233 application_manager_->Connect(std::move(params)); |
219 } | 234 } |
220 | 235 |
221 void Context::RunCommandLineApplication(const base::Closure& callback) { | |
222 DCHECK(app_urls_.empty()); | |
223 DCHECK(app_complete_callback_.is_null()); | |
224 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); | |
225 base::CommandLine::StringVector args = command_line->GetArgs(); | |
226 for (size_t i = 0; i < args.size(); ++i) { | |
227 GURL possible_app(args[i]); | |
228 if (possible_app.SchemeIs("mojo")) { | |
229 Run(possible_app); | |
230 app_complete_callback_ = callback; | |
231 break; | |
232 } | |
233 } | |
234 } | |
235 | |
236 void Context::OnApplicationEnd(const GURL& url) { | |
237 if (app_urls_.find(url) != app_urls_.end()) { | |
238 app_urls_.erase(url); | |
239 if (app_urls_.empty() && base::MessageLoop::current()->is_running()) { | |
240 DCHECK_EQ(base::MessageLoop::current()->task_runner(), shell_runner_); | |
241 if (app_complete_callback_.is_null()) { | |
242 base::MessageLoop::current()->QuitWhenIdle(); | |
243 } else { | |
244 app_complete_callback_.Run(); | |
245 } | |
246 } | |
247 } | |
248 } | |
249 | |
250 } // namespace shell | 236 } // namespace shell |
251 } // namespace mojo | 237 } // namespace mojo |
OLD | NEW |