| 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 <stdlib.h> | 7 #include <stdlib.h> |
| 8 | 8 |
| 9 #include "base/allocator/allocator_extension.h" | 9 #include "base/allocator/allocator_extension.h" |
| 10 #include "base/at_exit.h" | 10 #include "base/at_exit.h" |
| (...skipping 471 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 482 return 1; | 482 return 1; |
| 483 } | 483 } |
| 484 #endif // !OS_IOS | 484 #endif // !OS_IOS |
| 485 | 485 |
| 486 class ContentMainRunnerImpl : public ContentMainRunner { | 486 class ContentMainRunnerImpl : public ContentMainRunner { |
| 487 public: | 487 public: |
| 488 ContentMainRunnerImpl() | 488 ContentMainRunnerImpl() |
| 489 : is_initialized_(false), | 489 : is_initialized_(false), |
| 490 is_shutdown_(false), | 490 is_shutdown_(false), |
| 491 completed_basic_startup_(false), | 491 completed_basic_startup_(false), |
| 492 delegate_(NULL) { | 492 delegate_(NULL), |
| 493 ui_task_(NULL) { |
| 493 #if defined(OS_WIN) | 494 #if defined(OS_WIN) |
| 494 memset(&sandbox_info_, 0, sizeof(sandbox_info_)); | 495 memset(&sandbox_info_, 0, sizeof(sandbox_info_)); |
| 495 #endif | 496 #endif |
| 496 } | 497 } |
| 497 | 498 |
| 498 virtual ~ContentMainRunnerImpl() { | 499 virtual ~ContentMainRunnerImpl() { |
| 499 if (is_initialized_ && !is_shutdown_) | 500 if (is_initialized_ && !is_shutdown_) |
| 500 Shutdown(); | 501 Shutdown(); |
| 501 } | 502 } |
| 502 | 503 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 519 static void GetStatsThunk(char* buffer, int buffer_length) { | 520 static void GetStatsThunk(char* buffer, int buffer_length) { |
| 520 MallocExtension::instance()->GetStats(buffer, buffer_length); | 521 MallocExtension::instance()->GetStats(buffer, buffer_length); |
| 521 } | 522 } |
| 522 | 523 |
| 523 static void ReleaseFreeMemoryThunk() { | 524 static void ReleaseFreeMemoryThunk() { |
| 524 MallocExtension::instance()->ReleaseFreeMemory(); | 525 MallocExtension::instance()->ReleaseFreeMemory(); |
| 525 } | 526 } |
| 526 #endif | 527 #endif |
| 527 | 528 |
| 528 virtual int Initialize(const ContentMainParams& params) OVERRIDE { | 529 virtual int Initialize(const ContentMainParams& params) OVERRIDE { |
| 530 ui_task_ = params.ui_task; |
| 531 |
| 529 #if defined(OS_WIN) | 532 #if defined(OS_WIN) |
| 530 RegisterInvalidParamHandler(); | 533 RegisterInvalidParamHandler(); |
| 531 _Module.Init(NULL, static_cast<HINSTANCE>(params.instance)); | 534 _Module.Init(NULL, static_cast<HINSTANCE>(params.instance)); |
| 532 | 535 |
| 533 sandbox_info_ = *params.sandbox_info; | 536 sandbox_info_ = *params.sandbox_info; |
| 534 #else // !OS_WIN | 537 #else // !OS_WIN |
| 535 | 538 |
| 536 #if defined(OS_ANDROID) | 539 #if defined(OS_ANDROID) |
| 537 // See note at the initialization of ExitManager, below; basically, | 540 // See note at the initialization of ExitManager, below; basically, |
| 538 // only Android builds have the ctor/dtor handlers set up to use | 541 // only Android builds have the ctor/dtor handlers set up to use |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 605 | 608 |
| 606 base::EnableTerminationOnHeapCorruption(); | 609 base::EnableTerminationOnHeapCorruption(); |
| 607 base::EnableTerminationOnOutOfMemory(); | 610 base::EnableTerminationOnOutOfMemory(); |
| 608 | 611 |
| 609 // The exit manager is in charge of calling the dtors of singleton objects. | 612 // The exit manager is in charge of calling the dtors of singleton objects. |
| 610 // On Android, AtExitManager is set up when library is loaded. | 613 // On Android, AtExitManager is set up when library is loaded. |
| 611 // On iOS, it's set up in main(), which can't call directly through to here. | 614 // On iOS, it's set up in main(), which can't call directly through to here. |
| 612 // A consequence of this is that you can't use the ctor/dtor-based | 615 // A consequence of this is that you can't use the ctor/dtor-based |
| 613 // TRACE_EVENT methods on Linux or iOS builds till after we set this up. | 616 // TRACE_EVENT methods on Linux or iOS builds till after we set this up. |
| 614 #if !defined(OS_ANDROID) && !defined(OS_IOS) | 617 #if !defined(OS_ANDROID) && !defined(OS_IOS) |
| 615 exit_manager_.reset(new base::AtExitManager); | 618 if (!ui_task_) { |
| 619 // When running browser tests, don't create a second AtExitManager as that |
| 620 // interfers with shutdown when objects created before ContentMain is |
| 621 // called are destructed when it returns. |
| 622 exit_manager_.reset(new base::AtExitManager); |
| 623 } |
| 616 #endif // !OS_ANDROID && !OS_IOS | 624 #endif // !OS_ANDROID && !OS_IOS |
| 617 | 625 |
| 618 #if defined(OS_MACOSX) | 626 #if defined(OS_MACOSX) |
| 619 // We need this pool for all the objects created before we get to the | 627 // We need this pool for all the objects created before we get to the |
| 620 // event loop, but we don't want to leave them hanging around until the | 628 // event loop, but we don't want to leave them hanging around until the |
| 621 // app quits. Each "main" needs to flush this pool right before it goes into | 629 // app quits. Each "main" needs to flush this pool right before it goes into |
| 622 // its main event loop to get rid of the cruft. | 630 // its main event loop to get rid of the cruft. |
| 623 autorelease_pool_.reset(new base::mac::ScopedNSAutoreleasePool()); | 631 autorelease_pool_.reset(new base::mac::ScopedNSAutoreleasePool()); |
| 624 #endif | 632 #endif |
| 625 | 633 |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 762 } | 770 } |
| 763 | 771 |
| 764 virtual int Run() OVERRIDE { | 772 virtual int Run() OVERRIDE { |
| 765 DCHECK(is_initialized_); | 773 DCHECK(is_initialized_); |
| 766 DCHECK(!is_shutdown_); | 774 DCHECK(!is_shutdown_); |
| 767 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); | 775 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
| 768 std::string process_type = | 776 std::string process_type = |
| 769 command_line.GetSwitchValueASCII(switches::kProcessType); | 777 command_line.GetSwitchValueASCII(switches::kProcessType); |
| 770 | 778 |
| 771 MainFunctionParams main_params(command_line); | 779 MainFunctionParams main_params(command_line); |
| 780 main_params.ui_task = ui_task_; |
| 772 #if defined(OS_WIN) | 781 #if defined(OS_WIN) |
| 773 main_params.sandbox_info = &sandbox_info_; | 782 main_params.sandbox_info = &sandbox_info_; |
| 774 #elif defined(OS_MACOSX) | 783 #elif defined(OS_MACOSX) |
| 775 main_params.autorelease_pool = autorelease_pool_.get(); | 784 main_params.autorelease_pool = autorelease_pool_.get(); |
| 776 #endif | 785 #endif |
| 777 | 786 |
| 778 #if !defined(OS_IOS) | 787 #if !defined(OS_IOS) |
| 779 return RunNamedProcessTypeMain(process_type, main_params, delegate_); | 788 return RunNamedProcessTypeMain(process_type, main_params, delegate_); |
| 780 #else | 789 #else |
| 781 return 1; | 790 return 1; |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 828 // The delegate will outlive this object. | 837 // The delegate will outlive this object. |
| 829 ContentMainDelegate* delegate_; | 838 ContentMainDelegate* delegate_; |
| 830 | 839 |
| 831 scoped_ptr<base::AtExitManager> exit_manager_; | 840 scoped_ptr<base::AtExitManager> exit_manager_; |
| 832 #if defined(OS_WIN) | 841 #if defined(OS_WIN) |
| 833 sandbox::SandboxInterfaceInfo sandbox_info_; | 842 sandbox::SandboxInterfaceInfo sandbox_info_; |
| 834 #elif defined(OS_MACOSX) | 843 #elif defined(OS_MACOSX) |
| 835 scoped_ptr<base::mac::ScopedNSAutoreleasePool> autorelease_pool_; | 844 scoped_ptr<base::mac::ScopedNSAutoreleasePool> autorelease_pool_; |
| 836 #endif | 845 #endif |
| 837 | 846 |
| 847 base::Closure* ui_task_; |
| 848 |
| 838 DISALLOW_COPY_AND_ASSIGN(ContentMainRunnerImpl); | 849 DISALLOW_COPY_AND_ASSIGN(ContentMainRunnerImpl); |
| 839 }; | 850 }; |
| 840 | 851 |
| 841 // static | 852 // static |
| 842 ContentMainRunner* ContentMainRunner::Create() { | 853 ContentMainRunner* ContentMainRunner::Create() { |
| 843 return new ContentMainRunnerImpl(); | 854 return new ContentMainRunnerImpl(); |
| 844 } | 855 } |
| 845 | 856 |
| 846 } // namespace content | 857 } // namespace content |
| OLD | NEW |