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 <algorithm> | 7 #include <algorithm> |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 564 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
575 result_code_(content::RESULT_CODE_NORMAL_EXIT), | 575 result_code_(content::RESULT_CODE_NORMAL_EXIT), |
576 startup_watcher_(new StartupTimeBomb()), | 576 startup_watcher_(new StartupTimeBomb()), |
577 shutdown_watcher_(new ShutdownWatcherHelper()), | 577 shutdown_watcher_(new ShutdownWatcherHelper()), |
578 record_search_engine_(false), | 578 record_search_engine_(false), |
579 translate_manager_(NULL), | 579 translate_manager_(NULL), |
580 profile_(NULL), | 580 profile_(NULL), |
581 run_message_loop_(true), | 581 run_message_loop_(true), |
582 notify_result_(ProcessSingleton::PROCESS_NONE), | 582 notify_result_(ProcessSingleton::PROCESS_NONE), |
583 is_first_run_(false), | 583 is_first_run_(false), |
584 first_run_ui_bypass_(false), | 584 first_run_ui_bypass_(false), |
585 metrics_(NULL), | |
586 local_state_(NULL), | 585 local_state_(NULL), |
587 restart_last_session_(false) { | 586 restart_last_session_(false) { |
588 // If we're running tests (ui_task is non-null). | 587 // If we're running tests (ui_task is non-null). |
589 if (parameters.ui_task) | 588 if (parameters.ui_task) |
590 browser_defaults::enable_help_app = false; | 589 browser_defaults::enable_help_app = false; |
591 } | 590 } |
592 | 591 |
593 ChromeBrowserMainParts::~ChromeBrowserMainParts() { | 592 ChromeBrowserMainParts::~ChromeBrowserMainParts() { |
594 for (int i = static_cast<int>(chrome_extra_parts_.size())-1; i >= 0; --i) | 593 for (int i = static_cast<int>(chrome_extra_parts_.size())-1; i >= 0; --i) |
595 delete chrome_extra_parts_[i]; | 594 delete chrome_extra_parts_[i]; |
596 chrome_extra_parts_.clear(); | 595 chrome_extra_parts_.clear(); |
597 } | 596 } |
598 | 597 |
599 // This will be called after the command-line has been mutated by about:flags | 598 // This will be called after the command-line has been mutated by about:flags |
600 MetricsService* ChromeBrowserMainParts::SetupMetricsAndFieldTrials( | 599 void ChromeBrowserMainParts::SetupMetricsAndFieldTrials() { |
601 PrefService* local_state) { | |
602 // Must initialize metrics after labs have been converted into switches, | 600 // Must initialize metrics after labs have been converted into switches, |
603 // but before field trials are set up (so that client ID is available for | 601 // but before field trials are set up (so that client ID is available for |
604 // one-time randomized field trials). | 602 // one-time randomized field trials). |
605 MetricsService* metrics = InitializeMetrics( | 603 #if defined(OS_WIN) |
606 parsed_command_line_, local_state); | 604 if (parsed_command_line_.HasSwitch(switches::kChromeFrame)) |
| 605 MetricsLog::set_version_extension("-F"); |
| 606 #elif defined(ARCH_CPU_64_BITS) |
| 607 MetricsLog::set_version_extension("-64"); |
| 608 #endif // defined(OS_WIN) |
607 | 609 |
608 // Initialize FieldTrialList to support FieldTrials that use one-time | 610 // Initialize FieldTrialList to support FieldTrials that use one-time |
609 // randomization. The client ID will be empty if the user has not opted | 611 // randomization. The client ID will be empty if the user has not opted |
610 // to send metrics. | 612 // to send metrics. |
| 613 MetricsService* metrics = browser_process_->metrics_service(); |
611 field_trial_list_.reset(new base::FieldTrialList(metrics->GetClientId())); | 614 field_trial_list_.reset(new base::FieldTrialList(metrics->GetClientId())); |
612 | 615 |
613 SetupFieldTrials(metrics->recording_active(), | 616 SetupFieldTrials(metrics->recording_active(), |
614 local_state->IsManagedPreference( | 617 local_state_->IsManagedPreference( |
615 prefs::kMaxConnectionsPerProxy)); | 618 prefs::kMaxConnectionsPerProxy)); |
616 | 619 |
617 // Initialize FieldTrialSynchronizer system. This is a singleton and is used | 620 // Initialize FieldTrialSynchronizer system. This is a singleton and is used |
618 // for posting tasks via base::Bind. Its deleted when it goes out of scope. | 621 // for posting tasks via base::Bind. Its deleted when it goes out of scope. |
619 // Even though base::Bind does AddRef and Release, the object will not be | 622 // Even though base::Bind does AddRef and Release, the object will not be |
620 // deleted after the Task is executed. | 623 // deleted after the Task is executed. |
621 field_trial_synchronizer_ = new FieldTrialSynchronizer(); | 624 field_trial_synchronizer_ = new FieldTrialSynchronizer(); |
622 | |
623 return metrics; | |
624 } | 625 } |
625 | 626 |
626 // This is an A/B test for the maximum number of persistent connections per | 627 // This is an A/B test for the maximum number of persistent connections per |
627 // host. Currently Chrome, Firefox, and IE8 have this value set at 6. Safari | 628 // host. Currently Chrome, Firefox, and IE8 have this value set at 6. Safari |
628 // uses 4, and Fasterfox (a plugin for Firefox that supposedly configures it to | 629 // uses 4, and Fasterfox (a plugin for Firefox that supposedly configures it to |
629 // run faster) uses 8. We would like to see how much of an effect this value has | 630 // run faster) uses 8. We would like to see how much of an effect this value has |
630 // on browsing. Too large a value might cause us to run into SYN flood detection | 631 // on browsing. Too large a value might cause us to run into SYN flood detection |
631 // mechanisms. | 632 // mechanisms. |
632 void ChromeBrowserMainParts::ConnectionFieldTrial() { | 633 void ChromeBrowserMainParts::ConnectionFieldTrial() { |
633 const base::FieldTrial::Probability kConnectDivisor = 100; | 634 const base::FieldTrial::Probability kConnectDivisor = 100; |
(...skipping 364 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
998 base::FieldTrialList::CreateFieldTrial(kAutoLaunchTrialName, | 999 base::FieldTrialList::CreateFieldTrial(kAutoLaunchTrialName, |
999 kAutoLaunchTrialAutoLaunchGroup); | 1000 kAutoLaunchTrialAutoLaunchGroup); |
1000 } else if (auto_launch_trial::IsInControlGroup(brand)) { | 1001 } else if (auto_launch_trial::IsInControlGroup(brand)) { |
1001 base::FieldTrialList::CreateFieldTrial(kAutoLaunchTrialName, | 1002 base::FieldTrialList::CreateFieldTrial(kAutoLaunchTrialName, |
1002 kAutoLaunchTrialControlGroup); | 1003 kAutoLaunchTrialControlGroup); |
1003 } | 1004 } |
1004 } | 1005 } |
1005 | 1006 |
1006 // ChromeBrowserMainParts: |SetupMetricsAndFieldTrials()| related -------------- | 1007 // ChromeBrowserMainParts: |SetupMetricsAndFieldTrials()| related -------------- |
1007 | 1008 |
1008 // Initializes the metrics service with the configuration for this process, | 1009 void ChromeBrowserMainParts::SetupFieldTrials(bool metrics_recording_enabled, |
1009 // returning the created service (guaranteed non-NULL). | 1010 bool proxy_policy_is_set) { |
1010 MetricsService* ChromeBrowserMainParts::InitializeMetrics( | 1011 // Note: make sure to call ConnectionFieldTrial() before |
1011 const CommandLine& parsed_command_line, | 1012 // ProxyConnectionsFieldTrial(). |
1012 const PrefService* local_state) { | 1013 ConnectionFieldTrial(); |
1013 #if defined(OS_WIN) | 1014 SocketTimeoutFieldTrial(); |
1014 if (parsed_command_line.HasSwitch(switches::kChromeFrame)) | 1015 // If a policy is defining the number of active connections this field test |
1015 MetricsLog::set_version_extension("-F"); | 1016 // shoud not be performed. |
1016 #elif defined(ARCH_CPU_64_BITS) | 1017 if (!proxy_policy_is_set) |
1017 MetricsLog::set_version_extension("-64"); | 1018 ProxyConnectionsFieldTrial(); |
1018 #endif // defined(OS_WIN) | 1019 prerender::ConfigurePrefetchAndPrerender(parsed_command_line()); |
| 1020 InstantFieldTrial::Activate(); |
| 1021 SpdyFieldTrial(); |
| 1022 ConnectBackupJobsFieldTrial(); |
| 1023 WarmConnectionFieldTrial(); |
| 1024 PredictorFieldTrial(); |
| 1025 DefaultAppsFieldTrial(); |
| 1026 AutoLaunchChromeFieldTrial(); |
| 1027 sync_promo_trial::Activate(); |
| 1028 } |
1019 | 1029 |
| 1030 void ChromeBrowserMainParts::StartMetricsRecording() { |
1020 MetricsService* metrics = g_browser_process->metrics_service(); | 1031 MetricsService* metrics = g_browser_process->metrics_service(); |
1021 | 1032 if (parsed_command_line_.HasSwitch(switches::kMetricsRecordingOnly) || |
1022 if (parsed_command_line.HasSwitch(switches::kMetricsRecordingOnly) || | 1033 parsed_command_line_.HasSwitch(switches::kEnableBenchmarking)) { |
1023 parsed_command_line.HasSwitch(switches::kEnableBenchmarking)) { | |
1024 // If we're testing then we don't care what the user preference is, we turn | 1034 // If we're testing then we don't care what the user preference is, we turn |
1025 // on recording, but not reporting, otherwise tests fail. | 1035 // on recording, but not reporting, otherwise tests fail. |
1026 metrics->StartRecordingOnly(); | 1036 metrics->StartRecordingOnly(); |
1027 return metrics; | 1037 return; |
1028 } | 1038 } |
1029 | 1039 |
1030 // If the user permits metrics reporting with the checkbox in the | 1040 // If the user permits metrics reporting with the checkbox in the |
1031 // prefs, we turn on recording. We disable metrics completely for | 1041 // prefs, we turn on recording. We disable metrics completely for |
1032 // non-official builds. | 1042 // non-official builds. |
1033 #if defined(GOOGLE_CHROME_BUILD) | 1043 #if defined(GOOGLE_CHROME_BUILD) |
1034 #if defined(OS_CHROMEOS) | 1044 #if defined(OS_CHROMEOS) |
1035 bool enabled; | 1045 bool enabled; |
1036 chromeos::CrosSettings::Get()->GetBoolean(chromeos::kStatsReportingPref, | 1046 chromeos::CrosSettings::Get()->GetBoolean(chromeos::kStatsReportingPref, |
1037 &enabled); | 1047 &enabled); |
1038 #else | 1048 #else |
1039 bool enabled = local_state->GetBoolean(prefs::kMetricsReportingEnabled); | 1049 bool enabled = local_state_->GetBoolean(prefs::kMetricsReportingEnabled); |
1040 #endif // #if defined(OS_CHROMEOS) | 1050 #endif // #if defined(OS_CHROMEOS) |
1041 if (enabled) { | 1051 if (enabled) { |
1042 metrics->Start(); | 1052 metrics->Start(); |
1043 } | 1053 } |
1044 #endif // defined(GOOGLE_CHROME_BUILD) | 1054 #endif // defined(GOOGLE_CHROME_BUILD) |
1045 | |
1046 return metrics; | |
1047 } | |
1048 | |
1049 void ChromeBrowserMainParts::SetupFieldTrials(bool metrics_recording_enabled, | |
1050 bool proxy_policy_is_set) { | |
1051 // Note: make sure to call ConnectionFieldTrial() before | |
1052 // ProxyConnectionsFieldTrial(). | |
1053 ConnectionFieldTrial(); | |
1054 SocketTimeoutFieldTrial(); | |
1055 // If a policy is defining the number of active connections this field test | |
1056 // shoud not be performed. | |
1057 if (!proxy_policy_is_set) | |
1058 ProxyConnectionsFieldTrial(); | |
1059 prerender::ConfigurePrefetchAndPrerender(parsed_command_line()); | |
1060 InstantFieldTrial::Activate(); | |
1061 SpdyFieldTrial(); | |
1062 ConnectBackupJobsFieldTrial(); | |
1063 WarmConnectionFieldTrial(); | |
1064 PredictorFieldTrial(); | |
1065 DefaultAppsFieldTrial(); | |
1066 AutoLaunchChromeFieldTrial(); | |
1067 sync_promo_trial::Activate(); | |
1068 } | 1055 } |
1069 | 1056 |
1070 // ----------------------------------------------------------------------------- | 1057 // ----------------------------------------------------------------------------- |
1071 // TODO(viettrungluu): move more/rest of BrowserMain() into BrowserMainParts. | 1058 // TODO(viettrungluu): move more/rest of BrowserMain() into BrowserMainParts. |
1072 | 1059 |
1073 #if defined(OS_WIN) | 1060 #if defined(OS_WIN) |
1074 #define DLLEXPORT __declspec(dllexport) | 1061 #define DLLEXPORT __declspec(dllexport) |
1075 | 1062 |
1076 // We use extern C for the prototype DLLEXPORT to avoid C++ name mangling. | 1063 // We use extern C for the prototype DLLEXPORT to avoid C++ name mangling. |
1077 extern "C" { | 1064 extern "C" { |
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1302 #if defined(OS_MACOSX) | 1289 #if defined(OS_MACOSX) |
1303 // Get the Keychain API to register for distributed notifications on the main | 1290 // Get the Keychain API to register for distributed notifications on the main |
1304 // thread, which has a proper CFRunloop, instead of later on the I/O thread, | 1291 // thread, which has a proper CFRunloop, instead of later on the I/O thread, |
1305 // which doesn't. This ensures those notifications will get delivered | 1292 // which doesn't. This ensures those notifications will get delivered |
1306 // properly. See issue 37766. | 1293 // properly. See issue 37766. |
1307 // (Note that the callback mask here is empty. I don't want to register for | 1294 // (Note that the callback mask here is empty. I don't want to register for |
1308 // any callbacks, I just want to initialize the mechanism.) | 1295 // any callbacks, I just want to initialize the mechanism.) |
1309 SecKeychainAddCallback(&KeychainCallback, 0, NULL); | 1296 SecKeychainAddCallback(&KeychainCallback, 0, NULL); |
1310 #endif | 1297 #endif |
1311 | 1298 |
| 1299 // Now the command line has been mutated based on about:flags, we can setup |
| 1300 // metrics and initialize field trials. The field trials are needed by |
| 1301 // IOThread's initialization which happens in BrowserProcess:PreCreateThreads. |
| 1302 SetupMetricsAndFieldTrials(); |
| 1303 |
1312 // ChromeOS needs ResourceBundle::InitSharedInstance to be called before this. | 1304 // ChromeOS needs ResourceBundle::InitSharedInstance to be called before this. |
1313 browser_process_->PreCreateThreads(); | 1305 browser_process_->PreCreateThreads(); |
1314 | 1306 |
1315 return content::RESULT_CODE_NORMAL_EXIT; | 1307 return content::RESULT_CODE_NORMAL_EXIT; |
1316 } | 1308 } |
1317 | 1309 |
1318 void ChromeBrowserMainParts::PreMainMessageLoopRun() { | 1310 void ChromeBrowserMainParts::PreMainMessageLoopRun() { |
1319 result_code_ = PreMainMessageLoopRunImpl(); | 1311 result_code_ = PreMainMessageLoopRunImpl(); |
1320 | 1312 |
1321 for (size_t i = 0; i < chrome_extra_parts_.size(); ++i) | 1313 for (size_t i = 0; i < chrome_extra_parts_.size(); ++i) |
(...skipping 25 matching lines...) Expand all Loading... |
1347 for (size_t i = 0; i < chrome_extra_parts_.size(); ++i) | 1339 for (size_t i = 0; i < chrome_extra_parts_.size(); ++i) |
1348 chrome_extra_parts_[i]->PreBrowserStart(); | 1340 chrome_extra_parts_[i]->PreBrowserStart(); |
1349 } | 1341 } |
1350 | 1342 |
1351 void ChromeBrowserMainParts::PostBrowserStart() { | 1343 void ChromeBrowserMainParts::PostBrowserStart() { |
1352 for (size_t i = 0; i < chrome_extra_parts_.size(); ++i) | 1344 for (size_t i = 0; i < chrome_extra_parts_.size(); ++i) |
1353 chrome_extra_parts_[i]->PostBrowserStart(); | 1345 chrome_extra_parts_[i]->PostBrowserStart(); |
1354 } | 1346 } |
1355 | 1347 |
1356 int ChromeBrowserMainParts::PreMainMessageLoopRunImpl() { | 1348 int ChromeBrowserMainParts::PreMainMessageLoopRunImpl() { |
1357 // Now the command line has been mutated based on about:flags, | 1349 // Now that the file thread has been started, start recording. |
1358 // and the file thread has been started, we can set up metrics | 1350 StartMetricsRecording(); |
1359 // and initialize field trials. | |
1360 metrics_ = SetupMetricsAndFieldTrials(local_state_); | |
1361 | 1351 |
1362 #if defined(USE_LINUX_BREAKPAD) | 1352 #if defined(USE_LINUX_BREAKPAD) |
1363 // Needs to be called after we have chrome::DIR_USER_DATA and | 1353 // Needs to be called after we have chrome::DIR_USER_DATA and |
1364 // g_browser_process. This happens in PreCreateThreads. | 1354 // g_browser_process. This happens in PreCreateThreads. |
1365 BrowserThread::PostTask(BrowserThread::FILE, | 1355 BrowserThread::PostTask(BrowserThread::FILE, |
1366 FROM_HERE, | 1356 FROM_HERE, |
1367 base::Bind(&GetLinuxDistroCallback)); | 1357 base::Bind(&GetLinuxDistroCallback)); |
1368 | 1358 |
1369 if (IsCrashReportingEnabled(local_state_)) | 1359 if (IsCrashReportingEnabled(local_state_)) |
1370 InitCrashReporter(); | 1360 InitCrashReporter(); |
(...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1666 | 1656 |
1667 #if defined(OS_WIN) && !defined(GOOGLE_CHROME_BUILD) | 1657 #if defined(OS_WIN) && !defined(GOOGLE_CHROME_BUILD) |
1668 if (parsed_command_line().HasSwitch(switches::kDebugPrint)) { | 1658 if (parsed_command_line().HasSwitch(switches::kDebugPrint)) { |
1669 FilePath path = | 1659 FilePath path = |
1670 parsed_command_line().GetSwitchValuePath(switches::kDebugPrint); | 1660 parsed_command_line().GetSwitchValuePath(switches::kDebugPrint); |
1671 printing::PrintedDocument::set_debug_dump_path(path); | 1661 printing::PrintedDocument::set_debug_dump_path(path); |
1672 } | 1662 } |
1673 #endif | 1663 #endif |
1674 | 1664 |
1675 HandleTestParameters(parsed_command_line()); | 1665 HandleTestParameters(parsed_command_line()); |
1676 RecordBreakpadStatusUMA(metrics_); | 1666 RecordBreakpadStatusUMA(browser_process_->metrics_service()); |
1677 about_flags::RecordUMAStatistics(local_state_); | 1667 about_flags::RecordUMAStatistics(local_state_); |
1678 LanguageUsageMetrics::RecordAcceptLanguages( | 1668 LanguageUsageMetrics::RecordAcceptLanguages( |
1679 profile_->GetPrefs()->GetString(prefs::kAcceptLanguages)); | 1669 profile_->GetPrefs()->GetString(prefs::kAcceptLanguages)); |
1680 LanguageUsageMetrics::RecordApplicationLanguage( | 1670 LanguageUsageMetrics::RecordApplicationLanguage( |
1681 browser_process_->GetApplicationLocale()); | 1671 browser_process_->GetApplicationLocale()); |
1682 | 1672 |
1683 #if defined(OS_WIN) | 1673 #if defined(OS_WIN) |
1684 fragmentation_checker::RecordFragmentationMetricForCurrentModule(); | 1674 fragmentation_checker::RecordFragmentationMetricForCurrentModule(); |
1685 #endif | 1675 #endif |
1686 | 1676 |
(...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1960 if (base::win::GetVersion() <= base::win::VERSION_XP) | 1950 if (base::win::GetVersion() <= base::win::VERSION_XP) |
1961 uma_name += "_XP"; | 1951 uma_name += "_XP"; |
1962 | 1952 |
1963 uma_name += "_PreRead"; | 1953 uma_name += "_PreRead"; |
1964 uma_name += pre_read == "1" ? "Enabled" : "Disabled"; | 1954 uma_name += pre_read == "1" ? "Enabled" : "Disabled"; |
1965 AddPreReadHistogramTime(uma_name.c_str(), time); | 1955 AddPreReadHistogramTime(uma_name.c_str(), time); |
1966 } | 1956 } |
1967 #endif | 1957 #endif |
1968 #endif | 1958 #endif |
1969 } | 1959 } |
OLD | NEW |