| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "content/public/app/content_main_runner.h" | 5 #include "content/public/app/content_main_runner.h" |
| 6 | 6 |
| 7 #include "base/at_exit.h" | 7 #include "base/at_exit.h" |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/debug/debugger.h" | 9 #include "base/debug/debugger.h" |
| 10 #include "base/debug/trace_event.h" | 10 #include "base/debug/trace_event.h" |
| (...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 284 return delegate->RunProcess(process_type, main_function_params); | 284 return delegate->RunProcess(process_type, main_function_params); |
| 285 | 285 |
| 286 NOTREACHED() << "Unknown process type: " << process_type; | 286 NOTREACHED() << "Unknown process type: " << process_type; |
| 287 return 1; | 287 return 1; |
| 288 } | 288 } |
| 289 | 289 |
| 290 class ContentMainRunnerImpl : public content::ContentMainRunner { | 290 class ContentMainRunnerImpl : public content::ContentMainRunner { |
| 291 public: | 291 public: |
| 292 ContentMainRunnerImpl() | 292 ContentMainRunnerImpl() |
| 293 : is_initialized_(false), | 293 : is_initialized_(false), |
| 294 is_shutdown_(false) { | 294 is_shutdown_(false), |
| 295 completed_basic_startup_(false) { |
| 295 } | 296 } |
| 296 | 297 |
| 297 ~ContentMainRunnerImpl() { | 298 ~ContentMainRunnerImpl() { |
| 298 if (is_initialized_ && !is_shutdown_) | 299 if (is_initialized_ && !is_shutdown_) |
| 299 Shutdown(); | 300 Shutdown(); |
| 300 } | 301 } |
| 301 | 302 |
| 302 #if defined(OS_WIN) | 303 #if defined(OS_WIN) |
| 303 virtual int Initialize(HINSTANCE instance, | 304 virtual int Initialize(HINSTANCE instance, |
| 304 sandbox::SandboxInterfaceInfo* sandbox_info, | 305 sandbox::SandboxInterfaceInfo* sandbox_info, |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 364 // its main event loop to get rid of the cruft. | 365 // its main event loop to get rid of the cruft. |
| 365 autorelease_pool_.reset(new base::mac::ScopedNSAutoreleasePool()); | 366 autorelease_pool_.reset(new base::mac::ScopedNSAutoreleasePool()); |
| 366 #endif | 367 #endif |
| 367 | 368 |
| 368 CommandLine::Init(argc, argv); | 369 CommandLine::Init(argc, argv); |
| 369 | 370 |
| 370 int exit_code; | 371 int exit_code; |
| 371 if (delegate && delegate->BasicStartupComplete(&exit_code)) | 372 if (delegate && delegate->BasicStartupComplete(&exit_code)) |
| 372 return exit_code; | 373 return exit_code; |
| 373 | 374 |
| 375 completed_basic_startup_ = true; |
| 376 |
| 374 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); | 377 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
| 375 std::string process_type = | 378 std::string process_type = |
| 376 command_line.GetSwitchValueASCII(switches::kProcessType); | 379 command_line.GetSwitchValueASCII(switches::kProcessType); |
| 377 | 380 |
| 378 // Enable startup tracing asap to avoid early TRACE_EVENT calls being | 381 // Enable startup tracing asap to avoid early TRACE_EVENT calls being |
| 379 // ignored. | 382 // ignored. |
| 380 if (command_line.HasSwitch(switches::kTraceStartup)) { | 383 if (command_line.HasSwitch(switches::kTraceStartup)) { |
| 381 base::debug::TraceLog::GetInstance()->SetEnabled( | 384 base::debug::TraceLog::GetInstance()->SetEnabled( |
| 382 command_line.GetSwitchValueASCII(switches::kTraceStartup)); | 385 command_line.GetSwitchValueASCII(switches::kTraceStartup)); |
| 383 } | 386 } |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 493 #elif defined(OS_MACOSX) | 496 #elif defined(OS_MACOSX) |
| 494 main_params.autorelease_pool = autorelease_pool_.get(); | 497 main_params.autorelease_pool = autorelease_pool_.get(); |
| 495 #endif | 498 #endif |
| 496 | 499 |
| 497 return RunNamedProcessTypeMain(process_type, main_params, delegate_); | 500 return RunNamedProcessTypeMain(process_type, main_params, delegate_); |
| 498 } | 501 } |
| 499 | 502 |
| 500 virtual void Shutdown() OVERRIDE { | 503 virtual void Shutdown() OVERRIDE { |
| 501 DCHECK(is_initialized_); | 504 DCHECK(is_initialized_); |
| 502 DCHECK(!is_shutdown_); | 505 DCHECK(!is_shutdown_); |
| 503 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); | 506 |
| 504 std::string process_type = | 507 if (completed_basic_startup_ && delegate_) { |
| 508 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
| 509 std::string process_type = |
| 505 command_line.GetSwitchValueASCII(switches::kProcessType); | 510 command_line.GetSwitchValueASCII(switches::kProcessType); |
| 506 | 511 |
| 507 if (delegate_) | |
| 508 delegate_->ProcessExiting(process_type); | 512 delegate_->ProcessExiting(process_type); |
| 513 } |
| 509 | 514 |
| 510 #if defined(OS_WIN) | 515 #if defined(OS_WIN) |
| 511 #ifdef _CRTDBG_MAP_ALLOC | 516 #ifdef _CRTDBG_MAP_ALLOC |
| 512 _CrtDumpMemoryLeaks(); | 517 _CrtDumpMemoryLeaks(); |
| 513 #endif // _CRTDBG_MAP_ALLOC | 518 #endif // _CRTDBG_MAP_ALLOC |
| 514 | 519 |
| 515 _Module.Term(); | 520 _Module.Term(); |
| 516 #endif // OS_WIN | 521 #endif // OS_WIN |
| 517 | 522 |
| 518 #if defined(OS_MACOSX) | 523 #if defined(OS_MACOSX) |
| 519 autorelease_pool_.reset(NULL); | 524 autorelease_pool_.reset(NULL); |
| 520 #endif | 525 #endif |
| 521 | 526 |
| 522 exit_manager_.reset(NULL); | 527 exit_manager_.reset(NULL); |
| 523 | 528 |
| 524 delegate_ = NULL; | 529 delegate_ = NULL; |
| 525 is_shutdown_ = true; | 530 is_shutdown_ = true; |
| 526 } | 531 } |
| 527 | 532 |
| 528 protected: | 533 protected: |
| 529 // True if the runner has been initialized. | 534 // True if the runner has been initialized. |
| 530 bool is_initialized_; | 535 bool is_initialized_; |
| 531 | 536 |
| 532 // True if the runner has been shut down. | 537 // True if the runner has been shut down. |
| 533 bool is_shutdown_; | 538 bool is_shutdown_; |
| 534 | 539 |
| 540 // True if basic startup was completed. |
| 541 bool completed_basic_startup_; |
| 542 |
| 535 // The delegate will outlive this object. | 543 // The delegate will outlive this object. |
| 536 content::ContentMainDelegate* delegate_; | 544 content::ContentMainDelegate* delegate_; |
| 537 | 545 |
| 538 scoped_ptr<base::AtExitManager> exit_manager_; | 546 scoped_ptr<base::AtExitManager> exit_manager_; |
| 539 #if defined(OS_WIN) | 547 #if defined(OS_WIN) |
| 540 sandbox::SandboxInterfaceInfo sandbox_info_; | 548 sandbox::SandboxInterfaceInfo sandbox_info_; |
| 541 #elif defined(OS_MACOSX) | 549 #elif defined(OS_MACOSX) |
| 542 scoped_ptr<base::mac::ScopedNSAutoreleasePool> autorelease_pool_; | 550 scoped_ptr<base::mac::ScopedNSAutoreleasePool> autorelease_pool_; |
| 543 #endif | 551 #endif |
| 544 | 552 |
| 545 DISALLOW_COPY_AND_ASSIGN(ContentMainRunnerImpl); | 553 DISALLOW_COPY_AND_ASSIGN(ContentMainRunnerImpl); |
| 546 }; | 554 }; |
| 547 | 555 |
| 548 } // namespace | 556 } // namespace |
| 549 | 557 |
| 550 namespace content { | 558 namespace content { |
| 551 | 559 |
| 552 // static | 560 // static |
| 553 ContentMainRunner* ContentMainRunner::Create() { | 561 ContentMainRunner* ContentMainRunner::Create() { |
| 554 return new ContentMainRunnerImpl(); | 562 return new ContentMainRunnerImpl(); |
| 555 } | 563 } |
| 556 | 564 |
| 557 } // namespace content | 565 } // namespace content |
| OLD | NEW |