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 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
238 | 238 |
239 // TODO(abarth): Should this move to InitializeNetworkOptions? This doesn't | 239 // TODO(abarth): Should this move to InitializeNetworkOptions? This doesn't |
240 // seem dependent on InitializeSSL(). | 240 // seem dependent on InitializeSSL(). |
241 if (parsed_command_line().HasSwitch(switches::kEnableTcpFastOpen)) | 241 if (parsed_command_line().HasSwitch(switches::kEnableTcpFastOpen)) |
242 net::set_tcp_fastopen_enabled(true); | 242 net::set_tcp_fastopen_enabled(true); |
243 | 243 |
244 PostEarlyInitialization(); | 244 PostEarlyInitialization(); |
245 } | 245 } |
246 | 246 |
247 // This will be called after the command-line has been mutated by about:flags | 247 // This will be called after the command-line has been mutated by about:flags |
248 void BrowserMainParts::SetupFieldTrials() { | 248 MetricsService* BrowserMainParts::SetupMetricsAndFieldTrials( |
249 // Note: make sure to call ConnectionFieldTrial() before | 249 const CommandLine& parsed_command_line, |
250 // ProxyConnectionsFieldTrial(). | 250 PrefService* local_state) { |
251 ConnectionFieldTrial(); | 251 // Must initialize metrics after labs have been converted into switches, |
252 SocketTimeoutFieldTrial(); | 252 // but before field trials are set up (so that client ID is available for |
253 ProxyConnectionsFieldTrial(); | 253 // one-time randomized field trials). |
254 prerender::ConfigurePrefetchAndPrerender(parsed_command_line()); | 254 MetricsService* metrics = InitializeMetrics(parsed_command_line, local_state); |
255 SpdyFieldTrial(); | 255 |
256 ConnectBackupJobsFieldTrial(); | 256 // Initialize FieldTrialList to support FieldTrials that use one-time |
257 SSLFalseStartFieldTrial(); | 257 // randomization. The client ID will be empty if the user has not opted |
| 258 // to send metrics. |
| 259 field_trial_list_.reset(new base::FieldTrialList(metrics->GetClientId())); |
| 260 |
| 261 SetupFieldTrials(metrics->recording_active()); |
| 262 |
| 263 // Initialize FieldTrialSynchronizer system. This is a singleton and is used |
| 264 // for posting tasks via NewRunnableMethod. Its deleted when it goes out of |
| 265 // scope. Even though NewRunnableMethod does AddRef and Release, the object |
| 266 // will not be deleted after the Task is executed. |
| 267 field_trial_synchronizer_ = new FieldTrialSynchronizer(); |
| 268 |
| 269 return metrics; |
258 } | 270 } |
259 | 271 |
260 // This is an A/B test for the maximum number of persistent connections per | 272 // This is an A/B test for the maximum number of persistent connections per |
261 // host. Currently Chrome, Firefox, and IE8 have this value set at 6. Safari | 273 // host. Currently Chrome, Firefox, and IE8 have this value set at 6. Safari |
262 // uses 4, and Fasterfox (a plugin for Firefox that supposedly configures it to | 274 // uses 4, and Fasterfox (a plugin for Firefox that supposedly configures it to |
263 // run faster) uses 8. We would like to see how much of an effect this value has | 275 // run faster) uses 8. We would like to see how much of an effect this value has |
264 // on browsing. Too large a value might cause us to run into SYN flood detection | 276 // on browsing. Too large a value might cause us to run into SYN flood detection |
265 // mechanisms. | 277 // mechanisms. |
266 void BrowserMainParts::ConnectionFieldTrial() { | 278 void BrowserMainParts::ConnectionFieldTrial() { |
267 const base::FieldTrial::Probability kConnectDivisor = 100; | 279 const base::FieldTrial::Probability kConnectDivisor = 100; |
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
530 void BrowserMainParts::InitializeMainThread() { | 542 void BrowserMainParts::InitializeMainThread() { |
531 const char* kThreadName = "CrBrowserMain"; | 543 const char* kThreadName = "CrBrowserMain"; |
532 base::PlatformThread::SetName(kThreadName); | 544 base::PlatformThread::SetName(kThreadName); |
533 main_message_loop().set_thread_name(kThreadName); | 545 main_message_loop().set_thread_name(kThreadName); |
534 | 546 |
535 // Register the main thread by instantiating it, but don't call any methods. | 547 // Register the main thread by instantiating it, but don't call any methods. |
536 main_thread_.reset(new BrowserThread(BrowserThread::UI, | 548 main_thread_.reset(new BrowserThread(BrowserThread::UI, |
537 MessageLoop::current())); | 549 MessageLoop::current())); |
538 } | 550 } |
539 | 551 |
| 552 // BrowserMainParts: |SetupMetricsAndFieldTrials()| related -------------------- |
| 553 |
| 554 // Initializes the metrics service with the configuration for this process, |
| 555 // returning the created service (guaranteed non-NULL). |
| 556 MetricsService* BrowserMainParts::InitializeMetrics( |
| 557 const CommandLine& parsed_command_line, |
| 558 const PrefService* local_state) { |
| 559 #if defined(OS_WIN) |
| 560 if (parsed_command_line.HasSwitch(switches::kChromeFrame)) |
| 561 MetricsLog::set_version_extension("-F"); |
| 562 #elif defined(ARCH_CPU_64_BITS) |
| 563 MetricsLog::set_version_extension("-64"); |
| 564 #endif // defined(OS_WIN) |
| 565 |
| 566 MetricsService* metrics = g_browser_process->metrics_service(); |
| 567 |
| 568 if (parsed_command_line.HasSwitch(switches::kMetricsRecordingOnly) || |
| 569 parsed_command_line.HasSwitch(switches::kEnableBenchmarking)) { |
| 570 // If we're testing then we don't care what the user preference is, we turn |
| 571 // on recording, but not reporting, otherwise tests fail. |
| 572 metrics->StartRecordingOnly(); |
| 573 return metrics; |
| 574 } |
| 575 |
| 576 // If the user permits metrics reporting with the checkbox in the |
| 577 // prefs, we turn on recording. We disable metrics completely for |
| 578 // non-official builds. |
| 579 #if defined(GOOGLE_CHROME_BUILD) |
| 580 #if defined(OS_CHROMEOS) |
| 581 bool enabled = chromeos::MetricsCrosSettingsProvider::GetMetricsStatus(); |
| 582 #else |
| 583 bool enabled = local_state->GetBoolean(prefs::kMetricsReportingEnabled); |
| 584 #endif // #if defined(OS_CHROMEOS) |
| 585 if (enabled) { |
| 586 metrics->Start(); |
| 587 } |
| 588 #endif // defined(GOOGLE_CHROME_BUILD) |
| 589 |
| 590 return metrics; |
| 591 } |
| 592 |
| 593 void BrowserMainParts::SetupFieldTrials(bool metrics_recording_enabled) { |
| 594 if (metrics_recording_enabled) |
| 595 chrome_browser_net_websocket_experiment::WebSocketExperimentRunner::Start(); |
| 596 |
| 597 // Note: make sure to call ConnectionFieldTrial() before |
| 598 // ProxyConnectionsFieldTrial(). |
| 599 ConnectionFieldTrial(); |
| 600 SocketTimeoutFieldTrial(); |
| 601 ProxyConnectionsFieldTrial(); |
| 602 prerender::ConfigurePrefetchAndPrerender(parsed_command_line()); |
| 603 SpdyFieldTrial(); |
| 604 ConnectBackupJobsFieldTrial(); |
| 605 SSLFalseStartFieldTrial(); |
| 606 } |
| 607 |
540 // ----------------------------------------------------------------------------- | 608 // ----------------------------------------------------------------------------- |
541 // TODO(viettrungluu): move more/rest of BrowserMain() into above structure | 609 // TODO(viettrungluu): move more/rest of BrowserMain() into above structure |
542 | 610 |
543 namespace { | 611 namespace { |
544 | 612 |
545 // This function provides some ways to test crash and assertion handling | 613 // This function provides some ways to test crash and assertion handling |
546 // behavior of the program. | 614 // behavior of the program. |
547 void HandleTestParameters(const CommandLine& command_line) { | 615 void HandleTestParameters(const CommandLine& command_line) { |
548 // This parameter causes an assertion. | 616 // This parameter causes an assertion. |
549 if (command_line.HasSwitch(switches::kBrowserAssertTest)) { | 617 if (command_line.HasSwitch(switches::kBrowserAssertTest)) { |
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
761 // Precreate the desktop and window station used by the renderers. | 829 // Precreate the desktop and window station used by the renderers. |
762 sandbox::TargetPolicy* policy = broker_services->CreatePolicy(); | 830 sandbox::TargetPolicy* policy = broker_services->CreatePolicy(); |
763 sandbox::ResultCode result = policy->CreateAlternateDesktop(use_winsta); | 831 sandbox::ResultCode result = policy->CreateAlternateDesktop(use_winsta); |
764 CHECK(sandbox::SBOX_ERROR_FAILED_TO_SWITCH_BACK_WINSTATION != result); | 832 CHECK(sandbox::SBOX_ERROR_FAILED_TO_SWITCH_BACK_WINSTATION != result); |
765 policy->Release(); | 833 policy->Release(); |
766 } | 834 } |
767 } | 835 } |
768 #endif | 836 #endif |
769 } | 837 } |
770 | 838 |
771 // Initializes the metrics service with the configuration for this process, | |
772 // returning the created service (guaranteed non-NULL). | |
773 MetricsService* InitializeMetrics(const CommandLine& parsed_command_line, | |
774 const PrefService* local_state) { | |
775 #if defined(OS_WIN) | |
776 if (parsed_command_line.HasSwitch(switches::kChromeFrame)) | |
777 MetricsLog::set_version_extension("-F"); | |
778 #elif defined(ARCH_CPU_64_BITS) | |
779 MetricsLog::set_version_extension("-64"); | |
780 #endif // defined(OS_WIN) | |
781 | |
782 MetricsService* metrics = g_browser_process->metrics_service(); | |
783 | |
784 if (parsed_command_line.HasSwitch(switches::kMetricsRecordingOnly) || | |
785 parsed_command_line.HasSwitch(switches::kEnableBenchmarking)) { | |
786 // If we're testing then we don't care what the user preference is, we turn | |
787 // on recording, but not reporting, otherwise tests fail. | |
788 metrics->StartRecordingOnly(); | |
789 } else { | |
790 // If the user permits metrics reporting with the checkbox in the | |
791 // prefs, we turn on recording. We disable metrics completely for | |
792 // non-official builds. | |
793 #if defined(GOOGLE_CHROME_BUILD) | |
794 #if defined(OS_CHROMEOS) | |
795 bool enabled = chromeos::MetricsCrosSettingsProvider::GetMetricsStatus(); | |
796 #else | |
797 bool enabled = local_state->GetBoolean(prefs::kMetricsReportingEnabled); | |
798 #endif // #if defined(OS_CHROMEOS) | |
799 if (enabled) { | |
800 metrics->Start(); | |
801 chrome_browser_net_websocket_experiment:: | |
802 WebSocketExperimentRunner::Start(); | |
803 } | |
804 #endif | |
805 } | |
806 | |
807 return metrics; | |
808 } | |
809 | |
810 // Initializes the profile, possibly doing some user prompting to pick a | 839 // Initializes the profile, possibly doing some user prompting to pick a |
811 // fallback profile. Returns the newly created profile, or NULL if startup | 840 // fallback profile. Returns the newly created profile, or NULL if startup |
812 // should not continue. | 841 // should not continue. |
813 Profile* CreateProfile(const MainFunctionParams& parameters, | 842 Profile* CreateProfile(const MainFunctionParams& parameters, |
814 const FilePath& user_data_dir) { | 843 const FilePath& user_data_dir) { |
815 const CommandLine& browser_command_line = *CommandLine::ForCurrentProcess(); | 844 const CommandLine& browser_command_line = *CommandLine::ForCurrentProcess(); |
816 Profile* profile = browser_command_line.HasSwitch(switches::kMultiProfiles) ? | 845 Profile* profile = browser_command_line.HasSwitch(switches::kMultiProfiles) ? |
817 g_browser_process->profile_manager()->GetLastUsedProfile(user_data_dir) : | 846 g_browser_process->profile_manager()->GetLastUsedProfile(user_data_dir) : |
818 g_browser_process->profile_manager()->GetDefaultProfile(user_data_dir); | 847 g_browser_process->profile_manager()->GetDefaultProfile(user_data_dir); |
819 if (profile) | 848 if (profile) |
(...skipping 537 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1357 | 1386 |
1358 // Initialize thread watcher system. This is a singleton and is used by | 1387 // Initialize thread watcher system. This is a singleton and is used by |
1359 // WatchDogThread to keep track of information about threads that are being | 1388 // WatchDogThread to keep track of information about threads that are being |
1360 // watched. | 1389 // watched. |
1361 scoped_ptr<ThreadWatcherList> thread_watcher_list(new ThreadWatcherList()); | 1390 scoped_ptr<ThreadWatcherList> thread_watcher_list(new ThreadWatcherList()); |
1362 | 1391 |
1363 // Convert active labs into switches. Modifies the current command line. | 1392 // Convert active labs into switches. Modifies the current command line. |
1364 about_flags::ConvertFlagsToSwitches(local_state, | 1393 about_flags::ConvertFlagsToSwitches(local_state, |
1365 CommandLine::ForCurrentProcess()); | 1394 CommandLine::ForCurrentProcess()); |
1366 | 1395 |
1367 // Now the command line has been mutated based on about:flags, we can run some | 1396 // Now the command line has been mutated based on about:flags, we can |
1368 // field trials | 1397 // set up metrics and initialize field trials. |
1369 parts->SetupFieldTrials(); | 1398 MetricsService* metrics = parts->SetupMetricsAndFieldTrials( |
1370 | 1399 parsed_command_line, local_state); |
1371 // Initialize FieldTrialSynchronizer system. This is a singleton and is used | |
1372 // for posting tasks via NewRunnableMethod. Its deleted when it goes out of | |
1373 // scope. Even though NewRunnableMethod does AddRef and Release, the object | |
1374 // will not be deleted after the Task is executed. | |
1375 scoped_refptr<FieldTrialSynchronizer> field_trial_synchronizer( | |
1376 new FieldTrialSynchronizer()); | |
1377 | 1400 |
1378 // Now that all preferences have been registered, set the install date | 1401 // Now that all preferences have been registered, set the install date |
1379 // for the uninstall metrics if this is our first run. This only actually | 1402 // for the uninstall metrics if this is our first run. This only actually |
1380 // gets used if the user has metrics reporting enabled at uninstall time. | 1403 // gets used if the user has metrics reporting enabled at uninstall time. |
1381 int64 install_date = | 1404 int64 install_date = |
1382 local_state->GetInt64(prefs::kUninstallMetricsInstallDate); | 1405 local_state->GetInt64(prefs::kUninstallMetricsInstallDate); |
1383 if (install_date == 0) { | 1406 if (install_date == 0) { |
1384 local_state->SetInt64(prefs::kUninstallMetricsInstallDate, | 1407 local_state->SetInt64(prefs::kUninstallMetricsInstallDate, |
1385 base::Time::Now().ToTimeT()); | 1408 base::Time::Now().ToTimeT()); |
1386 } | 1409 } |
(...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1710 sdch_trial->AppendGroup("global_disable_sdch", | 1733 sdch_trial->AppendGroup("global_disable_sdch", |
1711 kSDCH_DISABLE_PROBABILITY); | 1734 kSDCH_DISABLE_PROBABILITY); |
1712 if (sdch_enabled != sdch_trial->group()) | 1735 if (sdch_enabled != sdch_trial->group()) |
1713 sdch_supported_domain = "never_enabled_sdch_for_any_domain"; | 1736 sdch_supported_domain = "never_enabled_sdch_for_any_domain"; |
1714 } | 1737 } |
1715 | 1738 |
1716 net::SdchManager sdch_manager; // Singleton database. | 1739 net::SdchManager sdch_manager; // Singleton database. |
1717 sdch_manager.set_sdch_fetcher(new SdchDictionaryFetcher); | 1740 sdch_manager.set_sdch_fetcher(new SdchDictionaryFetcher); |
1718 sdch_manager.EnableSdchSupport(sdch_supported_domain); | 1741 sdch_manager.EnableSdchSupport(sdch_supported_domain); |
1719 | 1742 |
1720 MetricsService* metrics = InitializeMetrics(parsed_command_line, local_state); | |
1721 InstallJankometer(parsed_command_line); | 1743 InstallJankometer(parsed_command_line); |
1722 | 1744 |
1723 #if defined(OS_WIN) && !defined(GOOGLE_CHROME_BUILD) | 1745 #if defined(OS_WIN) && !defined(GOOGLE_CHROME_BUILD) |
1724 if (parsed_command_line.HasSwitch(switches::kDebugPrint)) { | 1746 if (parsed_command_line.HasSwitch(switches::kDebugPrint)) { |
1725 FilePath path = | 1747 FilePath path = |
1726 parsed_command_line.GetSwitchValuePath(switches::kDebugPrint); | 1748 parsed_command_line.GetSwitchValuePath(switches::kDebugPrint); |
1727 printing::PrintedDocument::set_debug_dump_path(path); | 1749 printing::PrintedDocument::set_debug_dump_path(path); |
1728 } | 1750 } |
1729 #endif | 1751 #endif |
1730 | 1752 |
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1940 #if defined(OS_CHROMEOS) | 1962 #if defined(OS_CHROMEOS) |
1941 // To be precise, logout (browser shutdown) is not yet done, but the | 1963 // To be precise, logout (browser shutdown) is not yet done, but the |
1942 // remaining work is negligible, hence we say LogoutDone here. | 1964 // remaining work is negligible, hence we say LogoutDone here. |
1943 chromeos::BootTimesLoader::Get()->AddLogoutTimeMarker("LogoutDone", | 1965 chromeos::BootTimesLoader::Get()->AddLogoutTimeMarker("LogoutDone", |
1944 false); | 1966 false); |
1945 chromeos::BootTimesLoader::Get()->WriteLogoutTimes(); | 1967 chromeos::BootTimesLoader::Get()->WriteLogoutTimes(); |
1946 #endif | 1968 #endif |
1947 TRACE_EVENT_END_ETW("BrowserMain", 0, 0); | 1969 TRACE_EVENT_END_ETW("BrowserMain", 0, 0); |
1948 return result_code; | 1970 return result_code; |
1949 } | 1971 } |
OLD | NEW |