| 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 432 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 443 : is_initialized_(false), | 443 : is_initialized_(false), |
| 444 is_shutdown_(false), | 444 is_shutdown_(false), |
| 445 completed_basic_startup_(false), | 445 completed_basic_startup_(false), |
| 446 delegate_(NULL), | 446 delegate_(NULL), |
| 447 ui_task_(NULL) { | 447 ui_task_(NULL) { |
| 448 #if defined(OS_WIN) | 448 #if defined(OS_WIN) |
| 449 memset(&sandbox_info_, 0, sizeof(sandbox_info_)); | 449 memset(&sandbox_info_, 0, sizeof(sandbox_info_)); |
| 450 #endif | 450 #endif |
| 451 } | 451 } |
| 452 | 452 |
| 453 virtual ~ContentMainRunnerImpl() { | 453 ~ContentMainRunnerImpl() override { |
| 454 if (is_initialized_ && !is_shutdown_) | 454 if (is_initialized_ && !is_shutdown_) |
| 455 Shutdown(); | 455 Shutdown(); |
| 456 } | 456 } |
| 457 | 457 |
| 458 #if defined(USE_TCMALLOC) | 458 #if defined(USE_TCMALLOC) |
| 459 static bool GetAllocatorWasteSizeThunk(size_t* size) { | 459 static bool GetAllocatorWasteSizeThunk(size_t* size) { |
| 460 size_t heap_size, allocated_bytes, unmapped_bytes; | 460 size_t heap_size, allocated_bytes, unmapped_bytes; |
| 461 MallocExtension* ext = MallocExtension::instance(); | 461 MallocExtension* ext = MallocExtension::instance(); |
| 462 if (ext->GetNumericProperty("generic.heap_size", &heap_size) && | 462 if (ext->GetNumericProperty("generic.heap_size", &heap_size) && |
| 463 ext->GetNumericProperty("generic.current_allocated_bytes", | 463 ext->GetNumericProperty("generic.current_allocated_bytes", |
| 464 &allocated_bytes) && | 464 &allocated_bytes) && |
| 465 ext->GetNumericProperty("tcmalloc.pageheap_unmapped_bytes", | 465 ext->GetNumericProperty("tcmalloc.pageheap_unmapped_bytes", |
| 466 &unmapped_bytes)) { | 466 &unmapped_bytes)) { |
| 467 *size = heap_size - allocated_bytes - unmapped_bytes; | 467 *size = heap_size - allocated_bytes - unmapped_bytes; |
| 468 return true; | 468 return true; |
| 469 } | 469 } |
| 470 DCHECK(false); | 470 DCHECK(false); |
| 471 return false; | 471 return false; |
| 472 } | 472 } |
| 473 | 473 |
| 474 static void GetStatsThunk(char* buffer, int buffer_length) { | 474 static void GetStatsThunk(char* buffer, int buffer_length) { |
| 475 MallocExtension::instance()->GetStats(buffer, buffer_length); | 475 MallocExtension::instance()->GetStats(buffer, buffer_length); |
| 476 } | 476 } |
| 477 | 477 |
| 478 static void ReleaseFreeMemoryThunk() { | 478 static void ReleaseFreeMemoryThunk() { |
| 479 MallocExtension::instance()->ReleaseFreeMemory(); | 479 MallocExtension::instance()->ReleaseFreeMemory(); |
| 480 } | 480 } |
| 481 #endif | 481 #endif |
| 482 | 482 |
| 483 virtual int Initialize(const ContentMainParams& params) override { | 483 int Initialize(const ContentMainParams& params) override { |
| 484 ui_task_ = params.ui_task; | 484 ui_task_ = params.ui_task; |
| 485 | 485 |
| 486 #if defined(OS_WIN) | 486 #if defined(OS_WIN) |
| 487 RegisterInvalidParamHandler(); | 487 RegisterInvalidParamHandler(); |
| 488 ui::win::CreateATLModuleIfNeeded(); | 488 ui::win::CreateATLModuleIfNeeded(); |
| 489 | 489 |
| 490 sandbox_info_ = *params.sandbox_info; | 490 sandbox_info_ = *params.sandbox_info; |
| 491 #else // !OS_WIN | 491 #else // !OS_WIN |
| 492 | 492 |
| 493 #if defined(OS_ANDROID) | 493 #if defined(OS_ANDROID) |
| (...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 742 } | 742 } |
| 743 #endif | 743 #endif |
| 744 | 744 |
| 745 if (delegate_) | 745 if (delegate_) |
| 746 delegate_->SandboxInitialized(process_type); | 746 delegate_->SandboxInitialized(process_type); |
| 747 | 747 |
| 748 // Return -1 to indicate no early termination. | 748 // Return -1 to indicate no early termination. |
| 749 return -1; | 749 return -1; |
| 750 } | 750 } |
| 751 | 751 |
| 752 virtual int Run() override { | 752 int Run() override { |
| 753 DCHECK(is_initialized_); | 753 DCHECK(is_initialized_); |
| 754 DCHECK(!is_shutdown_); | 754 DCHECK(!is_shutdown_); |
| 755 const base::CommandLine& command_line = | 755 const base::CommandLine& command_line = |
| 756 *base::CommandLine::ForCurrentProcess(); | 756 *base::CommandLine::ForCurrentProcess(); |
| 757 std::string process_type = | 757 std::string process_type = |
| 758 command_line.GetSwitchValueASCII(switches::kProcessType); | 758 command_line.GetSwitchValueASCII(switches::kProcessType); |
| 759 | 759 |
| 760 MainFunctionParams main_params(command_line); | 760 MainFunctionParams main_params(command_line); |
| 761 main_params.ui_task = ui_task_; | 761 main_params.ui_task = ui_task_; |
| 762 #if defined(OS_WIN) | 762 #if defined(OS_WIN) |
| 763 main_params.sandbox_info = &sandbox_info_; | 763 main_params.sandbox_info = &sandbox_info_; |
| 764 #elif defined(OS_MACOSX) | 764 #elif defined(OS_MACOSX) |
| 765 main_params.autorelease_pool = autorelease_pool_.get(); | 765 main_params.autorelease_pool = autorelease_pool_.get(); |
| 766 #endif | 766 #endif |
| 767 | 767 |
| 768 #if !defined(OS_IOS) | 768 #if !defined(OS_IOS) |
| 769 return RunNamedProcessTypeMain(process_type, main_params, delegate_); | 769 return RunNamedProcessTypeMain(process_type, main_params, delegate_); |
| 770 #else | 770 #else |
| 771 return 1; | 771 return 1; |
| 772 #endif | 772 #endif |
| 773 } | 773 } |
| 774 | 774 |
| 775 virtual void Shutdown() override { | 775 void Shutdown() override { |
| 776 DCHECK(is_initialized_); | 776 DCHECK(is_initialized_); |
| 777 DCHECK(!is_shutdown_); | 777 DCHECK(!is_shutdown_); |
| 778 | 778 |
| 779 if (completed_basic_startup_ && delegate_) { | 779 if (completed_basic_startup_ && delegate_) { |
| 780 const base::CommandLine& command_line = | 780 const base::CommandLine& command_line = |
| 781 *base::CommandLine::ForCurrentProcess(); | 781 *base::CommandLine::ForCurrentProcess(); |
| 782 std::string process_type = | 782 std::string process_type = |
| 783 command_line.GetSwitchValueASCII(switches::kProcessType); | 783 command_line.GetSwitchValueASCII(switches::kProcessType); |
| 784 | 784 |
| 785 delegate_->ProcessExiting(process_type); | 785 delegate_->ProcessExiting(process_type); |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 828 | 828 |
| 829 DISALLOW_COPY_AND_ASSIGN(ContentMainRunnerImpl); | 829 DISALLOW_COPY_AND_ASSIGN(ContentMainRunnerImpl); |
| 830 }; | 830 }; |
| 831 | 831 |
| 832 // static | 832 // static |
| 833 ContentMainRunner* ContentMainRunner::Create() { | 833 ContentMainRunner* ContentMainRunner::Create() { |
| 834 return new ContentMainRunnerImpl(); | 834 return new ContentMainRunnerImpl(); |
| 835 } | 835 } |
| 836 | 836 |
| 837 } // namespace content | 837 } // namespace content |
| OLD | NEW |