OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/browser_main.h" | 5 #include "chrome/browser/browser_main.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
236 net::SSLConfigService::EnableDNSCertProvenanceChecking(); | 236 net::SSLConfigService::EnableDNSCertProvenanceChecking(); |
237 } | 237 } |
238 | 238 |
239 if (parsed_command_line().HasSwitch(switches::kEnableTcpFastOpen)) | 239 if (parsed_command_line().HasSwitch(switches::kEnableTcpFastOpen)) |
240 net::set_tcp_fastopen_enabled(true); | 240 net::set_tcp_fastopen_enabled(true); |
241 | 241 |
242 PostEarlyInitialization(); | 242 PostEarlyInitialization(); |
243 } | 243 } |
244 | 244 |
245 // This will be called after the command-line has been mutated by about:flags | 245 // This will be called after the command-line has been mutated by about:flags |
246 void BrowserMainParts::SetupFieldTrials() { | 246 MetricsService* BrowserMainParts::SetupMetricsAndFieldTrials( |
247 // Note: make sure to call ConnectionFieldTrial() before | 247 const CommandLine& parsed_command_line, |
248 // ProxyConnectionsFieldTrial(). | 248 PrefService* local_state) { |
249 ConnectionFieldTrial(); | 249 // Must initialize metrics after labs have been converted into switches, |
250 SocketTimeoutFieldTrial(); | 250 // but before field trials are set up (so that client ID is available for |
251 ProxyConnectionsFieldTrial(); | 251 // one-time randomized field trials). |
252 prerender::ConfigurePrefetchAndPrerender(parsed_command_line()); | 252 MetricsService* metrics = InitializeMetrics(parsed_command_line, local_state); |
253 SpdyFieldTrial(); | 253 |
254 ConnectBackupJobsFieldTrial(); | 254 // Initialize FieldTrialList to support FieldTrials that use one-time |
255 SSLFalseStartFieldTrial(); | 255 // randomization. The client ID will be empty if the user has not opted |
256 // to send metrics. | |
257 field_trial_list_.reset(new base::FieldTrialList(metrics->GetClientId())); | |
258 | |
259 SetupFieldTrials(); | |
260 | |
261 // Initialize FieldTrialSynchronizer system. This is a singleton and is used | |
262 // for posting tasks via NewRunnableMethod. Its deleted when it goes out of | |
263 // scope. Even though NewRunnableMethod does AddRef and Release, the object | |
264 // will not be deleted after the Task is executed. | |
265 field_trial_synchronizer_ = new FieldTrialSynchronizer(); | |
266 | |
267 return metrics; | |
256 } | 268 } |
257 | 269 |
258 // This is an A/B test for the maximum number of persistent connections per | 270 // This is an A/B test for the maximum number of persistent connections per |
259 // host. Currently Chrome, Firefox, and IE8 have this value set at 6. Safari | 271 // host. Currently Chrome, Firefox, and IE8 have this value set at 6. Safari |
260 // uses 4, and Fasterfox (a plugin for Firefox that supposedly configures it to | 272 // uses 4, and Fasterfox (a plugin for Firefox that supposedly configures it to |
261 // run faster) uses 8. We would like to see how much of an effect this value has | 273 // run faster) uses 8. We would like to see how much of an effect this value has |
262 // on browsing. Too large a value might cause us to run into SYN flood detection | 274 // on browsing. Too large a value might cause us to run into SYN flood detection |
263 // mechanisms. | 275 // mechanisms. |
264 void BrowserMainParts::ConnectionFieldTrial() { | 276 void BrowserMainParts::ConnectionFieldTrial() { |
265 const base::FieldTrial::Probability kConnectDivisor = 100; | 277 const base::FieldTrial::Probability kConnectDivisor = 100; |
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
528 void BrowserMainParts::InitializeMainThread() { | 540 void BrowserMainParts::InitializeMainThread() { |
529 const char* kThreadName = "CrBrowserMain"; | 541 const char* kThreadName = "CrBrowserMain"; |
530 base::PlatformThread::SetName(kThreadName); | 542 base::PlatformThread::SetName(kThreadName); |
531 main_message_loop().set_thread_name(kThreadName); | 543 main_message_loop().set_thread_name(kThreadName); |
532 | 544 |
533 // Register the main thread by instantiating it, but don't call any methods. | 545 // Register the main thread by instantiating it, but don't call any methods. |
534 main_thread_.reset(new BrowserThread(BrowserThread::UI, | 546 main_thread_.reset(new BrowserThread(BrowserThread::UI, |
535 MessageLoop::current())); | 547 MessageLoop::current())); |
536 } | 548 } |
537 | 549 |
550 // BrowserMainParts: |SetupMetricsAndFieldTrials()| related -------------------- | |
551 | |
552 // Initializes the metrics service with the configuration for this process, | |
553 // returning the created service (guaranteed non-NULL). | |
554 MetricsService* BrowserMainParts::InitializeMetrics( | |
555 const CommandLine& parsed_command_line, | |
556 const PrefService* local_state) { | |
557 #if defined(OS_WIN) | |
558 if (parsed_command_line.HasSwitch(switches::kChromeFrame)) | |
559 MetricsLog::set_version_extension("-F"); | |
560 #elif defined(ARCH_CPU_64_BITS) | |
561 MetricsLog::set_version_extension("-64"); | |
562 #endif // defined(OS_WIN) | |
563 | |
564 MetricsService* metrics = g_browser_process->metrics_service(); | |
565 | |
566 if (parsed_command_line.HasSwitch(switches::kMetricsRecordingOnly) || | |
567 parsed_command_line.HasSwitch(switches::kEnableBenchmarking)) { | |
568 // If we're testing then we don't care what the user preference is, we turn | |
569 // on recording, but not reporting, otherwise tests fail. | |
570 metrics->StartRecordingOnly(); | |
571 } else { | |
jar (doing other things)
2011/05/03 00:17:47
Please use an early return within the if block, an
Jói
2011/05/03 17:41:47
Done.
| |
572 // If the user permits metrics reporting with the checkbox in the | |
573 // prefs, we turn on recording. We disable metrics completely for | |
574 // non-official builds. | |
575 #if defined(GOOGLE_CHROME_BUILD) | |
jar (doing other things)
2011/05/03 00:17:47
I'm not sure if an early return works as well with
Jói
2011/05/03 17:41:47
After removing the else (previous comment) it seem
| |
576 #if defined(OS_CHROMEOS) | |
577 bool enabled = chromeos::MetricsCrosSettingsProvider::GetMetricsStatus(); | |
578 #else | |
579 bool enabled = local_state->GetBoolean(prefs::kMetricsReportingEnabled); | |
580 #endif // #if defined(OS_CHROMEOS) | |
581 if (enabled) { | |
582 metrics->Start(); | |
583 chrome_browser_net_websocket_experiment:: | |
584 WebSocketExperimentRunner::Start(); | |
585 } | |
586 #endif | |
587 } | |
588 | |
589 return metrics; | |
590 } | |
591 | |
592 void BrowserMainParts::SetupFieldTrials() { | |
593 // Note: make sure to call ConnectionFieldTrial() before | |
594 // ProxyConnectionsFieldTrial(). | |
595 ConnectionFieldTrial(); | |
596 SocketTimeoutFieldTrial(); | |
597 ProxyConnectionsFieldTrial(); | |
598 prerender::ConfigurePrefetchAndPrerender(parsed_command_line()); | |
599 SpdyFieldTrial(); | |
600 ConnectBackupJobsFieldTrial(); | |
601 SSLFalseStartFieldTrial(); | |
602 } | |
603 | |
538 // ----------------------------------------------------------------------------- | 604 // ----------------------------------------------------------------------------- |
539 // TODO(viettrungluu): move more/rest of BrowserMain() into above structure | 605 // TODO(viettrungluu): move more/rest of BrowserMain() into above structure |
540 | 606 |
541 namespace { | 607 namespace { |
542 | 608 |
543 // This function provides some ways to test crash and assertion handling | 609 // This function provides some ways to test crash and assertion handling |
544 // behavior of the program. | 610 // behavior of the program. |
545 void HandleTestParameters(const CommandLine& command_line) { | 611 void HandleTestParameters(const CommandLine& command_line) { |
546 // This parameter causes an assertion. | 612 // This parameter causes an assertion. |
547 if (command_line.HasSwitch(switches::kBrowserAssertTest)) { | 613 if (command_line.HasSwitch(switches::kBrowserAssertTest)) { |
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
756 // Precreate the desktop and window station used by the renderers. | 822 // Precreate the desktop and window station used by the renderers. |
757 sandbox::TargetPolicy* policy = broker_services->CreatePolicy(); | 823 sandbox::TargetPolicy* policy = broker_services->CreatePolicy(); |
758 sandbox::ResultCode result = policy->CreateAlternateDesktop(use_winsta); | 824 sandbox::ResultCode result = policy->CreateAlternateDesktop(use_winsta); |
759 CHECK(sandbox::SBOX_ERROR_FAILED_TO_SWITCH_BACK_WINSTATION != result); | 825 CHECK(sandbox::SBOX_ERROR_FAILED_TO_SWITCH_BACK_WINSTATION != result); |
760 policy->Release(); | 826 policy->Release(); |
761 } | 827 } |
762 } | 828 } |
763 #endif | 829 #endif |
764 } | 830 } |
765 | 831 |
766 // Initializes the metrics service with the configuration for this process, | |
767 // returning the created service (guaranteed non-NULL). | |
768 MetricsService* InitializeMetrics(const CommandLine& parsed_command_line, | |
769 const PrefService* local_state) { | |
770 #if defined(OS_WIN) | |
771 if (parsed_command_line.HasSwitch(switches::kChromeFrame)) | |
772 MetricsLog::set_version_extension("-F"); | |
773 #elif defined(ARCH_CPU_64_BITS) | |
774 MetricsLog::set_version_extension("-64"); | |
775 #endif // defined(OS_WIN) | |
776 | |
777 MetricsService* metrics = g_browser_process->metrics_service(); | |
778 | |
779 if (parsed_command_line.HasSwitch(switches::kMetricsRecordingOnly) || | |
780 parsed_command_line.HasSwitch(switches::kEnableBenchmarking)) { | |
781 // If we're testing then we don't care what the user preference is, we turn | |
782 // on recording, but not reporting, otherwise tests fail. | |
783 metrics->StartRecordingOnly(); | |
784 } else { | |
785 // If the user permits metrics reporting with the checkbox in the | |
786 // prefs, we turn on recording. We disable metrics completely for | |
787 // non-official builds. | |
788 #if defined(GOOGLE_CHROME_BUILD) | |
789 #if defined(OS_CHROMEOS) | |
790 bool enabled = chromeos::MetricsCrosSettingsProvider::GetMetricsStatus(); | |
791 #else | |
792 bool enabled = local_state->GetBoolean(prefs::kMetricsReportingEnabled); | |
793 #endif // #if defined(OS_CHROMEOS) | |
794 if (enabled) { | |
795 metrics->Start(); | |
796 chrome_browser_net_websocket_experiment:: | |
797 WebSocketExperimentRunner::Start(); | |
798 } | |
799 #endif | |
800 } | |
801 | |
802 return metrics; | |
803 } | |
804 | |
805 // Initializes the profile, possibly doing some user prompting to pick a | 832 // Initializes the profile, possibly doing some user prompting to pick a |
806 // fallback profile. Returns the newly created profile, or NULL if startup | 833 // fallback profile. Returns the newly created profile, or NULL if startup |
807 // should not continue. | 834 // should not continue. |
808 Profile* CreateProfile(const MainFunctionParams& parameters, | 835 Profile* CreateProfile(const MainFunctionParams& parameters, |
809 const FilePath& user_data_dir) { | 836 const FilePath& user_data_dir) { |
810 const CommandLine& browser_command_line = *CommandLine::ForCurrentProcess(); | 837 const CommandLine& browser_command_line = *CommandLine::ForCurrentProcess(); |
811 Profile* profile = browser_command_line.HasSwitch(switches::kMultiProfiles) ? | 838 Profile* profile = browser_command_line.HasSwitch(switches::kMultiProfiles) ? |
812 g_browser_process->profile_manager()->GetLastUsedProfile(user_data_dir) : | 839 g_browser_process->profile_manager()->GetLastUsedProfile(user_data_dir) : |
813 g_browser_process->profile_manager()->GetDefaultProfile(user_data_dir); | 840 g_browser_process->profile_manager()->GetDefaultProfile(user_data_dir); |
814 if (profile) | 841 if (profile) |
(...skipping 505 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1320 | 1347 |
1321 // Initialize thread watcher system. This is a singleton and is used by | 1348 // Initialize thread watcher system. This is a singleton and is used by |
1322 // WatchDogThread to keep track of information about threads that are being | 1349 // WatchDogThread to keep track of information about threads that are being |
1323 // watched. | 1350 // watched. |
1324 scoped_ptr<ThreadWatcherList> thread_watcher_list(new ThreadWatcherList()); | 1351 scoped_ptr<ThreadWatcherList> thread_watcher_list(new ThreadWatcherList()); |
1325 | 1352 |
1326 // Convert active labs into switches. Modifies the current command line. | 1353 // Convert active labs into switches. Modifies the current command line. |
1327 about_flags::ConvertFlagsToSwitches(local_state, | 1354 about_flags::ConvertFlagsToSwitches(local_state, |
1328 CommandLine::ForCurrentProcess()); | 1355 CommandLine::ForCurrentProcess()); |
1329 | 1356 |
1330 // Now the command line has been mutated based on about:flags, we can run some | 1357 // Now the command line has been mutated based on about:flags, we can |
1331 // field trials | 1358 // set up metrics and initialize field trials. |
1332 parts->SetupFieldTrials(); | 1359 MetricsService* metrics = parts->SetupMetricsAndFieldTrials( |
1333 | 1360 parsed_command_line, local_state); |
1334 // Initialize FieldTrialSynchronizer system. This is a singleton and is used | |
1335 // for posting tasks via NewRunnableMethod. Its deleted when it goes out of | |
1336 // scope. Even though NewRunnableMethod does AddRef and Release, the object | |
1337 // will not be deleted after the Task is executed. | |
1338 scoped_refptr<FieldTrialSynchronizer> field_trial_synchronizer( | |
1339 new FieldTrialSynchronizer()); | |
1340 | 1361 |
1341 // Now that all preferences have been registered, set the install date | 1362 // Now that all preferences have been registered, set the install date |
1342 // for the uninstall metrics if this is our first run. This only actually | 1363 // for the uninstall metrics if this is our first run. This only actually |
1343 // gets used if the user has metrics reporting enabled at uninstall time. | 1364 // gets used if the user has metrics reporting enabled at uninstall time. |
1344 int64 install_date = | 1365 int64 install_date = |
1345 local_state->GetInt64(prefs::kUninstallMetricsInstallDate); | 1366 local_state->GetInt64(prefs::kUninstallMetricsInstallDate); |
1346 if (install_date == 0) { | 1367 if (install_date == 0) { |
1347 local_state->SetInt64(prefs::kUninstallMetricsInstallDate, | 1368 local_state->SetInt64(prefs::kUninstallMetricsInstallDate, |
1348 base::Time::Now().ToTimeT()); | 1369 base::Time::Now().ToTimeT()); |
1349 } | 1370 } |
(...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1673 sdch_trial->AppendGroup("global_disable_sdch", | 1694 sdch_trial->AppendGroup("global_disable_sdch", |
1674 kSDCH_DISABLE_PROBABILITY); | 1695 kSDCH_DISABLE_PROBABILITY); |
1675 if (sdch_enabled != sdch_trial->group()) | 1696 if (sdch_enabled != sdch_trial->group()) |
1676 sdch_supported_domain = "never_enabled_sdch_for_any_domain"; | 1697 sdch_supported_domain = "never_enabled_sdch_for_any_domain"; |
1677 } | 1698 } |
1678 | 1699 |
1679 net::SdchManager sdch_manager; // Singleton database. | 1700 net::SdchManager sdch_manager; // Singleton database. |
1680 sdch_manager.set_sdch_fetcher(new SdchDictionaryFetcher); | 1701 sdch_manager.set_sdch_fetcher(new SdchDictionaryFetcher); |
1681 sdch_manager.EnableSdchSupport(sdch_supported_domain); | 1702 sdch_manager.EnableSdchSupport(sdch_supported_domain); |
1682 | 1703 |
1683 MetricsService* metrics = InitializeMetrics(parsed_command_line, local_state); | |
1684 InstallJankometer(parsed_command_line); | 1704 InstallJankometer(parsed_command_line); |
1685 | 1705 |
1686 #if defined(OS_WIN) && !defined(GOOGLE_CHROME_BUILD) | 1706 #if defined(OS_WIN) && !defined(GOOGLE_CHROME_BUILD) |
1687 if (parsed_command_line.HasSwitch(switches::kDebugPrint)) { | 1707 if (parsed_command_line.HasSwitch(switches::kDebugPrint)) { |
1688 FilePath path = | 1708 FilePath path = |
1689 parsed_command_line.GetSwitchValuePath(switches::kDebugPrint); | 1709 parsed_command_line.GetSwitchValuePath(switches::kDebugPrint); |
1690 printing::PrintedDocument::set_debug_dump_path(path); | 1710 printing::PrintedDocument::set_debug_dump_path(path); |
1691 } | 1711 } |
1692 #endif | 1712 #endif |
1693 | 1713 |
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1898 #if defined(OS_CHROMEOS) | 1918 #if defined(OS_CHROMEOS) |
1899 // To be precise, logout (browser shutdown) is not yet done, but the | 1919 // To be precise, logout (browser shutdown) is not yet done, but the |
1900 // remaining work is negligible, hence we say LogoutDone here. | 1920 // remaining work is negligible, hence we say LogoutDone here. |
1901 chromeos::BootTimesLoader::Get()->AddLogoutTimeMarker("LogoutDone", | 1921 chromeos::BootTimesLoader::Get()->AddLogoutTimeMarker("LogoutDone", |
1902 false); | 1922 false); |
1903 chromeos::BootTimesLoader::Get()->WriteLogoutTimes(); | 1923 chromeos::BootTimesLoader::Get()->WriteLogoutTimes(); |
1904 #endif | 1924 #endif |
1905 TRACE_EVENT_END("BrowserMain", 0, 0); | 1925 TRACE_EVENT_END("BrowserMain", 0, 0); |
1906 return result_code; | 1926 return result_code; |
1907 } | 1927 } |
OLD | NEW |