Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(69)

Side by Side Diff: shell/context.cc

Issue 983113002: ApplicationManager: Use callback to get notified on application shutdown. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 274 matching lines...) Expand 10 before | Expand all | Expand 10 after
285 base::CommandLine::ForCurrentProcess()->HasSwitch( 285 base::CommandLine::ForCurrentProcess()->HasSwitch(
286 switches::kDisableCache)); 286 switches::kDisableCache));
287 287
288 InitContentHandlers(&application_manager_, command_line); 288 InitContentHandlers(&application_manager_, command_line);
289 InitNativeOptions(&application_manager_, command_line); 289 InitNativeOptions(&application_manager_, command_line);
290 290
291 ServiceProviderPtr tracing_service_provider_ptr; 291 ServiceProviderPtr tracing_service_provider_ptr;
292 new TracingServiceProvider(GetProxy(&tracing_service_provider_ptr)); 292 new TracingServiceProvider(GetProxy(&tracing_service_provider_ptr));
293 application_manager_.ConnectToApplication( 293 application_manager_.ConnectToApplication(
294 GURL("mojo:tracing"), GURL(""), nullptr, 294 GURL("mojo:tracing"), GURL(""), nullptr,
295 tracing_service_provider_ptr.Pass()); 295 tracing_service_provider_ptr.Pass(), base::Closure());
296 296
297 if (listener_) 297 if (listener_)
298 listener_->WaitForListening(); 298 listener_->WaitForListening();
299 299
300 return true; 300 return true;
301 } 301 }
302 302
303 void Context::Shutdown() { 303 void Context::Shutdown() {
304 DCHECK_EQ(base::MessageLoop::current()->task_runner(), 304 DCHECK_EQ(base::MessageLoop::current()->task_runner(),
305 task_runners_->shell_runner()); 305 task_runners_->shell_runner());
306 embedder::ShutdownIPCSupport(); 306 embedder::ShutdownIPCSupport();
307 // We'll quit when we get OnShutdownComplete(). 307 // We'll quit when we get OnShutdownComplete().
308 base::MessageLoop::current()->Run(); 308 base::MessageLoop::current()->Run();
309 } 309 }
310 310
311 void Context::OnApplicationError(const GURL& url) {
312 if (app_urls_.find(url) != app_urls_.end()) {
313 app_urls_.erase(url);
314 if (app_urls_.empty() && base::MessageLoop::current()->is_running()) {
315 DCHECK_EQ(base::MessageLoop::current()->task_runner(),
316 task_runners_->shell_runner());
317 base::MessageLoop::current()->Quit();
318 }
319 }
320 }
321
322 GURL Context::ResolveURL(const GURL& url) { 311 GURL Context::ResolveURL(const GURL& url) {
323 return url_resolver_.ResolveMojoURL(url); 312 return url_resolver_.ResolveMojoURL(url);
324 } 313 }
325 314
326 GURL Context::ResolveMappings(const GURL& url) { 315 GURL Context::ResolveMappings(const GURL& url) {
327 return url_resolver_.ApplyMappings(url); 316 return url_resolver_.ApplyMappings(url);
328 } 317 }
329 318
330 void Context::OnShutdownComplete() { 319 void Context::OnShutdownComplete() {
331 DCHECK_EQ(base::MessageLoop::current()->task_runner(), 320 DCHECK_EQ(base::MessageLoop::current()->task_runner(),
332 task_runners_->shell_runner()); 321 task_runners_->shell_runner());
333 base::MessageLoop::current()->Quit(); 322 base::MessageLoop::current()->Quit();
334 } 323 }
335 324
336 void Context::Run(const GURL& url) { 325 void Context::Run(const GURL& url) {
337 ServiceProviderPtr services; 326 ServiceProviderPtr services;
338 ServiceProviderPtr exposed_services; 327 ServiceProviderPtr exposed_services;
339 328
340 app_urls_.insert(url); 329 app_urls_.insert(url);
341 application_manager_.ConnectToApplication(url, GURL(), GetProxy(&services), 330 application_manager_.ConnectToApplication(
342 exposed_services.Pass()); 331 url, GURL(), GetProxy(&services), exposed_services.Pass(),
332 base::Bind(&Context::OnApplicationEnd, base::Unretained(this), url));
343 } 333 }
344 334
345 ScopedMessagePipeHandle Context::ConnectToServiceByName( 335 ScopedMessagePipeHandle Context::ConnectToServiceByName(
346 const GURL& application_url, 336 const GURL& application_url,
347 const std::string& service_name) { 337 const std::string& service_name) {
348 app_urls_.insert(application_url);
349 return application_manager_.ConnectToServiceByName(application_url, 338 return application_manager_.ConnectToServiceByName(application_url,
350 service_name).Pass(); 339 service_name).Pass();
351 } 340 }
352 341
342 void Context::OnApplicationEnd(const GURL& url) {
343 if (app_urls_.find(url) != app_urls_.end()) {
344 app_urls_.erase(url);
345 if (app_urls_.empty() && base::MessageLoop::current()->is_running()) {
346 DCHECK_EQ(base::MessageLoop::current()->task_runner(),
347 task_runners_->shell_runner());
348 base::MessageLoop::current()->Quit();
349 }
350 }
351 }
352
353 } // namespace shell 353 } // namespace shell
354 } // namespace mojo 354 } // namespace mojo
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698