Chromium Code Reviews| 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 std::vector<std::string>& bug_messages = g_messages.Get()[bug_id]; | |
| 410 msgs->assign(bug_messages.begin(), bug_messages.end()); | |
|
Bernhard Bauer
2012/09/05 15:04:55
Could you just write `*msgs = g_messages.Get()[bug
Scott Hess - ex-Googler
2012/09/05 17:17:05
Done. Sometimes it's harder to see the things whi
| |
| 411 return !msgs->empty(); | |
| 412 } | |
| 413 | |
| 372 } // namespace | 414 } // namespace |
| 373 | 415 |
| 374 ChromeMainDelegate::ChromeMainDelegate() { | 416 ChromeMainDelegate::ChromeMainDelegate() { |
| 375 } | 417 } |
| 376 | 418 |
| 377 ChromeMainDelegate::~ChromeMainDelegate() { | 419 ChromeMainDelegate::~ChromeMainDelegate() { |
| 378 } | 420 } |
| 379 | 421 |
| 380 bool ChromeMainDelegate::BasicStartupComplete(int* exit_code) { | 422 bool ChromeMainDelegate::BasicStartupComplete(int* exit_code) { |
| 381 #if defined(OS_CHROMEOS) | 423 #if defined(OS_CHROMEOS) |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 518 if (IsCrashReporterEnabled()) | 560 if (IsCrashReporterEnabled()) |
| 519 InitCrashProcessInfo(); | 561 InitCrashProcessInfo(); |
| 520 } | 562 } |
| 521 #endif // defined(OS_MACOSX) | 563 #endif // defined(OS_MACOSX) |
| 522 | 564 |
| 523 void ChromeMainDelegate::PreSandboxStartup() { | 565 void ChromeMainDelegate::PreSandboxStartup() { |
| 524 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); | 566 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
| 525 std::string process_type = | 567 std::string process_type = |
| 526 command_line.GetSwitchValueASCII(switches::kProcessType); | 568 command_line.GetSwitchValueASCII(switches::kProcessType); |
| 527 | 569 |
| 570 // TODO(shess): Could this be registered earlier? | |
| 571 if (process_type.empty()) | |
| 572 content::debug::RegisterMessageHandlers(RecordMsg, GetMessages); | |
| 573 | |
| 528 chrome::RegisterPathProvider(); | 574 chrome::RegisterPathProvider(); |
| 529 | 575 |
| 530 #if defined(OS_MACOSX) | 576 #if defined(OS_MACOSX) |
| 531 // On the Mac, the child executable lives at a predefined location within | 577 // On the Mac, the child executable lives at a predefined location within |
| 532 // the app bundle's versioned directory. | 578 // the app bundle's versioned directory. |
| 533 PathService::Override(content::CHILD_PROCESS_EXE, | 579 PathService::Override(content::CHILD_PROCESS_EXE, |
| 534 chrome::GetVersionedDirectory(). | 580 chrome::GetVersionedDirectory(). |
| 535 Append(chrome::kHelperProcessExecutablePath)); | 581 Append(chrome::kHelperProcessExecutablePath)); |
| 536 | 582 |
| 537 InitMacCrashReporter(command_line, process_type); | 583 InitMacCrashReporter(command_line, process_type); |
| (...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 716 | 762 |
| 717 content::ContentRendererClient* | 763 content::ContentRendererClient* |
| 718 ChromeMainDelegate::CreateContentRendererClient() { | 764 ChromeMainDelegate::CreateContentRendererClient() { |
| 719 return &g_chrome_content_renderer_client.Get(); | 765 return &g_chrome_content_renderer_client.Get(); |
| 720 } | 766 } |
| 721 | 767 |
| 722 content::ContentUtilityClient* | 768 content::ContentUtilityClient* |
| 723 ChromeMainDelegate::CreateContentUtilityClient() { | 769 ChromeMainDelegate::CreateContentUtilityClient() { |
| 724 return &g_chrome_content_utility_client.Get(); | 770 return &g_chrome_content_utility_client.Get(); |
| 725 } | 771 } |
| OLD | NEW |