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 MetricsService* BrowserMainParts::SetupMetricsAndFieldTrials( | 246 void BrowserMainParts::SetupFieldTrials() { |
247 const CommandLine& parsed_command_line, | 247 // Note: make sure to call ConnectionFieldTrial() before |
248 PrefService* local_state) { | 248 // ProxyConnectionsFieldTrial(). |
249 // Must initialize metrics after labs have been converted into switches, | 249 ConnectionFieldTrial(); |
250 // but before field trials are set up (so that client ID is available for | 250 SocketTimeoutFieldTrial(); |
251 // one-time randomized field trials). | 251 ProxyConnectionsFieldTrial(); |
252 MetricsService* metrics = InitializeMetrics(parsed_command_line, local_state); | 252 prerender::ConfigurePrefetchAndPrerender(parsed_command_line()); |
253 | 253 SpdyFieldTrial(); |
254 // Initialize FieldTrialList to support FieldTrials that use one-time | 254 ConnectBackupJobsFieldTrial(); |
255 // randomization. The client ID will be empty if the user has not opted | 255 SSLFalseStartFieldTrial(); |
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; | |
268 } | 256 } |
269 | 257 |
270 // This is an A/B test for the maximum number of persistent connections per | 258 // This is an A/B test for the maximum number of persistent connections per |
271 // host. Currently Chrome, Firefox, and IE8 have this value set at 6. Safari | 259 // host. Currently Chrome, Firefox, and IE8 have this value set at 6. Safari |
272 // uses 4, and Fasterfox (a plugin for Firefox that supposedly configures it to | 260 // uses 4, and Fasterfox (a plugin for Firefox that supposedly configures it to |
273 // run faster) uses 8. We would like to see how much of an effect this value has | 261 // run faster) uses 8. We would like to see how much of an effect this value has |
274 // on browsing. Too large a value might cause us to run into SYN flood detection | 262 // on browsing. Too large a value might cause us to run into SYN flood detection |
275 // mechanisms. | 263 // mechanisms. |
276 void BrowserMainParts::ConnectionFieldTrial() { | 264 void BrowserMainParts::ConnectionFieldTrial() { |
277 const base::FieldTrial::Probability kConnectDivisor = 100; | 265 const base::FieldTrial::Probability kConnectDivisor = 100; |
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
540 void BrowserMainParts::InitializeMainThread() { | 528 void BrowserMainParts::InitializeMainThread() { |
541 const char* kThreadName = "CrBrowserMain"; | 529 const char* kThreadName = "CrBrowserMain"; |
542 base::PlatformThread::SetName(kThreadName); | 530 base::PlatformThread::SetName(kThreadName); |
543 main_message_loop().set_thread_name(kThreadName); | 531 main_message_loop().set_thread_name(kThreadName); |
544 | 532 |
545 // Register the main thread by instantiating it, but don't call any methods. | 533 // Register the main thread by instantiating it, but don't call any methods. |
546 main_thread_.reset(new BrowserThread(BrowserThread::UI, | 534 main_thread_.reset(new BrowserThread(BrowserThread::UI, |
547 MessageLoop::current())); | 535 MessageLoop::current())); |
548 } | 536 } |
549 | 537 |
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 return metrics; | |
572 } | |
573 | |
574 // If the user permits metrics reporting with the checkbox in the | |
575 // prefs, we turn on recording. We disable metrics completely for | |
576 // non-official builds. | |
577 #if defined(GOOGLE_CHROME_BUILD) | |
578 #if defined(OS_CHROMEOS) | |
579 bool enabled = chromeos::MetricsCrosSettingsProvider::GetMetricsStatus(); | |
580 #else | |
581 bool enabled = local_state->GetBoolean(prefs::kMetricsReportingEnabled); | |
582 #endif // #if defined(OS_CHROMEOS) | |
583 if (enabled) { | |
584 metrics->Start(); | |
585 chrome_browser_net_websocket_experiment:: | |
586 WebSocketExperimentRunner::Start(); | |
587 } | |
588 #endif // defined(GOOGLE_CHROME_BUILD) | |
589 | |
590 return metrics; | |
591 } | |
592 | |
593 void BrowserMainParts::SetupFieldTrials() { | |
594 // Note: make sure to call ConnectionFieldTrial() before | |
595 // ProxyConnectionsFieldTrial(). | |
596 ConnectionFieldTrial(); | |
597 SocketTimeoutFieldTrial(); | |
598 ProxyConnectionsFieldTrial(); | |
599 prerender::ConfigurePrefetchAndPrerender(parsed_command_line()); | |
600 SpdyFieldTrial(); | |
601 ConnectBackupJobsFieldTrial(); | |
602 SSLFalseStartFieldTrial(); | |
603 } | |
604 | |
605 // ----------------------------------------------------------------------------- | 538 // ----------------------------------------------------------------------------- |
606 // TODO(viettrungluu): move more/rest of BrowserMain() into above structure | 539 // TODO(viettrungluu): move more/rest of BrowserMain() into above structure |
607 | 540 |
608 namespace { | 541 namespace { |
609 | 542 |
610 // This function provides some ways to test crash and assertion handling | 543 // This function provides some ways to test crash and assertion handling |
611 // behavior of the program. | 544 // behavior of the program. |
612 void HandleTestParameters(const CommandLine& command_line) { | 545 void HandleTestParameters(const CommandLine& command_line) { |
613 // This parameter causes an assertion. | 546 // This parameter causes an assertion. |
614 if (command_line.HasSwitch(switches::kBrowserAssertTest)) { | 547 if (command_line.HasSwitch(switches::kBrowserAssertTest)) { |
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
823 // Precreate the desktop and window station used by the renderers. | 756 // Precreate the desktop and window station used by the renderers. |
824 sandbox::TargetPolicy* policy = broker_services->CreatePolicy(); | 757 sandbox::TargetPolicy* policy = broker_services->CreatePolicy(); |
825 sandbox::ResultCode result = policy->CreateAlternateDesktop(use_winsta); | 758 sandbox::ResultCode result = policy->CreateAlternateDesktop(use_winsta); |
826 CHECK(sandbox::SBOX_ERROR_FAILED_TO_SWITCH_BACK_WINSTATION != result); | 759 CHECK(sandbox::SBOX_ERROR_FAILED_TO_SWITCH_BACK_WINSTATION != result); |
827 policy->Release(); | 760 policy->Release(); |
828 } | 761 } |
829 } | 762 } |
830 #endif | 763 #endif |
831 } | 764 } |
832 | 765 |
| 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 |
833 // Initializes the profile, possibly doing some user prompting to pick a | 805 // Initializes the profile, possibly doing some user prompting to pick a |
834 // fallback profile. Returns the newly created profile, or NULL if startup | 806 // fallback profile. Returns the newly created profile, or NULL if startup |
835 // should not continue. | 807 // should not continue. |
836 Profile* CreateProfile(const MainFunctionParams& parameters, | 808 Profile* CreateProfile(const MainFunctionParams& parameters, |
837 const FilePath& user_data_dir) { | 809 const FilePath& user_data_dir) { |
838 const CommandLine& browser_command_line = *CommandLine::ForCurrentProcess(); | 810 const CommandLine& browser_command_line = *CommandLine::ForCurrentProcess(); |
839 Profile* profile = browser_command_line.HasSwitch(switches::kMultiProfiles) ? | 811 Profile* profile = browser_command_line.HasSwitch(switches::kMultiProfiles) ? |
840 g_browser_process->profile_manager()->GetLastUsedProfile(user_data_dir) : | 812 g_browser_process->profile_manager()->GetLastUsedProfile(user_data_dir) : |
841 g_browser_process->profile_manager()->GetDefaultProfile(user_data_dir); | 813 g_browser_process->profile_manager()->GetDefaultProfile(user_data_dir); |
842 if (profile) | 814 if (profile) |
(...skipping 505 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1348 | 1320 |
1349 // Initialize thread watcher system. This is a singleton and is used by | 1321 // Initialize thread watcher system. This is a singleton and is used by |
1350 // WatchDogThread to keep track of information about threads that are being | 1322 // WatchDogThread to keep track of information about threads that are being |
1351 // watched. | 1323 // watched. |
1352 scoped_ptr<ThreadWatcherList> thread_watcher_list(new ThreadWatcherList()); | 1324 scoped_ptr<ThreadWatcherList> thread_watcher_list(new ThreadWatcherList()); |
1353 | 1325 |
1354 // Convert active labs into switches. Modifies the current command line. | 1326 // Convert active labs into switches. Modifies the current command line. |
1355 about_flags::ConvertFlagsToSwitches(local_state, | 1327 about_flags::ConvertFlagsToSwitches(local_state, |
1356 CommandLine::ForCurrentProcess()); | 1328 CommandLine::ForCurrentProcess()); |
1357 | 1329 |
1358 // Now the command line has been mutated based on about:flags, we can | 1330 // Now the command line has been mutated based on about:flags, we can run some |
1359 // set up metrics and initialize field trials. | 1331 // field trials |
1360 MetricsService* metrics = parts->SetupMetricsAndFieldTrials( | 1332 parts->SetupFieldTrials(); |
1361 parsed_command_line, local_state); | 1333 |
| 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()); |
1362 | 1340 |
1363 // Now that all preferences have been registered, set the install date | 1341 // Now that all preferences have been registered, set the install date |
1364 // for the uninstall metrics if this is our first run. This only actually | 1342 // for the uninstall metrics if this is our first run. This only actually |
1365 // gets used if the user has metrics reporting enabled at uninstall time. | 1343 // gets used if the user has metrics reporting enabled at uninstall time. |
1366 int64 install_date = | 1344 int64 install_date = |
1367 local_state->GetInt64(prefs::kUninstallMetricsInstallDate); | 1345 local_state->GetInt64(prefs::kUninstallMetricsInstallDate); |
1368 if (install_date == 0) { | 1346 if (install_date == 0) { |
1369 local_state->SetInt64(prefs::kUninstallMetricsInstallDate, | 1347 local_state->SetInt64(prefs::kUninstallMetricsInstallDate, |
1370 base::Time::Now().ToTimeT()); | 1348 base::Time::Now().ToTimeT()); |
1371 } | 1349 } |
(...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1695 sdch_trial->AppendGroup("global_disable_sdch", | 1673 sdch_trial->AppendGroup("global_disable_sdch", |
1696 kSDCH_DISABLE_PROBABILITY); | 1674 kSDCH_DISABLE_PROBABILITY); |
1697 if (sdch_enabled != sdch_trial->group()) | 1675 if (sdch_enabled != sdch_trial->group()) |
1698 sdch_supported_domain = "never_enabled_sdch_for_any_domain"; | 1676 sdch_supported_domain = "never_enabled_sdch_for_any_domain"; |
1699 } | 1677 } |
1700 | 1678 |
1701 net::SdchManager sdch_manager; // Singleton database. | 1679 net::SdchManager sdch_manager; // Singleton database. |
1702 sdch_manager.set_sdch_fetcher(new SdchDictionaryFetcher); | 1680 sdch_manager.set_sdch_fetcher(new SdchDictionaryFetcher); |
1703 sdch_manager.EnableSdchSupport(sdch_supported_domain); | 1681 sdch_manager.EnableSdchSupport(sdch_supported_domain); |
1704 | 1682 |
| 1683 MetricsService* metrics = InitializeMetrics(parsed_command_line, local_state); |
1705 InstallJankometer(parsed_command_line); | 1684 InstallJankometer(parsed_command_line); |
1706 | 1685 |
1707 #if defined(OS_WIN) && !defined(GOOGLE_CHROME_BUILD) | 1686 #if defined(OS_WIN) && !defined(GOOGLE_CHROME_BUILD) |
1708 if (parsed_command_line.HasSwitch(switches::kDebugPrint)) { | 1687 if (parsed_command_line.HasSwitch(switches::kDebugPrint)) { |
1709 FilePath path = | 1688 FilePath path = |
1710 parsed_command_line.GetSwitchValuePath(switches::kDebugPrint); | 1689 parsed_command_line.GetSwitchValuePath(switches::kDebugPrint); |
1711 printing::PrintedDocument::set_debug_dump_path(path); | 1690 printing::PrintedDocument::set_debug_dump_path(path); |
1712 } | 1691 } |
1713 #endif | 1692 #endif |
1714 | 1693 |
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1924 #if defined(OS_CHROMEOS) | 1903 #if defined(OS_CHROMEOS) |
1925 // To be precise, logout (browser shutdown) is not yet done, but the | 1904 // To be precise, logout (browser shutdown) is not yet done, but the |
1926 // remaining work is negligible, hence we say LogoutDone here. | 1905 // remaining work is negligible, hence we say LogoutDone here. |
1927 chromeos::BootTimesLoader::Get()->AddLogoutTimeMarker("LogoutDone", | 1906 chromeos::BootTimesLoader::Get()->AddLogoutTimeMarker("LogoutDone", |
1928 false); | 1907 false); |
1929 chromeos::BootTimesLoader::Get()->WriteLogoutTimes(); | 1908 chromeos::BootTimesLoader::Get()->WriteLogoutTimes(); |
1930 #endif | 1909 #endif |
1931 TRACE_EVENT_END("BrowserMain", 0, 0); | 1910 TRACE_EVENT_END("BrowserMain", 0, 0); |
1932 return result_code; | 1911 return result_code; |
1933 } | 1912 } |
OLD | NEW |