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/browser/chrome_browser_main.h" | 5 #include "chrome/browser/chrome_browser_main.h" |
6 | 6 |
7 #include <set> | 7 #include <set> |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
215 #if defined(USE_AURA) | 215 #if defined(USE_AURA) |
216 #include "ui/aura/env.h" | 216 #include "ui/aura/env.h" |
217 #endif | 217 #endif |
218 | 218 |
219 using content::BrowserThread; | 219 using content::BrowserThread; |
220 | 220 |
221 namespace { | 221 namespace { |
222 | 222 |
223 // This function provides some ways to test crash and assertion handling | 223 // This function provides some ways to test crash and assertion handling |
224 // behavior of the program. | 224 // behavior of the program. |
225 void HandleTestParameters(const CommandLine& command_line) { | 225 void HandleTestParameters(const base::CommandLine& command_line) { |
226 // This parameter causes an assertion. | 226 // This parameter causes an assertion. |
227 if (command_line.HasSwitch(switches::kBrowserAssertTest)) { | 227 if (command_line.HasSwitch(switches::kBrowserAssertTest)) { |
228 DCHECK(false); | 228 DCHECK(false); |
229 } | 229 } |
230 | 230 |
231 // This parameter causes a null pointer crash (crash reporter trigger). | 231 // This parameter causes a null pointer crash (crash reporter trigger). |
232 if (command_line.HasSwitch(switches::kBrowserCrashTest)) { | 232 if (command_line.HasSwitch(switches::kBrowserCrashTest)) { |
233 int* bad_pointer = NULL; | 233 int* bad_pointer = NULL; |
234 *bad_pointer = 0; | 234 *bad_pointer = 0; |
235 } | 235 } |
236 } | 236 } |
237 | 237 |
238 #if !defined(OS_ANDROID) && !defined(OS_CHROMEOS) | 238 #if !defined(OS_ANDROID) && !defined(OS_CHROMEOS) |
239 void AddFirstRunNewTabs(StartupBrowserCreator* browser_creator, | 239 void AddFirstRunNewTabs(StartupBrowserCreator* browser_creator, |
240 const std::vector<GURL>& new_tabs) { | 240 const std::vector<GURL>& new_tabs) { |
241 for (std::vector<GURL>::const_iterator it = new_tabs.begin(); | 241 for (std::vector<GURL>::const_iterator it = new_tabs.begin(); |
242 it != new_tabs.end(); ++it) { | 242 it != new_tabs.end(); ++it) { |
243 if (it->is_valid()) | 243 if (it->is_valid()) |
244 browser_creator->AddFirstRunTab(*it); | 244 browser_creator->AddFirstRunTab(*it); |
245 } | 245 } |
246 } | 246 } |
247 #endif // !defined(OS_ANDROID) && !defined(OS_CHROMEOS) | 247 #endif // !defined(OS_ANDROID) && !defined(OS_CHROMEOS) |
248 | 248 |
249 // Returns the new local state object, guaranteed non-NULL. | 249 // Returns the new local state object, guaranteed non-NULL. |
250 // |local_state_task_runner| must be a shutdown-blocking task runner. | 250 // |local_state_task_runner| must be a shutdown-blocking task runner. |
251 PrefService* InitializeLocalState( | 251 PrefService* InitializeLocalState( |
252 base::SequencedTaskRunner* local_state_task_runner, | 252 base::SequencedTaskRunner* local_state_task_runner, |
253 const CommandLine& parsed_command_line) { | 253 const base::CommandLine& parsed_command_line) { |
254 TRACE_EVENT0("startup", "ChromeBrowserMainParts::InitializeLocalState") | 254 TRACE_EVENT0("startup", "ChromeBrowserMainParts::InitializeLocalState") |
255 base::FilePath local_state_path; | 255 base::FilePath local_state_path; |
256 PathService::Get(chrome::FILE_LOCAL_STATE, &local_state_path); | 256 PathService::Get(chrome::FILE_LOCAL_STATE, &local_state_path); |
257 bool local_state_file_exists = base::PathExists(local_state_path); | 257 bool local_state_file_exists = base::PathExists(local_state_path); |
258 | 258 |
259 // Load local state. This includes the application locale so we know which | 259 // Load local state. This includes the application locale so we know which |
260 // locale dll to load. This also causes local state prefs to be registered. | 260 // locale dll to load. This also causes local state prefs to be registered. |
261 PrefService* local_state = g_browser_process->local_state(); | 261 PrefService* local_state = g_browser_process->local_state(); |
262 DCHECK(local_state); | 262 DCHECK(local_state); |
263 | 263 |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
320 #endif | 320 #endif |
321 | 321 |
322 return local_state; | 322 return local_state; |
323 } | 323 } |
324 | 324 |
325 // Initializes the primary profile, possibly doing some user prompting to pick | 325 // Initializes the primary profile, possibly doing some user prompting to pick |
326 // a fallback profile. Returns the newly created profile, or NULL if startup | 326 // a fallback profile. Returns the newly created profile, or NULL if startup |
327 // should not continue. | 327 // should not continue. |
328 Profile* CreatePrimaryProfile(const content::MainFunctionParams& parameters, | 328 Profile* CreatePrimaryProfile(const content::MainFunctionParams& parameters, |
329 const base::FilePath& user_data_dir, | 329 const base::FilePath& user_data_dir, |
330 const CommandLine& parsed_command_line) { | 330 const base::CommandLine& parsed_command_line) { |
331 TRACE_EVENT0("startup", "ChromeBrowserMainParts::CreateProfile") | 331 TRACE_EVENT0("startup", "ChromeBrowserMainParts::CreateProfile") |
332 base::Time start = base::Time::Now(); | 332 base::Time start = base::Time::Now(); |
333 if (profiles::IsMultipleProfilesEnabled() && | 333 if (profiles::IsMultipleProfilesEnabled() && |
334 parsed_command_line.HasSwitch(switches::kProfileDirectory)) { | 334 parsed_command_line.HasSwitch(switches::kProfileDirectory)) { |
335 g_browser_process->local_state()->SetString(prefs::kProfileLastUsed, | 335 g_browser_process->local_state()->SetString(prefs::kProfileLastUsed, |
336 parsed_command_line.GetSwitchValueASCII(switches::kProfileDirectory)); | 336 parsed_command_line.GetSwitchValueASCII(switches::kProfileDirectory)); |
337 // Clear kProfilesLastActive since the user only wants to launch a specific | 337 // Clear kProfilesLastActive since the user only wants to launch a specific |
338 // profile. | 338 // profile. |
339 ListPrefUpdate update(g_browser_process->local_state(), | 339 ListPrefUpdate update(g_browser_process->local_state(), |
340 prefs::kProfilesLastActive); | 340 prefs::kProfilesLastActive); |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
448 | 448 |
449 #if defined(OS_WIN) | 449 #if defined(OS_WIN) |
450 RegisterSwReporterComponent(cus, g_browser_process->local_state()); | 450 RegisterSwReporterComponent(cus, g_browser_process->local_state()); |
451 #endif | 451 #endif |
452 | 452 |
453 cus->Start(); | 453 cus->Start(); |
454 } | 454 } |
455 | 455 |
456 #if !defined(OS_ANDROID) | 456 #if !defined(OS_ANDROID) |
457 bool ProcessSingletonNotificationCallback( | 457 bool ProcessSingletonNotificationCallback( |
458 const CommandLine& command_line, | 458 const base::CommandLine& command_line, |
459 const base::FilePath& current_directory) { | 459 const base::FilePath& current_directory) { |
460 // Drop the request if the browser process is already in shutdown path. | 460 // Drop the request if the browser process is already in shutdown path. |
461 if (!g_browser_process || g_browser_process->IsShuttingDown()) | 461 if (!g_browser_process || g_browser_process->IsShuttingDown()) |
462 return false; | 462 return false; |
463 | 463 |
464 if (command_line.HasSwitch(switches::kOriginalProcessStartTime)) { | 464 if (command_line.HasSwitch(switches::kOriginalProcessStartTime)) { |
465 std::string start_time_string = | 465 std::string start_time_string = |
466 command_line.GetSwitchValueASCII(switches::kOriginalProcessStartTime); | 466 command_line.GetSwitchValueASCII(switches::kOriginalProcessStartTime); |
467 int64 remote_start_time; | 467 int64 remote_start_time; |
468 if (base::StringToInt64(start_time_string, &remote_start_time)) { | 468 if (base::StringToInt64(start_time_string, &remote_start_time)) { |
(...skipping 16 matching lines...) Expand all Loading... |
485 g_browser_process->profile_manager()->user_data_dir(); | 485 g_browser_process->profile_manager()->user_data_dir(); |
486 base::FilePath startup_profile_dir = | 486 base::FilePath startup_profile_dir = |
487 GetStartupProfilePath(user_data_dir, command_line); | 487 GetStartupProfilePath(user_data_dir, command_line); |
488 | 488 |
489 StartupBrowserCreator::ProcessCommandLineAlreadyRunning( | 489 StartupBrowserCreator::ProcessCommandLineAlreadyRunning( |
490 command_line, current_directory, startup_profile_dir); | 490 command_line, current_directory, startup_profile_dir); |
491 return true; | 491 return true; |
492 } | 492 } |
493 #endif // !defined(OS_ANDROID) | 493 #endif // !defined(OS_ANDROID) |
494 | 494 |
495 void LaunchDevToolsHandlerIfNeeded(const CommandLine& command_line) { | 495 void LaunchDevToolsHandlerIfNeeded(const base::CommandLine& command_line) { |
496 if (command_line.HasSwitch(::switches::kRemoteDebuggingPort)) { | 496 if (command_line.HasSwitch(::switches::kRemoteDebuggingPort)) { |
497 std::string port_str = | 497 std::string port_str = |
498 command_line.GetSwitchValueASCII(::switches::kRemoteDebuggingPort); | 498 command_line.GetSwitchValueASCII(::switches::kRemoteDebuggingPort); |
499 int port; | 499 int port; |
500 if (base::StringToInt(port_str, &port) && port >= 0 && port < 65535) { | 500 if (base::StringToInt(port_str, &port) && port >= 0 && port < 65535) { |
501 g_browser_process->CreateDevToolsHttpProtocolHandler( | 501 g_browser_process->CreateDevToolsHttpProtocolHandler( |
502 chrome::HOST_DESKTOP_TYPE_NATIVE, | 502 chrome::HOST_DESKTOP_TYPE_NATIVE, |
503 "127.0.0.1", | 503 "127.0.0.1", |
504 static_cast<uint16>(port)); | 504 static_cast<uint16>(port)); |
505 } else { | 505 } else { |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
593 // Must initialize metrics after labs have been converted into switches, | 593 // Must initialize metrics after labs have been converted into switches, |
594 // but before field trials are set up (so that client ID is available for | 594 // but before field trials are set up (so that client ID is available for |
595 // one-time randomized field trials). | 595 // one-time randomized field trials). |
596 | 596 |
597 // Initialize FieldTrialList to support FieldTrials that use one-time | 597 // Initialize FieldTrialList to support FieldTrials that use one-time |
598 // randomization. | 598 // randomization. |
599 metrics::MetricsService* metrics = browser_process_->metrics_service(); | 599 metrics::MetricsService* metrics = browser_process_->metrics_service(); |
600 field_trial_list_.reset( | 600 field_trial_list_.reset( |
601 new base::FieldTrialList(metrics->CreateEntropyProvider().release())); | 601 new base::FieldTrialList(metrics->CreateEntropyProvider().release())); |
602 | 602 |
603 const CommandLine* command_line = CommandLine::ForCurrentProcess(); | 603 const base::CommandLine* command_line = |
| 604 base::CommandLine::ForCurrentProcess(); |
604 if (command_line->HasSwitch(switches::kEnableBenchmarking) || | 605 if (command_line->HasSwitch(switches::kEnableBenchmarking) || |
605 command_line->HasSwitch(cc::switches::kEnableGpuBenchmarking)) { | 606 command_line->HasSwitch(cc::switches::kEnableGpuBenchmarking)) { |
606 base::FieldTrial::EnableBenchmarking(); | 607 base::FieldTrial::EnableBenchmarking(); |
607 } | 608 } |
608 | 609 |
609 // Ensure any field trials specified on the command line are initialized. | 610 // Ensure any field trials specified on the command line are initialized. |
610 if (command_line->HasSwitch(switches::kForceFieldTrials)) { | 611 if (command_line->HasSwitch(switches::kForceFieldTrials)) { |
611 std::set<std::string> unforceable_field_trials; | 612 std::set<std::string> unforceable_field_trials; |
612 #if defined(OFFICIAL_BUILD) | 613 #if defined(OFFICIAL_BUILD) |
613 unforceable_field_trials.insert("SettingsEnforcement"); | 614 unforceable_field_trials.insert("SettingsEnforcement"); |
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
868 // ResourceBundle::InitSharedInstanceWithLocale as some loaded resources are | 869 // ResourceBundle::InitSharedInstanceWithLocale as some loaded resources are |
869 // affected by experiment flags (--touch-optimized-ui in particular). | 870 // affected by experiment flags (--touch-optimized-ui in particular). |
870 // On ChromeOS system level flags are applied from the device settings from | 871 // On ChromeOS system level flags are applied from the device settings from |
871 // the session manager. | 872 // the session manager. |
872 { | 873 { |
873 TRACE_EVENT0("startup", | 874 TRACE_EVENT0("startup", |
874 "ChromeBrowserMainParts::PreCreateThreadsImpl:ConvertFlags"); | 875 "ChromeBrowserMainParts::PreCreateThreadsImpl:ConvertFlags"); |
875 about_flags::PrefServiceFlagsStorage flags_storage_( | 876 about_flags::PrefServiceFlagsStorage flags_storage_( |
876 g_browser_process->local_state()); | 877 g_browser_process->local_state()); |
877 about_flags::ConvertFlagsToSwitches(&flags_storage_, | 878 about_flags::ConvertFlagsToSwitches(&flags_storage_, |
878 CommandLine::ForCurrentProcess(), | 879 base::CommandLine::ForCurrentProcess(), |
879 about_flags::kAddSentinels); | 880 about_flags::kAddSentinels); |
880 } | 881 } |
881 #endif | 882 #endif |
882 | 883 |
883 local_state_->UpdateCommandLinePrefStore( | 884 local_state_->UpdateCommandLinePrefStore( |
884 new CommandLinePrefStore(CommandLine::ForCurrentProcess())); | 885 new CommandLinePrefStore(base::CommandLine::ForCurrentProcess())); |
885 | 886 |
886 // Reset the command line in the crash report details, since we may have | 887 // Reset the command line in the crash report details, since we may have |
887 // just changed it to include experiments. | 888 // just changed it to include experiments. |
888 crash_keys::SetSwitchesFromCommandLine(CommandLine::ForCurrentProcess()); | 889 crash_keys::SetSwitchesFromCommandLine( |
| 890 base::CommandLine::ForCurrentProcess()); |
889 | 891 |
890 // Mac starts it earlier in |PreMainMessageLoopStart()| (because it is | 892 // Mac starts it earlier in |PreMainMessageLoopStart()| (because it is |
891 // needed when loading the MainMenu.nib and the language doesn't depend on | 893 // needed when loading the MainMenu.nib and the language doesn't depend on |
892 // anything since it comes from Cocoa. | 894 // anything since it comes from Cocoa. |
893 #if defined(OS_MACOSX) | 895 #if defined(OS_MACOSX) |
894 std::string locale = | 896 std::string locale = |
895 parameters().ui_task ? "en-US" : l10n_util::GetLocaleOverride(); | 897 parameters().ui_task ? "en-US" : l10n_util::GetLocaleOverride(); |
896 browser_process_->SetApplicationLocale(locale); | 898 browser_process_->SetApplicationLocale(locale); |
897 #else | 899 #else |
898 const std::string locale = | 900 const std::string locale = |
(...skipping 824 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1723 chromeos::CrosSettings::Shutdown(); | 1725 chromeos::CrosSettings::Shutdown(); |
1724 #endif | 1726 #endif |
1725 #endif | 1727 #endif |
1726 } | 1728 } |
1727 | 1729 |
1728 // Public members: | 1730 // Public members: |
1729 | 1731 |
1730 void ChromeBrowserMainParts::AddParts(ChromeBrowserMainExtraParts* parts) { | 1732 void ChromeBrowserMainParts::AddParts(ChromeBrowserMainExtraParts* parts) { |
1731 chrome_extra_parts_.push_back(parts); | 1733 chrome_extra_parts_.push_back(parts); |
1732 } | 1734 } |
OLD | NEW |