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 395 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
406 memset(&sandbox_info_, 0, sizeof(sandbox_info_)); | 406 memset(&sandbox_info_, 0, sizeof(sandbox_info_)); |
407 #endif | 407 #endif |
408 } | 408 } |
409 | 409 |
410 ~ContentMainRunnerImpl() { | 410 ~ContentMainRunnerImpl() { |
411 if (is_initialized_ && !is_shutdown_) | 411 if (is_initialized_ && !is_shutdown_) |
412 Shutdown(); | 412 Shutdown(); |
413 } | 413 } |
414 | 414 |
415 #if defined(USE_TCMALLOC) | 415 #if defined(USE_TCMALLOC) |
| 416 static bool GetPropertyThunk(const char* name, size_t* value) { |
| 417 return MallocExtension::instance()->GetNumericProperty(name, value); |
| 418 } |
| 419 |
416 static void GetStatsThunk(char* buffer, int buffer_length) { | 420 static void GetStatsThunk(char* buffer, int buffer_length) { |
417 MallocExtension::instance()->GetStats(buffer, buffer_length); | 421 MallocExtension::instance()->GetStats(buffer, buffer_length); |
418 } | 422 } |
419 | 423 |
420 static void ReleaseFreeMemoryThunk() { | 424 static void ReleaseFreeMemoryThunk() { |
421 MallocExtension::instance()->ReleaseFreeMemory(); | 425 MallocExtension::instance()->ReleaseFreeMemory(); |
422 } | 426 } |
423 #endif | 427 #endif |
424 | 428 |
425 | 429 |
(...skipping 18 matching lines...) Expand all Loading... |
444 // process_util_linux.cc with the definition of | 448 // process_util_linux.cc with the definition of |
445 // EnableTerminationOnOutOfMemory(). That's because base shouldn't have a | 449 // EnableTerminationOnOutOfMemory(). That's because base shouldn't have a |
446 // dependency on TCMalloc. Really, we ought to have our allocator shim code | 450 // dependency on TCMalloc. Really, we ought to have our allocator shim code |
447 // implement this EnableTerminationOnOutOfMemory() function. Whateverz. | 451 // implement this EnableTerminationOnOutOfMemory() function. Whateverz. |
448 // This works for now. | 452 // This works for now. |
449 #if !defined(OS_MACOSX) && defined(USE_TCMALLOC) | 453 #if !defined(OS_MACOSX) && defined(USE_TCMALLOC) |
450 // For tcmalloc, we need to tell it to behave like new. | 454 // For tcmalloc, we need to tell it to behave like new. |
451 tc_set_new_mode(1); | 455 tc_set_new_mode(1); |
452 | 456 |
453 // On windows, we've already set these thunks up in _heap_init() | 457 // On windows, we've already set these thunks up in _heap_init() |
| 458 base::allocator::SetGetPropertyFunction(GetPropertyThunk); |
454 base::allocator::SetGetStatsFunction(GetStatsThunk); | 459 base::allocator::SetGetStatsFunction(GetStatsThunk); |
455 base::allocator::SetReleaseFreeMemoryFunction(ReleaseFreeMemoryThunk); | 460 base::allocator::SetReleaseFreeMemoryFunction(ReleaseFreeMemoryThunk); |
456 | 461 |
457 // Provide optional hook for monitoring allocation quantities on a | 462 // Provide optional hook for monitoring allocation quantities on a |
458 // per-thread basis. Only set the hook if the environment indicates this | 463 // per-thread basis. Only set the hook if the environment indicates this |
459 // needs to be enabled. | 464 // needs to be enabled. |
460 const char* profiling = getenv(tracked_objects::kAlternateProfilerTime); | 465 const char* profiling = getenv(tracked_objects::kAlternateProfilerTime); |
461 if (profiling && | 466 if (profiling && |
462 (atoi(profiling) == tracked_objects::TIME_SOURCE_TYPE_TCMALLOC)) { | 467 (atoi(profiling) == tracked_objects::TIME_SOURCE_TYPE_TCMALLOC)) { |
463 tracked_objects::SetAlternateTimeSource( | 468 tracked_objects::SetAlternateTimeSource( |
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
703 | 708 |
704 DISALLOW_COPY_AND_ASSIGN(ContentMainRunnerImpl); | 709 DISALLOW_COPY_AND_ASSIGN(ContentMainRunnerImpl); |
705 }; | 710 }; |
706 | 711 |
707 // static | 712 // static |
708 ContentMainRunner* ContentMainRunner::Create() { | 713 ContentMainRunner* ContentMainRunner::Create() { |
709 return new ContentMainRunnerImpl(); | 714 return new ContentMainRunnerImpl(); |
710 } | 715 } |
711 | 716 |
712 } // namespace content | 717 } // namespace content |
OLD | NEW |