| 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 "chrome/app/chrome_main_delegate.h" | 5 #include "chrome/app/chrome_main_delegate.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/lazy_instance.h" | 8 #include "base/lazy_instance.h" |
| 9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
| 10 #include "base/metrics/field_trial.h" | 10 #include "base/metrics/field_trial.h" |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 #include "chrome/common/chrome_paths_internal.h" | 23 #include "chrome/common/chrome_paths_internal.h" |
| 24 #include "chrome/common/chrome_switches.h" | 24 #include "chrome/common/chrome_switches.h" |
| 25 #include "chrome/common/chrome_version_info.h" | 25 #include "chrome/common/chrome_version_info.h" |
| 26 #include "chrome/common/logging_chrome.h" | 26 #include "chrome/common/logging_chrome.h" |
| 27 #include "chrome/common/profiling.h" | 27 #include "chrome/common/profiling.h" |
| 28 #include "chrome/common/url_constants.h" | 28 #include "chrome/common/url_constants.h" |
| 29 #include "chrome/plugin/chrome_content_plugin_client.h" | 29 #include "chrome/plugin/chrome_content_plugin_client.h" |
| 30 #include "chrome/renderer/chrome_content_renderer_client.h" | 30 #include "chrome/renderer/chrome_content_renderer_client.h" |
| 31 #include "chrome/utility/chrome_content_utility_client.h" | 31 #include "chrome/utility/chrome_content_utility_client.h" |
| 32 #include "content/public/common/content_client.h" | 32 #include "content/public/common/content_client.h" |
| 33 #include "content/public/common/content_debug_logging.h" |
| 33 #include "content/public/common/content_paths.h" | 34 #include "content/public/common/content_paths.h" |
| 34 #include "content/public/common/content_switches.h" | 35 #include "content/public/common/content_switches.h" |
| 35 #include "ui/base/ui_base_switches.h" | 36 #include "ui/base/ui_base_switches.h" |
| 36 | 37 |
| 37 #if defined(OS_WIN) | 38 #if defined(OS_WIN) |
| 38 #include <algorithm> | 39 #include <algorithm> |
| 39 #include <atlbase.h> | 40 #include <atlbase.h> |
| 40 #include <malloc.h> | 41 #include <malloc.h> |
| 41 #include "base/string_util.h" | 42 #include "base/string_util.h" |
| 42 #include "base/win/registry.h" | 43 #include "base/win/registry.h" |
| (...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 362 } | 363 } |
| 363 #endif | 364 #endif |
| 364 | 365 |
| 365 #endif // OS_POSIX | 366 #endif // OS_POSIX |
| 366 | 367 |
| 367 struct MainFunction { | 368 struct MainFunction { |
| 368 const char* name; | 369 const char* name; |
| 369 int (*function)(const content::MainFunctionParams&); | 370 int (*function)(const content::MainFunctionParams&); |
| 370 }; | 371 }; |
| 371 | 372 |
| 373 // Limit message count and size to prevent rogue processes from |
| 374 // bloating memory use. |
| 375 const size_t kMaxBugMessages = 20; |
| 376 const size_t kMaxMessageSize = 64; |
| 377 |
| 378 // Locks g_messages. |
| 379 static base::LazyInstance<base::Lock>::Leaky |
| 380 g_messages_lock = LAZY_INSTANCE_INITIALIZER; |
| 381 |
| 382 // Map bug ids to messages for that bug. |
| 383 // TODO(shess): Would multimap<> maintain the items in order added? |
| 384 base::LazyInstance<std::map<int, std::vector<std::string> > > |
| 385 g_messages = LAZY_INSTANCE_INITIALIZER; |
| 386 |
| 387 void RecordMsg(int bug_id, const std::string& msg) { |
| 388 // Only record information about specific bugs to prevent rogue |
| 389 // processes from bloating memory usage. |
| 390 CHECK(bug_id == 97285 || bug_id == 141055); |
| 391 |
| 392 // Make sure legitimate clients know that things are getting too big |
| 393 // to handle. |
| 394 DCHECK_LE(msg.size(), kMaxMessageSize); |
| 395 |
| 396 base::AutoLock pin(g_messages_lock.Get()); |
| 397 std::vector<std::string>& bug_messages = g_messages.Get()[bug_id]; |
| 398 bug_messages.push_back(msg.substr(0, kMaxMessageSize)); |
| 399 |
| 400 // Should only remove a single item. |
| 401 while (bug_messages.size() > kMaxBugMessages) |
| 402 bug_messages.erase(bug_messages.begin()); |
| 403 } |
| 404 |
| 405 bool GetMessages(int bug_id, std::vector<std::string>* msgs) { |
| 406 CHECK(bug_id == 97285 || bug_id == 141055); |
| 407 |
| 408 base::AutoLock pin(g_messages_lock.Get()); |
| 409 *msgs = g_messages.Get()[bug_id]; |
| 410 return !msgs->empty(); |
| 411 } |
| 412 |
| 372 } // namespace | 413 } // namespace |
| 373 | 414 |
| 374 ChromeMainDelegate::ChromeMainDelegate() { | 415 ChromeMainDelegate::ChromeMainDelegate() { |
| 375 } | 416 } |
| 376 | 417 |
| 377 ChromeMainDelegate::~ChromeMainDelegate() { | 418 ChromeMainDelegate::~ChromeMainDelegate() { |
| 378 } | 419 } |
| 379 | 420 |
| 380 bool ChromeMainDelegate::BasicStartupComplete(int* exit_code) { | 421 bool ChromeMainDelegate::BasicStartupComplete(int* exit_code) { |
| 381 #if defined(OS_CHROMEOS) | 422 #if defined(OS_CHROMEOS) |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 518 if (IsCrashReporterEnabled()) | 559 if (IsCrashReporterEnabled()) |
| 519 InitCrashProcessInfo(); | 560 InitCrashProcessInfo(); |
| 520 } | 561 } |
| 521 #endif // defined(OS_MACOSX) | 562 #endif // defined(OS_MACOSX) |
| 522 | 563 |
| 523 void ChromeMainDelegate::PreSandboxStartup() { | 564 void ChromeMainDelegate::PreSandboxStartup() { |
| 524 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); | 565 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
| 525 std::string process_type = | 566 std::string process_type = |
| 526 command_line.GetSwitchValueASCII(switches::kProcessType); | 567 command_line.GetSwitchValueASCII(switches::kProcessType); |
| 527 | 568 |
| 569 // TODO(shess): Could this be registered earlier? |
| 570 if (process_type.empty()) |
| 571 content::debug::RegisterMessageHandlers(RecordMsg, GetMessages); |
| 572 |
| 528 chrome::RegisterPathProvider(); | 573 chrome::RegisterPathProvider(); |
| 529 | 574 |
| 530 #if defined(OS_MACOSX) | 575 #if defined(OS_MACOSX) |
| 531 // On the Mac, the child executable lives at a predefined location within | 576 // On the Mac, the child executable lives at a predefined location within |
| 532 // the app bundle's versioned directory. | 577 // the app bundle's versioned directory. |
| 533 PathService::Override(content::CHILD_PROCESS_EXE, | 578 PathService::Override(content::CHILD_PROCESS_EXE, |
| 534 chrome::GetVersionedDirectory(). | 579 chrome::GetVersionedDirectory(). |
| 535 Append(chrome::kHelperProcessExecutablePath)); | 580 Append(chrome::kHelperProcessExecutablePath)); |
| 536 | 581 |
| 537 InitMacCrashReporter(command_line, process_type); | 582 InitMacCrashReporter(command_line, process_type); |
| (...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 716 | 761 |
| 717 content::ContentRendererClient* | 762 content::ContentRendererClient* |
| 718 ChromeMainDelegate::CreateContentRendererClient() { | 763 ChromeMainDelegate::CreateContentRendererClient() { |
| 719 return &g_chrome_content_renderer_client.Get(); | 764 return &g_chrome_content_renderer_client.Get(); |
| 720 } | 765 } |
| 721 | 766 |
| 722 content::ContentUtilityClient* | 767 content::ContentUtilityClient* |
| 723 ChromeMainDelegate::CreateContentUtilityClient() { | 768 ChromeMainDelegate::CreateContentUtilityClient() { |
| 724 return &g_chrome_content_utility_client.Get(); | 769 return &g_chrome_content_utility_client.Get(); |
| 725 } | 770 } |
| OLD | NEW |