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 <stddef.h> | 7 #include <stddef.h> |
8 #include <stdlib.h> | 8 #include <stdlib.h> |
9 #include <string.h> | 9 #include <string.h> |
10 #include <string> | 10 #include <string> |
(...skipping 399 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
410 #if defined(OS_WIN) | 410 #if defined(OS_WIN) |
411 memset(&sandbox_info_, 0, sizeof(sandbox_info_)); | 411 memset(&sandbox_info_, 0, sizeof(sandbox_info_)); |
412 #endif | 412 #endif |
413 } | 413 } |
414 | 414 |
415 ~ContentMainRunnerImpl() override { | 415 ~ContentMainRunnerImpl() override { |
416 if (is_initialized_ && !is_shutdown_) | 416 if (is_initialized_ && !is_shutdown_) |
417 Shutdown(); | 417 Shutdown(); |
418 } | 418 } |
419 | 419 |
420 #if defined(USE_TCMALLOC) | |
421 static bool GetNumericPropertyThunk(const char* name, size_t* value) { | |
422 return MallocExtension::instance()->GetNumericProperty(name, value); | |
423 } | |
424 | |
425 static void ReleaseFreeMemoryThunk() { | |
426 MallocExtension::instance()->ReleaseFreeMemory(); | |
427 } | |
428 #endif | |
429 | |
430 int Initialize(const ContentMainParams& params) override { | 420 int Initialize(const ContentMainParams& params) override { |
431 ui_task_ = params.ui_task; | 421 ui_task_ = params.ui_task; |
432 | 422 |
433 base::EnableTerminationOnOutOfMemory(); | 423 base::EnableTerminationOnOutOfMemory(); |
434 #if defined(OS_WIN) | 424 #if defined(OS_WIN) |
435 base::win::RegisterInvalidParamHandler(); | 425 base::win::RegisterInvalidParamHandler(); |
436 ui::win::CreateATLModuleIfNeeded(); | 426 ui::win::CreateATLModuleIfNeeded(); |
437 | 427 |
438 sandbox_info_ = *params.sandbox_info; | 428 sandbox_info_ = *params.sandbox_info; |
439 #else // !OS_WIN | 429 #else // !OS_WIN |
440 | 430 |
441 #if defined(OS_ANDROID) | 431 #if defined(OS_ANDROID) |
442 // See note at the initialization of ExitManager, below; basically, | 432 // See note at the initialization of ExitManager, below; basically, |
443 // only Android builds have the ctor/dtor handlers set up to use | 433 // only Android builds have the ctor/dtor handlers set up to use |
444 // TRACE_EVENT right away. | 434 // TRACE_EVENT right away. |
445 TRACE_EVENT0("startup,benchmark", "ContentMainRunnerImpl::Initialize"); | 435 TRACE_EVENT0("startup,benchmark", "ContentMainRunnerImpl::Initialize"); |
446 #endif // OS_ANDROID | 436 #endif // OS_ANDROID |
447 | 437 |
448 // NOTE(willchan): One might ask why these TCMalloc-related calls are done | 438 // NOTE(willchan): One might ask why these TCMalloc-related calls are done |
449 // here rather than in process_util_linux.cc with the definition of | 439 // here rather than in process_util_linux.cc with the definition of |
450 // EnableTerminationOnOutOfMemory(). That's because base shouldn't have a | 440 // EnableTerminationOnOutOfMemory(). That's because base shouldn't have a |
451 // dependency on TCMalloc. Really, we ought to have our allocator shim code | 441 // dependency on TCMalloc. Really, we ought to have our allocator shim code |
452 // implement this EnableTerminationOnOutOfMemory() function. Whateverz. | 442 // implement this EnableTerminationOnOutOfMemory() function. Whateverz. |
453 // This works for now. | 443 // This works for now. |
454 #if !defined(OS_MACOSX) && defined(USE_TCMALLOC) | 444 #if !defined(OS_MACOSX) && defined(USE_TCMALLOC) |
455 // For tcmalloc, we need to tell it to behave like new. | 445 // For tcmalloc, we need to tell it to behave like new. |
456 tc_set_new_mode(1); | 446 tc_set_new_mode(1); |
457 | 447 |
458 // On windows, we've already set these thunks up in _heap_init() | |
459 base::allocator::SetGetNumericPropertyFunction(GetNumericPropertyThunk); | |
460 base::allocator::SetReleaseFreeMemoryFunction(ReleaseFreeMemoryThunk); | |
461 | |
462 // Provide optional hook for monitoring allocation quantities on a | 448 // Provide optional hook for monitoring allocation quantities on a |
463 // per-thread basis. Only set the hook if the environment indicates this | 449 // per-thread basis. Only set the hook if the environment indicates this |
464 // needs to be enabled. | 450 // needs to be enabled. |
465 const char* profiling = getenv(tracked_objects::kAlternateProfilerTime); | 451 const char* profiling = getenv(tracked_objects::kAlternateProfilerTime); |
466 if (profiling && | 452 if (profiling && |
467 (atoi(profiling) == tracked_objects::TIME_SOURCE_TYPE_TCMALLOC)) { | 453 (atoi(profiling) == tracked_objects::TIME_SOURCE_TYPE_TCMALLOC)) { |
468 tracked_objects::SetAlternateTimeSource( | 454 tracked_objects::SetAlternateTimeSource( |
469 MallocExtension::GetBytesAllocatedOnCurrentThread, | 455 MallocExtension::GetBytesAllocatedOnCurrentThread, |
470 tracked_objects::TIME_SOURCE_TYPE_TCMALLOC); | 456 tracked_objects::TIME_SOURCE_TYPE_TCMALLOC); |
471 } | 457 } |
(...skipping 374 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
846 | 832 |
847 DISALLOW_COPY_AND_ASSIGN(ContentMainRunnerImpl); | 833 DISALLOW_COPY_AND_ASSIGN(ContentMainRunnerImpl); |
848 }; | 834 }; |
849 | 835 |
850 // static | 836 // static |
851 ContentMainRunner* ContentMainRunner::Create() { | 837 ContentMainRunner* ContentMainRunner::Create() { |
852 return new ContentMainRunnerImpl(); | 838 return new ContentMainRunnerImpl(); |
853 } | 839 } |
854 | 840 |
855 } // namespace content | 841 } // namespace content |
OLD | NEW |