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 <string> | 9 #include <string> |
10 | 10 |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
51 #include "ipc/ipc_switches.h" | 51 #include "ipc/ipc_switches.h" |
52 #include "media/base/media.h" | 52 #include "media/base/media.h" |
53 #include "sandbox/win/src/sandbox_types.h" | 53 #include "sandbox/win/src/sandbox_types.h" |
54 #include "ui/base/ui_base_paths.h" | 54 #include "ui/base/ui_base_paths.h" |
55 #include "ui/base/ui_base_switches.h" | 55 #include "ui/base/ui_base_switches.h" |
56 | 56 |
57 #ifdef V8_USE_EXTERNAL_STARTUP_DATA | 57 #ifdef V8_USE_EXTERNAL_STARTUP_DATA |
58 #include "gin/v8_initializer.h" | 58 #include "gin/v8_initializer.h" |
59 #endif | 59 #endif |
60 | 60 |
61 #if defined(USE_TCMALLOC) | |
62 #include "third_party/tcmalloc/chromium/src/gperftools/malloc_extension.h" | |
63 #endif | |
64 | |
65 #if !defined(OS_IOS) | 61 #if !defined(OS_IOS) |
66 #include "content/app/mojo/mojo_init.h" | 62 #include "content/app/mojo/mojo_init.h" |
67 #include "content/browser/gpu/gpu_process_host.h" | 63 #include "content/browser/gpu/gpu_process_host.h" |
68 #include "content/browser/renderer_host/render_process_host_impl.h" | 64 #include "content/browser/renderer_host/render_process_host_impl.h" |
69 #include "content/browser/utility_process_host_impl.h" | 65 #include "content/browser/utility_process_host_impl.h" |
70 #include "content/public/plugin/content_plugin_client.h" | 66 #include "content/public/plugin/content_plugin_client.h" |
71 #include "content/public/renderer/content_renderer_client.h" | 67 #include "content/public/renderer/content_renderer_client.h" |
72 #include "content/public/utility/content_utility_client.h" | 68 #include "content/public/utility/content_utility_client.h" |
73 #endif | 69 #endif |
74 | 70 |
(...skipping 29 matching lines...) Expand all Loading... |
104 #if !defined(OS_MACOSX) && !defined(OS_ANDROID) | 100 #if !defined(OS_MACOSX) && !defined(OS_ANDROID) |
105 #include "content/zygote/zygote_main.h" | 101 #include "content/zygote/zygote_main.h" |
106 #endif | 102 #endif |
107 | 103 |
108 #endif // OS_POSIX | 104 #endif // OS_POSIX |
109 | 105 |
110 #if defined(USE_NSS_CERTS) | 106 #if defined(USE_NSS_CERTS) |
111 #include "crypto/nss_util.h" | 107 #include "crypto/nss_util.h" |
112 #endif | 108 #endif |
113 | 109 |
114 #if !defined(OS_MACOSX) && defined(USE_TCMALLOC) | 110 #if defined(USE_TCMALLOC) |
115 extern "C" { | 111 namespace { |
116 int tc_set_new_mode(int mode); | 112 |
| 113 // This method translates the tcmalloc bytes allocated function to now function |
| 114 // for alternate time source. |
| 115 unsigned int TimeSourceNowFunction() { |
| 116 return static_cast<unsigned int>( |
| 117 base::allocator::GetBytesAllocatedOnCurrentThread()); |
117 } | 118 } |
118 #endif | 119 |
| 120 } // namespace |
| 121 #endif // defined(USE_TCMALLOC) |
119 | 122 |
120 namespace content { | 123 namespace content { |
121 extern int GpuMain(const content::MainFunctionParams&); | 124 extern int GpuMain(const content::MainFunctionParams&); |
122 #if defined(ENABLE_PLUGINS) | 125 #if defined(ENABLE_PLUGINS) |
123 #if !defined(OS_LINUX) | 126 #if !defined(OS_LINUX) |
124 extern int PluginMain(const content::MainFunctionParams&); | 127 extern int PluginMain(const content::MainFunctionParams&); |
125 #endif | 128 #endif |
126 extern int PpapiPluginMain(const MainFunctionParams&); | 129 extern int PpapiPluginMain(const MainFunctionParams&); |
127 extern int PpapiBrokerMain(const MainFunctionParams&); | 130 extern int PpapiBrokerMain(const MainFunctionParams&); |
128 #endif | 131 #endif |
(...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
406 #if defined(OS_WIN) | 409 #if defined(OS_WIN) |
407 memset(&sandbox_info_, 0, sizeof(sandbox_info_)); | 410 memset(&sandbox_info_, 0, sizeof(sandbox_info_)); |
408 #endif | 411 #endif |
409 } | 412 } |
410 | 413 |
411 ~ContentMainRunnerImpl() override { | 414 ~ContentMainRunnerImpl() override { |
412 if (is_initialized_ && !is_shutdown_) | 415 if (is_initialized_ && !is_shutdown_) |
413 Shutdown(); | 416 Shutdown(); |
414 } | 417 } |
415 | 418 |
416 #if defined(USE_TCMALLOC) | |
417 static bool GetAllocatorWasteSizeThunk(size_t* size) { | |
418 size_t heap_size, allocated_bytes, unmapped_bytes; | |
419 MallocExtension* ext = MallocExtension::instance(); | |
420 if (ext->GetNumericProperty("generic.heap_size", &heap_size) && | |
421 ext->GetNumericProperty("generic.current_allocated_bytes", | |
422 &allocated_bytes) && | |
423 ext->GetNumericProperty("tcmalloc.pageheap_unmapped_bytes", | |
424 &unmapped_bytes)) { | |
425 *size = heap_size - allocated_bytes - unmapped_bytes; | |
426 return true; | |
427 } | |
428 DCHECK(false); | |
429 return false; | |
430 } | |
431 | |
432 static void GetStatsThunk(char* buffer, int buffer_length) { | |
433 MallocExtension::instance()->GetStats(buffer, buffer_length); | |
434 } | |
435 | |
436 static bool GetNumericPropertyThunk(const char* name, size_t* value) { | |
437 return MallocExtension::instance()->GetNumericProperty(name, value); | |
438 } | |
439 | |
440 static void ReleaseFreeMemoryThunk() { | |
441 MallocExtension::instance()->ReleaseFreeMemory(); | |
442 } | |
443 #endif | |
444 | |
445 int Initialize(const ContentMainParams& params) override { | 419 int Initialize(const ContentMainParams& params) override { |
446 ui_task_ = params.ui_task; | 420 ui_task_ = params.ui_task; |
447 | 421 |
448 base::EnableTerminationOnOutOfMemory(); | 422 base::EnableTerminationOnOutOfMemory(); |
449 #if defined(OS_WIN) | 423 #if defined(OS_WIN) |
450 base::win::RegisterInvalidParamHandler(); | 424 base::win::RegisterInvalidParamHandler(); |
451 ui::win::CreateATLModuleIfNeeded(); | 425 ui::win::CreateATLModuleIfNeeded(); |
452 | 426 |
453 sandbox_info_ = *params.sandbox_info; | 427 sandbox_info_ = *params.sandbox_info; |
454 #else // !OS_WIN | 428 #else // !OS_WIN |
455 | 429 |
456 #if defined(OS_ANDROID) | 430 #if defined(OS_ANDROID) |
457 // See note at the initialization of ExitManager, below; basically, | 431 // See note at the initialization of ExitManager, below; basically, |
458 // only Android builds have the ctor/dtor handlers set up to use | 432 // only Android builds have the ctor/dtor handlers set up to use |
459 // TRACE_EVENT right away. | 433 // TRACE_EVENT right away. |
460 TRACE_EVENT0("startup,benchmark", "ContentMainRunnerImpl::Initialize"); | 434 TRACE_EVENT0("startup,benchmark", "ContentMainRunnerImpl::Initialize"); |
461 #endif // OS_ANDROID | 435 #endif // OS_ANDROID |
462 | 436 |
463 // NOTE(willchan): One might ask why these TCMalloc-related calls are done | |
464 // here rather than in process_util_linux.cc with the definition of | |
465 // EnableTerminationOnOutOfMemory(). That's because base shouldn't have a | |
466 // dependency on TCMalloc. Really, we ought to have our allocator shim code | |
467 // implement this EnableTerminationOnOutOfMemory() function. Whateverz. | |
468 // This works for now. | |
469 #if !defined(OS_MACOSX) && defined(USE_TCMALLOC) | 437 #if !defined(OS_MACOSX) && defined(USE_TCMALLOC) |
470 // For tcmalloc, we need to tell it to behave like new. | 438 // Allocator initialization is needed for tcmalloc to set up the allocator |
471 tc_set_new_mode(1); | 439 // extension callbacks. This needs to happen before any threads are created |
472 | 440 // and any of the extension methods is used. To be able to call this method |
473 // On windows, we've already set these thunks up in _heap_init() | 441 // implies that the executable target should link in the allocator shim |
474 base::allocator::SetGetAllocatorWasteSizeFunction( | 442 // implementation. Note that the content target does not decide the |
475 GetAllocatorWasteSizeThunk); | 443 // allocator. |
476 base::allocator::SetGetStatsFunction(GetStatsThunk); | 444 base::allocator::InitializeAllocator(); |
477 base::allocator::SetGetNumericPropertyFunction(GetNumericPropertyThunk); | |
478 base::allocator::SetReleaseFreeMemoryFunction(ReleaseFreeMemoryThunk); | |
479 | 445 |
480 // Provide optional hook for monitoring allocation quantities on a | 446 // Provide optional hook for monitoring allocation quantities on a |
481 // per-thread basis. Only set the hook if the environment indicates this | 447 // per-thread basis. Only set the hook if the environment indicates this |
482 // needs to be enabled. | 448 // needs to be enabled. |
483 const char* profiling = getenv(tracked_objects::kAlternateProfilerTime); | 449 const char* profiling = getenv(tracked_objects::kAlternateProfilerTime); |
484 if (profiling && | 450 if (profiling && |
485 (atoi(profiling) == tracked_objects::TIME_SOURCE_TYPE_TCMALLOC)) { | 451 (atoi(profiling) == tracked_objects::TIME_SOURCE_TYPE_TCMALLOC)) { |
486 tracked_objects::SetAlternateTimeSource( | 452 tracked_objects::SetAlternateTimeSource( |
487 MallocExtension::GetBytesAllocatedOnCurrentThread, | 453 TimeSourceNowFunction, tracked_objects::TIME_SOURCE_TYPE_TCMALLOC); |
488 tracked_objects::TIME_SOURCE_TYPE_TCMALLOC); | |
489 } | 454 } |
490 #endif // !OS_MACOSX && USE_TCMALLOC | 455 #endif // !OS_MACOSX && USE_TCMALLOC |
491 | 456 |
492 #if !defined(OS_IOS) | 457 #if !defined(OS_IOS) |
493 base::GlobalDescriptors* g_fds = base::GlobalDescriptors::GetInstance(); | 458 base::GlobalDescriptors* g_fds = base::GlobalDescriptors::GetInstance(); |
494 #endif | 459 #endif |
495 | 460 |
496 // On Android, | 461 // On Android, |
497 // - setlocale() is not supported. | 462 // - setlocale() is not supported. |
498 // - We do not override the signal handlers so that we can get | 463 // - We do not override the signal handlers so that we can get |
(...skipping 364 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
863 | 828 |
864 DISALLOW_COPY_AND_ASSIGN(ContentMainRunnerImpl); | 829 DISALLOW_COPY_AND_ASSIGN(ContentMainRunnerImpl); |
865 }; | 830 }; |
866 | 831 |
867 // static | 832 // static |
868 ContentMainRunner* ContentMainRunner::Create() { | 833 ContentMainRunner* ContentMainRunner::Create() { |
869 return new ContentMainRunnerImpl(); | 834 return new ContentMainRunnerImpl(); |
870 } | 835 } |
871 | 836 |
872 } // namespace content | 837 } // namespace content |
OLD | NEW |