| 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 "base/allocator/allocator_extension.h" |
| 7 #include "base/at_exit.h" | 8 #include "base/at_exit.h" |
| 8 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 9 #include "base/debug/debugger.h" | 10 #include "base/debug/debugger.h" |
| 10 #include "base/debug/trace_event.h" | 11 #include "base/debug/trace_event.h" |
| 11 #include "base/file_path.h" | 12 #include "base/file_path.h" |
| 12 #include "base/i18n/icu_util.h" | 13 #include "base/i18n/icu_util.h" |
| 13 #include "base/logging.h" | 14 #include "base/logging.h" |
| 14 #include "base/memory/scoped_ptr.h" | 15 #include "base/memory/scoped_ptr.h" |
| 15 #include "base/metrics/stats_table.h" | 16 #include "base/metrics/stats_table.h" |
| 16 #include "base/path_service.h" | 17 #include "base/path_service.h" |
| (...skipping 13 matching lines...) Expand all Loading... |
| 30 #include "content/public/common/url_constants.h" | 31 #include "content/public/common/url_constants.h" |
| 31 #include "crypto/nss_util.h" | 32 #include "crypto/nss_util.h" |
| 32 #include "ipc/ipc_switches.h" | 33 #include "ipc/ipc_switches.h" |
| 33 #include "media/base/media.h" | 34 #include "media/base/media.h" |
| 34 #include "sandbox/src/sandbox_types.h" | 35 #include "sandbox/src/sandbox_types.h" |
| 35 #include "ui/base/ui_base_switches.h" | 36 #include "ui/base/ui_base_switches.h" |
| 36 #include "ui/base/ui_base_paths.h" | 37 #include "ui/base/ui_base_paths.h" |
| 37 #include "ui/base/win/dpi.h" | 38 #include "ui/base/win/dpi.h" |
| 38 #include "webkit/glue/webkit_glue.h" | 39 #include "webkit/glue/webkit_glue.h" |
| 39 | 40 |
| 41 #if defined(USE_TCMALLOC) |
| 42 #include "third_party/tcmalloc/chromium/src/gperftools/malloc_extension.h" |
| 43 #endif |
| 44 |
| 40 #if defined(OS_WIN) | 45 #if defined(OS_WIN) |
| 41 #include <atlbase.h> | 46 #include <atlbase.h> |
| 42 #include <atlapp.h> | 47 #include <atlapp.h> |
| 43 #include <malloc.h> | 48 #include <malloc.h> |
| 44 #elif defined(OS_MACOSX) | 49 #elif defined(OS_MACOSX) |
| 45 #include "base/mac/scoped_nsautorelease_pool.h" | 50 #include "base/mac/scoped_nsautorelease_pool.h" |
| 46 #include "base/mach_ipc_mac.h" | 51 #include "base/mach_ipc_mac.h" |
| 47 #include "base/system_monitor/system_monitor.h" | 52 #include "base/system_monitor/system_monitor.h" |
| 48 #include "content/browser/mach_broker_mac.h" | 53 #include "content/browser/mach_broker_mac.h" |
| 49 #include "content/common/sandbox_init_mac.h" | 54 #include "content/common/sandbox_init_mac.h" |
| (...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 307 : is_initialized_(false), | 312 : is_initialized_(false), |
| 308 is_shutdown_(false), | 313 is_shutdown_(false), |
| 309 completed_basic_startup_(false) { | 314 completed_basic_startup_(false) { |
| 310 } | 315 } |
| 311 | 316 |
| 312 ~ContentMainRunnerImpl() { | 317 ~ContentMainRunnerImpl() { |
| 313 if (is_initialized_ && !is_shutdown_) | 318 if (is_initialized_ && !is_shutdown_) |
| 314 Shutdown(); | 319 Shutdown(); |
| 315 } | 320 } |
| 316 | 321 |
| 322 #if defined(USE_TCMALLOC) |
| 323 static void GetStatsThunk(char* buffer, int buffer_length) { |
| 324 MallocExtension::instance()->GetStats(buffer, buffer_length); |
| 325 } |
| 326 |
| 327 static void ReleaseFreeMemoryThunk() { |
| 328 MallocExtension::instance()->ReleaseFreeMemory(); |
| 329 } |
| 330 #endif |
| 331 |
| 332 |
| 317 #if defined(OS_WIN) | 333 #if defined(OS_WIN) |
| 318 virtual int Initialize(HINSTANCE instance, | 334 virtual int Initialize(HINSTANCE instance, |
| 319 sandbox::SandboxInterfaceInfo* sandbox_info, | 335 sandbox::SandboxInterfaceInfo* sandbox_info, |
| 320 content::ContentMainDelegate* delegate) OVERRIDE { | 336 content::ContentMainDelegate* delegate) OVERRIDE { |
| 321 // argc/argv are ignored on Windows; see command_line.h for details. | 337 // argc/argv are ignored on Windows; see command_line.h for details. |
| 322 int argc = 0; | 338 int argc = 0; |
| 323 char** argv = NULL; | 339 char** argv = NULL; |
| 324 | 340 |
| 325 content::RegisterInvalidParamHandler(); | 341 content::RegisterInvalidParamHandler(); |
| 326 _Module.Init(NULL, static_cast<HINSTANCE>(instance)); | 342 _Module.Init(NULL, static_cast<HINSTANCE>(instance)); |
| 327 | 343 |
| 328 if (sandbox_info) | 344 if (sandbox_info) |
| 329 sandbox_info_ = *sandbox_info; | 345 sandbox_info_ = *sandbox_info; |
| 330 else | 346 else |
| 331 memset(&sandbox_info_, 0, sizeof(sandbox_info_)); | 347 memset(&sandbox_info_, 0, sizeof(sandbox_info_)); |
| 332 | 348 |
| 333 #else // !OS_WIN | 349 #else // !OS_WIN |
| 334 virtual int Initialize(int argc, | 350 virtual int Initialize(int argc, |
| 335 const char** argv, | 351 const char** argv, |
| 336 content::ContentMainDelegate* delegate) OVERRIDE { | 352 content::ContentMainDelegate* delegate) OVERRIDE { |
| 337 // NOTE(willchan): One might ask why this call is done here rather than in | 353 // NOTE(willchan): One might ask why this call is done here rather than in |
| 338 // process_util_linux.cc with the definition of | 354 // process_util_linux.cc with the definition of |
| 339 // EnableTerminationOnOutOfMemory(). That's because base shouldn't have a | 355 // EnableTerminationOnOutOfMemory(). That's because base shouldn't have a |
| 340 // dependency on TCMalloc. Really, we ought to have our allocator shim code | 356 // dependency on TCMalloc. Really, we ought to have our allocator shim code |
| 341 // implement this EnableTerminationOnOutOfMemory() function. Whateverz. | 357 // implement this EnableTerminationOnOutOfMemory() function. Whateverz. |
| 342 // This works for now. | 358 // This works for now. |
| 343 #if !defined(OS_MACOSX) && defined(USE_TCMALLOC) | 359 #if !defined(OS_MACOSX) && defined(USE_TCMALLOC) |
| 344 // For tcmalloc, we need to tell it to behave like new. | 360 // For tcmalloc, we need to tell it to behave like new. |
| 345 tc_set_new_mode(1); | 361 tc_set_new_mode(1); |
| 362 |
| 363 // On windows, we've already set these thunks up in _heap_init() |
| 364 base::allocator::SetGetStatsFunction(GetStatsThunk); |
| 365 base::allocator::SetReleaseFreeMemoryFunction(ReleaseFreeMemoryThunk); |
| 346 #endif | 366 #endif |
| 347 | 367 |
| 348 #if !defined(OS_ANDROID) | 368 #if !defined(OS_ANDROID) |
| 349 // Set C library locale to make sure CommandLine can parse argument values | 369 // Set C library locale to make sure CommandLine can parse argument values |
| 350 // in correct encoding. | 370 // in correct encoding. |
| 351 setlocale(LC_ALL, ""); | 371 setlocale(LC_ALL, ""); |
| 352 #endif | 372 #endif |
| 353 | 373 |
| 354 SetupSignalHandlers(); | 374 SetupSignalHandlers(); |
| 355 | 375 |
| (...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 584 } // namespace | 604 } // namespace |
| 585 | 605 |
| 586 namespace content { | 606 namespace content { |
| 587 | 607 |
| 588 // static | 608 // static |
| 589 ContentMainRunner* ContentMainRunner::Create() { | 609 ContentMainRunner* ContentMainRunner::Create() { |
| 590 return new ContentMainRunnerImpl(); | 610 return new ContentMainRunnerImpl(); |
| 591 } | 611 } |
| 592 | 612 |
| 593 } // namespace content | 613 } // namespace content |
| OLD | NEW |