| 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 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 |
| 538 // ----------------------------------------------------------------------------- | 605 // ----------------------------------------------------------------------------- |
| 539 // TODO(viettrungluu): move more/rest of BrowserMain() into above structure | 606 // TODO(viettrungluu): move more/rest of BrowserMain() into above structure |
| 540 | 607 |
| 541 namespace { | 608 namespace { |
| 542 | 609 |
| 543 // This function provides some ways to test crash and assertion handling | 610 // This function provides some ways to test crash and assertion handling |
| 544 // behavior of the program. | 611 // behavior of the program. |
| 545 void HandleTestParameters(const CommandLine& command_line) { | 612 void HandleTestParameters(const CommandLine& command_line) { |
| 546 // This parameter causes an assertion. | 613 // This parameter causes an assertion. |
| 547 if (command_line.HasSwitch(switches::kBrowserAssertTest)) { | 614 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. | 823 // Precreate the desktop and window station used by the renderers. |
| 757 sandbox::TargetPolicy* policy = broker_services->CreatePolicy(); | 824 sandbox::TargetPolicy* policy = broker_services->CreatePolicy(); |
| 758 sandbox::ResultCode result = policy->CreateAlternateDesktop(use_winsta); | 825 sandbox::ResultCode result = policy->CreateAlternateDesktop(use_winsta); |
| 759 CHECK(sandbox::SBOX_ERROR_FAILED_TO_SWITCH_BACK_WINSTATION != result); | 826 CHECK(sandbox::SBOX_ERROR_FAILED_TO_SWITCH_BACK_WINSTATION != result); |
| 760 policy->Release(); | 827 policy->Release(); |
| 761 } | 828 } |
| 762 } | 829 } |
| 763 #endif | 830 #endif |
| 764 } | 831 } |
| 765 | 832 |
| 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 | 833 // Initializes the profile, possibly doing some user prompting to pick a |
| 806 // fallback profile. Returns the newly created profile, or NULL if startup | 834 // fallback profile. Returns the newly created profile, or NULL if startup |
| 807 // should not continue. | 835 // should not continue. |
| 808 Profile* CreateProfile(const MainFunctionParams& parameters, | 836 Profile* CreateProfile(const MainFunctionParams& parameters, |
| 809 const FilePath& user_data_dir) { | 837 const FilePath& user_data_dir) { |
| 810 const CommandLine& browser_command_line = *CommandLine::ForCurrentProcess(); | 838 const CommandLine& browser_command_line = *CommandLine::ForCurrentProcess(); |
| 811 Profile* profile = browser_command_line.HasSwitch(switches::kMultiProfiles) ? | 839 Profile* profile = browser_command_line.HasSwitch(switches::kMultiProfiles) ? |
| 812 g_browser_process->profile_manager()->GetLastUsedProfile(user_data_dir) : | 840 g_browser_process->profile_manager()->GetLastUsedProfile(user_data_dir) : |
| 813 g_browser_process->profile_manager()->GetDefaultProfile(user_data_dir); | 841 g_browser_process->profile_manager()->GetDefaultProfile(user_data_dir); |
| 814 if (profile) | 842 if (profile) |
| (...skipping 505 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1320 | 1348 |
| 1321 // Initialize thread watcher system. This is a singleton and is used by | 1349 // Initialize thread watcher system. This is a singleton and is used by |
| 1322 // WatchDogThread to keep track of information about threads that are being | 1350 // WatchDogThread to keep track of information about threads that are being |
| 1323 // watched. | 1351 // watched. |
| 1324 scoped_ptr<ThreadWatcherList> thread_watcher_list(new ThreadWatcherList()); | 1352 scoped_ptr<ThreadWatcherList> thread_watcher_list(new ThreadWatcherList()); |
| 1325 | 1353 |
| 1326 // Convert active labs into switches. Modifies the current command line. | 1354 // Convert active labs into switches. Modifies the current command line. |
| 1327 about_flags::ConvertFlagsToSwitches(local_state, | 1355 about_flags::ConvertFlagsToSwitches(local_state, |
| 1328 CommandLine::ForCurrentProcess()); | 1356 CommandLine::ForCurrentProcess()); |
| 1329 | 1357 |
| 1330 // Now the command line has been mutated based on about:flags, we can run some | 1358 // Now the command line has been mutated based on about:flags, we can |
| 1331 // field trials | 1359 // set up metrics and initialize field trials. |
| 1332 parts->SetupFieldTrials(); | 1360 MetricsService* metrics = parts->SetupMetricsAndFieldTrials( |
| 1333 | 1361 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 | 1362 |
| 1341 // Now that all preferences have been registered, set the install date | 1363 // 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 | 1364 // 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. | 1365 // gets used if the user has metrics reporting enabled at uninstall time. |
| 1344 int64 install_date = | 1366 int64 install_date = |
| 1345 local_state->GetInt64(prefs::kUninstallMetricsInstallDate); | 1367 local_state->GetInt64(prefs::kUninstallMetricsInstallDate); |
| 1346 if (install_date == 0) { | 1368 if (install_date == 0) { |
| 1347 local_state->SetInt64(prefs::kUninstallMetricsInstallDate, | 1369 local_state->SetInt64(prefs::kUninstallMetricsInstallDate, |
| 1348 base::Time::Now().ToTimeT()); | 1370 base::Time::Now().ToTimeT()); |
| 1349 } | 1371 } |
| (...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1673 sdch_trial->AppendGroup("global_disable_sdch", | 1695 sdch_trial->AppendGroup("global_disable_sdch", |
| 1674 kSDCH_DISABLE_PROBABILITY); | 1696 kSDCH_DISABLE_PROBABILITY); |
| 1675 if (sdch_enabled != sdch_trial->group()) | 1697 if (sdch_enabled != sdch_trial->group()) |
| 1676 sdch_supported_domain = "never_enabled_sdch_for_any_domain"; | 1698 sdch_supported_domain = "never_enabled_sdch_for_any_domain"; |
| 1677 } | 1699 } |
| 1678 | 1700 |
| 1679 net::SdchManager sdch_manager; // Singleton database. | 1701 net::SdchManager sdch_manager; // Singleton database. |
| 1680 sdch_manager.set_sdch_fetcher(new SdchDictionaryFetcher); | 1702 sdch_manager.set_sdch_fetcher(new SdchDictionaryFetcher); |
| 1681 sdch_manager.EnableSdchSupport(sdch_supported_domain); | 1703 sdch_manager.EnableSdchSupport(sdch_supported_domain); |
| 1682 | 1704 |
| 1683 MetricsService* metrics = InitializeMetrics(parsed_command_line, local_state); | |
| 1684 InstallJankometer(parsed_command_line); | 1705 InstallJankometer(parsed_command_line); |
| 1685 | 1706 |
| 1686 #if defined(OS_WIN) && !defined(GOOGLE_CHROME_BUILD) | 1707 #if defined(OS_WIN) && !defined(GOOGLE_CHROME_BUILD) |
| 1687 if (parsed_command_line.HasSwitch(switches::kDebugPrint)) { | 1708 if (parsed_command_line.HasSwitch(switches::kDebugPrint)) { |
| 1688 FilePath path = | 1709 FilePath path = |
| 1689 parsed_command_line.GetSwitchValuePath(switches::kDebugPrint); | 1710 parsed_command_line.GetSwitchValuePath(switches::kDebugPrint); |
| 1690 printing::PrintedDocument::set_debug_dump_path(path); | 1711 printing::PrintedDocument::set_debug_dump_path(path); |
| 1691 } | 1712 } |
| 1692 #endif | 1713 #endif |
| 1693 | 1714 |
| (...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1898 #if defined(OS_CHROMEOS) | 1919 #if defined(OS_CHROMEOS) |
| 1899 // To be precise, logout (browser shutdown) is not yet done, but the | 1920 // To be precise, logout (browser shutdown) is not yet done, but the |
| 1900 // remaining work is negligible, hence we say LogoutDone here. | 1921 // remaining work is negligible, hence we say LogoutDone here. |
| 1901 chromeos::BootTimesLoader::Get()->AddLogoutTimeMarker("LogoutDone", | 1922 chromeos::BootTimesLoader::Get()->AddLogoutTimeMarker("LogoutDone", |
| 1902 false); | 1923 false); |
| 1903 chromeos::BootTimesLoader::Get()->WriteLogoutTimes(); | 1924 chromeos::BootTimesLoader::Get()->WriteLogoutTimes(); |
| 1904 #endif | 1925 #endif |
| 1905 TRACE_EVENT_END("BrowserMain", 0, 0); | 1926 TRACE_EVENT_END("BrowserMain", 0, 0); |
| 1906 return result_code; | 1927 return result_code; |
| 1907 } | 1928 } |
| OLD | NEW |