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/base_paths.h" | 7 #include "base/base_paths.h" |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/cpu.h" | 9 #include "base/cpu.h" |
10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
248 process_type == switches::kPpapiBrokerProcess || | 248 process_type == switches::kPpapiBrokerProcess || |
249 process_type == switches::kGpuProcess || | 249 process_type == switches::kGpuProcess || |
250 #endif | 250 #endif |
251 process_type == switches::kRendererProcess || | 251 process_type == switches::kRendererProcess || |
252 process_type == switches::kUtilityProcess; | 252 process_type == switches::kUtilityProcess; |
253 } | 253 } |
254 | 254 |
255 #if defined(OS_POSIX) | 255 #if defined(OS_POSIX) |
256 // Check for --version and --product-version; return true if we encountered | 256 // Check for --version and --product-version; return true if we encountered |
257 // one of these switches and should exit now. | 257 // one of these switches and should exit now. |
258 bool HandleVersionSwitches(const CommandLine& command_line) { | 258 bool HandleVersionSwitches(const base::CommandLine& command_line) { |
259 const chrome::VersionInfo version_info; | 259 const chrome::VersionInfo version_info; |
260 | 260 |
261 #if !defined(OS_MACOSX) | 261 #if !defined(OS_MACOSX) |
262 if (command_line.HasSwitch(switches::kProductVersion)) { | 262 if (command_line.HasSwitch(switches::kProductVersion)) { |
263 printf("%s\n", version_info.Version().c_str()); | 263 printf("%s\n", version_info.Version().c_str()); |
264 return true; | 264 return true; |
265 } | 265 } |
266 #endif | 266 #endif |
267 | 267 |
268 if (command_line.HasSwitch(switches::kVersion)) { | 268 if (command_line.HasSwitch(switches::kVersion)) { |
269 printf("%s %s %s\n", | 269 printf("%s %s %s\n", |
270 version_info.Name().c_str(), | 270 version_info.Name().c_str(), |
271 version_info.Version().c_str(), | 271 version_info.Version().c_str(), |
272 chrome::VersionInfo::GetVersionStringModifier().c_str()); | 272 chrome::VersionInfo::GetVersionStringModifier().c_str()); |
273 return true; | 273 return true; |
274 } | 274 } |
275 | 275 |
276 return false; | 276 return false; |
277 } | 277 } |
278 | 278 |
279 #if !defined(OS_MACOSX) && !defined(OS_CHROMEOS) | 279 #if !defined(OS_MACOSX) && !defined(OS_CHROMEOS) |
280 // Show the man page if --help or -h is on the command line. | 280 // Show the man page if --help or -h is on the command line. |
281 void HandleHelpSwitches(const CommandLine& command_line) { | 281 void HandleHelpSwitches(const base::CommandLine& command_line) { |
282 if (command_line.HasSwitch(switches::kHelp) || | 282 if (command_line.HasSwitch(switches::kHelp) || |
283 command_line.HasSwitch(switches::kHelpShort)) { | 283 command_line.HasSwitch(switches::kHelpShort)) { |
284 base::FilePath binary(command_line.argv()[0]); | 284 base::FilePath binary(command_line.argv()[0]); |
285 execlp("man", "man", binary.BaseName().value().c_str(), NULL); | 285 execlp("man", "man", binary.BaseName().value().c_str(), NULL); |
286 PLOG(FATAL) << "execlp failed"; | 286 PLOG(FATAL) << "execlp failed"; |
287 } | 287 } |
288 } | 288 } |
289 #endif | 289 #endif |
290 | 290 |
291 #if !defined(OS_MACOSX) && !defined(OS_ANDROID) | 291 #if !defined(OS_MACOSX) && !defined(OS_ANDROID) |
(...skipping 17 matching lines...) Expand all Loading... |
309 | 309 |
310 #endif // OS_POSIX | 310 #endif // OS_POSIX |
311 | 311 |
312 struct MainFunction { | 312 struct MainFunction { |
313 const char* name; | 313 const char* name; |
314 int (*function)(const content::MainFunctionParams&); | 314 int (*function)(const content::MainFunctionParams&); |
315 }; | 315 }; |
316 | 316 |
317 // Initializes the user data dir. Must be called before InitializeLocalState(). | 317 // Initializes the user data dir. Must be called before InitializeLocalState(). |
318 void InitializeUserDataDir() { | 318 void InitializeUserDataDir() { |
319 CommandLine* command_line = CommandLine::ForCurrentProcess(); | 319 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); |
320 base::FilePath user_data_dir = | 320 base::FilePath user_data_dir = |
321 command_line->GetSwitchValuePath(switches::kUserDataDir); | 321 command_line->GetSwitchValuePath(switches::kUserDataDir); |
322 std::string process_type = | 322 std::string process_type = |
323 command_line->GetSwitchValueASCII(switches::kProcessType); | 323 command_line->GetSwitchValueASCII(switches::kProcessType); |
324 | 324 |
325 #if defined(OS_LINUX) | 325 #if defined(OS_LINUX) |
326 // On Linux, Chrome does not support running multiple copies under different | 326 // On Linux, Chrome does not support running multiple copies under different |
327 // DISPLAYs, so the profile directory can be specified in the environment to | 327 // DISPLAYs, so the profile directory can be specified in the environment to |
328 // support the virtual desktop use-case. | 328 // support the virtual desktop use-case. |
329 if (user_data_dir.empty()) { | 329 if (user_data_dir.empty()) { |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
387 } | 387 } |
388 | 388 |
389 ChromeMainDelegate::~ChromeMainDelegate() { | 389 ChromeMainDelegate::~ChromeMainDelegate() { |
390 } | 390 } |
391 | 391 |
392 bool ChromeMainDelegate::BasicStartupComplete(int* exit_code) { | 392 bool ChromeMainDelegate::BasicStartupComplete(int* exit_code) { |
393 #if defined(OS_CHROMEOS) | 393 #if defined(OS_CHROMEOS) |
394 chromeos::BootTimesLoader::Get()->SaveChromeMainStats(); | 394 chromeos::BootTimesLoader::Get()->SaveChromeMainStats(); |
395 #endif | 395 #endif |
396 | 396 |
397 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); | 397 const base::CommandLine& command_line = |
| 398 *base::CommandLine::ForCurrentProcess(); |
398 | 399 |
399 #if defined(OS_MACOSX) | 400 #if defined(OS_MACOSX) |
400 // Give the browser process a longer treadmill, since crashes | 401 // Give the browser process a longer treadmill, since crashes |
401 // there have more impact. | 402 // there have more impact. |
402 const bool is_browser = !command_line.HasSwitch(switches::kProcessType); | 403 const bool is_browser = !command_line.HasSwitch(switches::kProcessType); |
403 ObjcEvilDoers::ZombieEnable(true, is_browser ? 10000 : 1000); | 404 ObjcEvilDoers::ZombieEnable(true, is_browser ? 10000 : 1000); |
404 | 405 |
405 SetUpBundleOverrides(); | 406 SetUpBundleOverrides(); |
406 chrome::common::mac::EnableCFBundleBlocker(); | 407 chrome::common::mac::EnableCFBundleBlocker(); |
407 #endif | 408 #endif |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
489 // If we are recovering from a crash on ChromeOS, then we will do some | 490 // If we are recovering from a crash on ChromeOS, then we will do some |
490 // recovery using the diagnostics module, and then continue on. We fake up a | 491 // recovery using the diagnostics module, and then continue on. We fake up a |
491 // command line to tell it that we want it to recover, and to preserve the | 492 // command line to tell it that we want it to recover, and to preserve the |
492 // original command line. | 493 // original command line. |
493 if (command_line.HasSwitch(chromeos::switches::kLoginUser) || | 494 if (command_line.HasSwitch(chromeos::switches::kLoginUser) || |
494 command_line.HasSwitch(switches::kDiagnosticsRecovery)) { | 495 command_line.HasSwitch(switches::kDiagnosticsRecovery)) { |
495 // The statistics subsystem needs get initialized soon enough for the | 496 // The statistics subsystem needs get initialized soon enough for the |
496 // statistics to be collected. It's safe to call this more than once. | 497 // statistics to be collected. It's safe to call this more than once. |
497 base::StatisticsRecorder::Initialize(); | 498 base::StatisticsRecorder::Initialize(); |
498 | 499 |
499 CommandLine interim_command_line(command_line.GetProgram()); | 500 base::CommandLine interim_command_line(command_line.GetProgram()); |
500 const char* const kSwitchNames[] = {switches::kUserDataDir, }; | 501 const char* const kSwitchNames[] = {switches::kUserDataDir, }; |
501 interim_command_line.CopySwitchesFrom( | 502 interim_command_line.CopySwitchesFrom( |
502 command_line, kSwitchNames, arraysize(kSwitchNames)); | 503 command_line, kSwitchNames, arraysize(kSwitchNames)); |
503 interim_command_line.AppendSwitch(switches::kDiagnostics); | 504 interim_command_line.AppendSwitch(switches::kDiagnostics); |
504 interim_command_line.AppendSwitch(switches::kDiagnosticsRecovery); | 505 interim_command_line.AppendSwitch(switches::kDiagnosticsRecovery); |
505 | 506 |
506 diagnostics::DiagnosticsWriter::FormatType format = | 507 diagnostics::DiagnosticsWriter::FormatType format = |
507 diagnostics::DiagnosticsWriter::LOG; | 508 diagnostics::DiagnosticsWriter::LOG; |
508 if (command_line.HasSwitch(switches::kDiagnosticsFormat)) { | 509 if (command_line.HasSwitch(switches::kDiagnosticsFormat)) { |
509 std::string format_str = | 510 std::string format_str = |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
638 process_type.empty()) | 639 process_type.empty()) |
639 << "Main application forbids --type, saw " << process_type; | 640 << "Main application forbids --type, saw " << process_type; |
640 } | 641 } |
641 | 642 |
642 if (breakpad::IsCrashReporterEnabled()) | 643 if (breakpad::IsCrashReporterEnabled()) |
643 breakpad::InitCrashProcessInfo(process_type); | 644 breakpad::InitCrashProcessInfo(process_type); |
644 } | 645 } |
645 #endif // defined(OS_MACOSX) | 646 #endif // defined(OS_MACOSX) |
646 | 647 |
647 void ChromeMainDelegate::PreSandboxStartup() { | 648 void ChromeMainDelegate::PreSandboxStartup() { |
648 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); | 649 const base::CommandLine& command_line = |
| 650 *base::CommandLine::ForCurrentProcess(); |
649 std::string process_type = | 651 std::string process_type = |
650 command_line.GetSwitchValueASCII(switches::kProcessType); | 652 command_line.GetSwitchValueASCII(switches::kProcessType); |
651 | 653 |
652 #if defined(OS_POSIX) | 654 #if defined(OS_POSIX) |
653 crash_reporter::SetCrashReporterClient(g_chrome_crash_client.Pointer()); | 655 crash_reporter::SetCrashReporterClient(g_chrome_crash_client.Pointer()); |
654 #endif | 656 #endif |
655 | 657 |
656 #if defined(OS_MACOSX) | 658 #if defined(OS_MACOSX) |
657 // On the Mac, the child executable lives at a predefined location within | 659 // On the Mac, the child executable lives at a predefined location within |
658 // the app bundle's versioned directory. | 660 // the app bundle's versioned directory. |
(...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
909 | 911 |
910 void ChromeMainDelegate::ZygoteForked() { | 912 void ChromeMainDelegate::ZygoteForked() { |
911 Profiling::ProcessStarted(); | 913 Profiling::ProcessStarted(); |
912 if (Profiling::BeingProfiled()) { | 914 if (Profiling::BeingProfiled()) { |
913 base::debug::RestartProfilingAfterFork(); | 915 base::debug::RestartProfilingAfterFork(); |
914 SetUpProfilingShutdownHandler(); | 916 SetUpProfilingShutdownHandler(); |
915 } | 917 } |
916 | 918 |
917 // Needs to be called after we have chrome::DIR_USER_DATA. BrowserMain sets | 919 // Needs to be called after we have chrome::DIR_USER_DATA. BrowserMain sets |
918 // this up for the browser process in a different manner. | 920 // this up for the browser process in a different manner. |
919 const CommandLine* command_line = CommandLine::ForCurrentProcess(); | 921 const base::CommandLine* command_line = |
| 922 base::CommandLine::ForCurrentProcess(); |
920 std::string process_type = | 923 std::string process_type = |
921 command_line->GetSwitchValueASCII(switches::kProcessType); | 924 command_line->GetSwitchValueASCII(switches::kProcessType); |
922 breakpad::InitCrashReporter(process_type); | 925 breakpad::InitCrashReporter(process_type); |
923 | 926 |
924 // Reset the command line for the newly spawned process. | 927 // Reset the command line for the newly spawned process. |
925 crash_keys::SetSwitchesFromCommandLine(command_line); | 928 crash_keys::SetSwitchesFromCommandLine(command_line); |
926 } | 929 } |
927 | 930 |
928 #endif // OS_MACOSX | 931 #endif // OS_MACOSX |
929 | 932 |
(...skipping 30 matching lines...) Expand all Loading... |
960 } | 963 } |
961 | 964 |
962 content::ContentUtilityClient* | 965 content::ContentUtilityClient* |
963 ChromeMainDelegate::CreateContentUtilityClient() { | 966 ChromeMainDelegate::CreateContentUtilityClient() { |
964 #if defined(CHROME_MULTIPLE_DLL_BROWSER) | 967 #if defined(CHROME_MULTIPLE_DLL_BROWSER) |
965 return NULL; | 968 return NULL; |
966 #else | 969 #else |
967 return g_chrome_content_utility_client.Pointer(); | 970 return g_chrome_content_utility_client.Pointer(); |
968 #endif | 971 #endif |
969 } | 972 } |
OLD | NEW |