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 "shell/context.h" | 5 #include "shell/context.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/base_switches.h" | 9 #include "base/base_switches.h" |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
282 base::CommandLine::ForCurrentProcess()->HasSwitch( | 282 base::CommandLine::ForCurrentProcess()->HasSwitch( |
283 switches::kDisableCache)); | 283 switches::kDisableCache)); |
284 | 284 |
285 InitContentHandlers(&application_manager_, command_line); | 285 InitContentHandlers(&application_manager_, command_line); |
286 InitNativeOptions(&application_manager_, command_line); | 286 InitNativeOptions(&application_manager_, command_line); |
287 | 287 |
288 ServiceProviderPtr tracing_service_provider_ptr; | 288 ServiceProviderPtr tracing_service_provider_ptr; |
289 new TracingServiceProvider(GetProxy(&tracing_service_provider_ptr)); | 289 new TracingServiceProvider(GetProxy(&tracing_service_provider_ptr)); |
290 application_manager_.ConnectToApplication( | 290 application_manager_.ConnectToApplication( |
291 GURL("mojo:tracing"), GURL(""), nullptr, | 291 GURL("mojo:tracing"), GURL(""), nullptr, |
292 tracing_service_provider_ptr.Pass()); | 292 tracing_service_provider_ptr.Pass(), base::Closure()); |
293 | 293 |
294 if (listener_) | 294 if (listener_) |
295 listener_->WaitForListening(); | 295 listener_->WaitForListening(); |
296 | 296 |
297 return true; | 297 return true; |
298 } | 298 } |
299 | 299 |
300 void Context::Shutdown() { | 300 void Context::Shutdown() { |
301 DCHECK_EQ(base::MessageLoop::current()->task_runner(), | 301 DCHECK_EQ(base::MessageLoop::current()->task_runner(), |
302 task_runners_->shell_runner()); | 302 task_runners_->shell_runner()); |
303 embedder::ShutdownIPCSupport(); | 303 embedder::ShutdownIPCSupport(); |
304 // We'll quit when we get OnShutdownComplete(). | 304 // We'll quit when we get OnShutdownComplete(). |
305 base::MessageLoop::current()->Run(); | 305 base::MessageLoop::current()->Run(); |
306 } | 306 } |
307 | 307 |
308 void Context::OnApplicationError(const GURL& url) { | |
309 if (app_urls_.find(url) != app_urls_.end()) { | |
310 app_urls_.erase(url); | |
311 if (app_urls_.empty() && base::MessageLoop::current()->is_running()) { | |
312 DCHECK_EQ(base::MessageLoop::current()->task_runner(), | |
313 task_runners_->shell_runner()); | |
314 base::MessageLoop::current()->Quit(); | |
315 } | |
316 } | |
317 } | |
318 | |
319 GURL Context::ResolveURL(const GURL& url) { | 308 GURL Context::ResolveURL(const GURL& url) { |
320 return url_resolver_.ResolveMojoURL(url); | 309 return url_resolver_.ResolveMojoURL(url); |
321 } | 310 } |
322 | 311 |
323 GURL Context::ResolveMappings(const GURL& url) { | 312 GURL Context::ResolveMappings(const GURL& url) { |
324 return url_resolver_.ApplyMappings(url); | 313 return url_resolver_.ApplyMappings(url); |
325 } | 314 } |
326 | 315 |
327 void Context::OnShutdownComplete() { | 316 void Context::OnShutdownComplete() { |
328 DCHECK_EQ(base::MessageLoop::current()->task_runner(), | 317 DCHECK_EQ(base::MessageLoop::current()->task_runner(), |
329 task_runners_->shell_runner()); | 318 task_runners_->shell_runner()); |
330 base::MessageLoop::current()->Quit(); | 319 base::MessageLoop::current()->Quit(); |
331 } | 320 } |
332 | 321 |
333 void Context::Run(const GURL& url) { | 322 void Context::Run(const GURL& url) { |
334 ServiceProviderPtr services; | 323 ServiceProviderPtr services; |
335 ServiceProviderPtr exposed_services; | 324 ServiceProviderPtr exposed_services; |
336 | 325 |
337 app_urls_.insert(url); | 326 app_urls_.insert(url); |
338 application_manager_.ConnectToApplication(url, GURL(), GetProxy(&services), | 327 application_manager_.ConnectToApplication( |
339 exposed_services.Pass()); | 328 url, GURL(), GetProxy(&services), exposed_services.Pass(), |
| 329 base::Bind(&Context::OnApplicationEnd, base::Unretained(this), url)); |
340 } | 330 } |
341 | 331 |
342 ScopedMessagePipeHandle Context::ConnectToServiceByName( | 332 ScopedMessagePipeHandle Context::ConnectToServiceByName( |
343 const GURL& application_url, | 333 const GURL& application_url, |
344 const std::string& service_name) { | 334 const std::string& service_name) { |
345 app_urls_.insert(application_url); | |
346 return application_manager_.ConnectToServiceByName(application_url, | 335 return application_manager_.ConnectToServiceByName(application_url, |
347 service_name).Pass(); | 336 service_name).Pass(); |
348 } | 337 } |
349 | 338 |
| 339 void Context::OnApplicationEnd(const GURL& url) { |
| 340 if (app_urls_.find(url) != app_urls_.end()) { |
| 341 app_urls_.erase(url); |
| 342 if (app_urls_.empty() && base::MessageLoop::current()->is_running()) { |
| 343 DCHECK_EQ(base::MessageLoop::current()->task_runner(), |
| 344 task_runners_->shell_runner()); |
| 345 base::MessageLoop::current()->Quit(); |
| 346 } |
| 347 } |
| 348 } |
| 349 |
350 } // namespace shell | 350 } // namespace shell |
351 } // namespace mojo | 351 } // namespace mojo |
OLD | NEW |