| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <algorithm> | 10 #include <algorithm> |
| (...skipping 774 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 785 net::URLRequest::SetDefaultCookiePolicyToBlock(); | 785 net::URLRequest::SetDefaultCookiePolicyToBlock(); |
| 786 } | 786 } |
| 787 | 787 |
| 788 ChromeBrowserMainParts::~ChromeBrowserMainParts() { | 788 ChromeBrowserMainParts::~ChromeBrowserMainParts() { |
| 789 for (int i = static_cast<int>(chrome_extra_parts_.size())-1; i >= 0; --i) | 789 for (int i = static_cast<int>(chrome_extra_parts_.size())-1; i >= 0; --i) |
| 790 delete chrome_extra_parts_[i]; | 790 delete chrome_extra_parts_[i]; |
| 791 chrome_extra_parts_.clear(); | 791 chrome_extra_parts_.clear(); |
| 792 } | 792 } |
| 793 | 793 |
| 794 // This will be called after the command-line has been mutated by about:flags | 794 // This will be called after the command-line has been mutated by about:flags |
| 795 void ChromeBrowserMainParts::SetupMetricsAndFieldTrials() { | 795 void ChromeBrowserMainParts::SetupFieldTrials() { |
| 796 TRACE_EVENT0("startup", "ChromeBrowserMainParts::SetupMetricsAndFieldTrials"); | 796 TRACE_EVENT0("startup", "ChromeBrowserMainParts::SetupFieldTrials"); |
| 797 | 797 |
| 798 // Initialize FieldTrialList to support FieldTrials that use one-time | 798 // Initialize FieldTrialList to support FieldTrials that use one-time |
| 799 // randomization. | 799 // randomization. |
| 800 DCHECK(!field_trial_list_); | 800 DCHECK(!field_trial_list_); |
| 801 field_trial_list_.reset( | 801 field_trial_list_.reset( |
| 802 new base::FieldTrialList(browser_process_->GetMetricsServicesManager() | 802 new base::FieldTrialList(browser_process_->GetMetricsServicesManager() |
| 803 ->CreateEntropyProvider() | 803 ->CreateEntropyProvider() |
| 804 .release())); | 804 .release())); |
| 805 | 805 |
| 806 const base::CommandLine* command_line = | 806 const base::CommandLine* command_line = |
| (...skipping 28 matching lines...) Expand all Loading... |
| 835 | 835 |
| 836 std::unique_ptr<base::FeatureList> feature_list(new base::FeatureList); | 836 std::unique_ptr<base::FeatureList> feature_list(new base::FeatureList); |
| 837 | 837 |
| 838 // Associate parameters chosen in about:flags and create trial/group for them. | 838 // Associate parameters chosen in about:flags and create trial/group for them. |
| 839 flags_ui::PrefServiceFlagsStorage flags_storage( | 839 flags_ui::PrefServiceFlagsStorage flags_storage( |
| 840 g_browser_process->local_state()); | 840 g_browser_process->local_state()); |
| 841 std::vector<std::string> variation_ids = | 841 std::vector<std::string> variation_ids = |
| 842 about_flags::RegisterAllFeatureVariationParameters( | 842 about_flags::RegisterAllFeatureVariationParameters( |
| 843 &flags_storage, feature_list.get()); | 843 &flags_storage, feature_list.get()); |
| 844 | 844 |
| 845 // Must initialize metrics after about:flags have been converted into | |
| 846 // switches, but before field trials are set up (so that client ID is | |
| 847 // available for one-time randomized field trials). | |
| 848 metrics::MetricsService* metrics = browser_process_->metrics_service(); | |
| 849 | |
| 850 variations::VariationsHttpHeaderProvider* http_header_provider = | 845 variations::VariationsHttpHeaderProvider* http_header_provider = |
| 851 variations::VariationsHttpHeaderProvider::GetInstance(); | 846 variations::VariationsHttpHeaderProvider::GetInstance(); |
| 852 // Force the variation ids selected in chrome://flags and/or specified using | 847 // Force the variation ids selected in chrome://flags and/or specified using |
| 853 // the command-line flag. | 848 // the command-line flag. |
| 854 bool result = http_header_provider->ForceVariationIds( | 849 bool result = http_header_provider->ForceVariationIds( |
| 855 command_line->GetSwitchValueASCII(switches::kForceVariationIds), | 850 command_line->GetSwitchValueASCII(switches::kForceVariationIds), |
| 856 &variation_ids); | 851 &variation_ids); |
| 857 CHECK(result) << "Invalid list of variation ids specified (either in --" | 852 CHECK(result) << "Invalid list of variation ids specified (either in --" |
| 858 << switches::kForceVariationIds << " or in chrome://flags)"; | 853 << switches::kForceVariationIds << " or in chrome://flags)"; |
| 859 metrics->AddSyntheticTrialObserver(http_header_provider); | |
| 860 | 854 |
| 861 feature_list->InitializeFromCommandLine( | 855 feature_list->InitializeFromCommandLine( |
| 862 command_line->GetSwitchValueASCII(switches::kEnableFeatures), | 856 command_line->GetSwitchValueASCII(switches::kEnableFeatures), |
| 863 command_line->GetSwitchValueASCII(switches::kDisableFeatures)); | 857 command_line->GetSwitchValueASCII(switches::kDisableFeatures)); |
| 864 | 858 |
| 865 #if defined(FIELDTRIAL_TESTING_ENABLED) | 859 #if defined(FIELDTRIAL_TESTING_ENABLED) |
| 866 if (!command_line->HasSwitch(switches::kDisableFieldTrialTestingConfig) && | 860 if (!command_line->HasSwitch(switches::kDisableFieldTrialTestingConfig) && |
| 867 !command_line->HasSwitch(switches::kForceFieldTrials) && | 861 !command_line->HasSwitch(switches::kForceFieldTrials) && |
| 868 !command_line->HasSwitch(variations::switches::kVariationsServerURL)) { | 862 !command_line->HasSwitch(variations::switches::kVariationsServerURL)) { |
| 869 chrome_variations::AssociateDefaultFieldTrialConfig(feature_list.get()); | 863 chrome_variations::AssociateDefaultFieldTrialConfig(feature_list.get()); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 889 command_line->HasSwitch(switches::kTraceUploadURL)) { | 883 command_line->HasSwitch(switches::kTraceUploadURL)) { |
| 890 tracing::SetupNavigationTracing(); | 884 tracing::SetupNavigationTracing(); |
| 891 } | 885 } |
| 892 | 886 |
| 893 // Initialize FieldTrialSynchronizer system. This is a singleton and is used | 887 // Initialize FieldTrialSynchronizer system. This is a singleton and is used |
| 894 // for posting tasks via base::Bind. Its deleted when it goes out of scope. | 888 // for posting tasks via base::Bind. Its deleted when it goes out of scope. |
| 895 // Even though base::Bind does AddRef and Release, the object will not be | 889 // Even though base::Bind does AddRef and Release, the object will not be |
| 896 // deleted after the Task is executed. | 890 // deleted after the Task is executed. |
| 897 field_trial_synchronizer_ = new FieldTrialSynchronizer(); | 891 field_trial_synchronizer_ = new FieldTrialSynchronizer(); |
| 898 | 892 |
| 899 // Now that field trials have been created, initializes metrics recording. | |
| 900 metrics->InitializeMetricsRecordingState(); | |
| 901 | |
| 902 const version_info::Channel channel = chrome::GetChannel(); | |
| 903 | |
| 904 // Enable profiler instrumentation depending on the channel. | |
| 905 switch (channel) { | |
| 906 case version_info::Channel::UNKNOWN: | |
| 907 case version_info::Channel::CANARY: | |
| 908 tracked_objects::ScopedTracker::Enable(); | |
| 909 break; | |
| 910 | |
| 911 case version_info::Channel::DEV: | |
| 912 case version_info::Channel::BETA: | |
| 913 case version_info::Channel::STABLE: | |
| 914 // Don't enable instrumentation. | |
| 915 break; | |
| 916 } | |
| 917 | |
| 918 // Register a synthetic field trial for the sampling profiler configuration | 893 // Register a synthetic field trial for the sampling profiler configuration |
| 919 // that was already chosen. | 894 // that was already chosen. |
| 920 sampling_profiler_config_.RegisterSyntheticFieldTrial(); | 895 sampling_profiler_config_.RegisterSyntheticFieldTrial(); |
| 921 | 896 |
| 922 #if defined(OS_WIN) || defined(OS_MACOSX) || \ | 897 #if defined(OS_WIN) || defined(OS_MACOSX) || \ |
| 923 (defined(OS_LINUX) && !defined(OS_CHROMEOS)) | 898 (defined(OS_LINUX) && !defined(OS_CHROMEOS)) |
| 924 metrics::DesktopEngagementService::Initialize(); | 899 metrics::DesktopEngagementService::Initialize(); |
| 925 #endif | 900 #endif |
| 926 | 901 |
| 927 #if defined(OS_WIN) | 902 #if defined(OS_WIN) |
| 928 // Cleanup the PreRead field trial registry key. | 903 // Cleanup the PreRead field trial registry key. |
| 929 // TODO(fdoray): Remove this when M56 hits stable. | 904 // TODO(fdoray): Remove this when M56 hits stable. |
| 930 const base::string16 pre_read_field_trial_registry_path = | 905 const base::string16 pre_read_field_trial_registry_path = |
| 931 BrowserDistribution::GetDistribution()->GetRegistryPath() + | 906 BrowserDistribution::GetDistribution()->GetRegistryPath() + |
| 932 L"\\PreReadFieldTrial"; | 907 L"\\PreReadFieldTrial"; |
| 933 base::win::RegKey(HKEY_CURRENT_USER, | 908 base::win::RegKey(HKEY_CURRENT_USER, |
| 934 pre_read_field_trial_registry_path.c_str(), KEY_SET_VALUE) | 909 pre_read_field_trial_registry_path.c_str(), KEY_SET_VALUE) |
| 935 .DeleteKey(L""); | 910 .DeleteKey(L""); |
| 936 #endif // defined(OS_WIN) | 911 #endif // defined(OS_WIN) |
| 937 } | 912 } |
| 938 | 913 |
| 939 // ChromeBrowserMainParts: |SetupMetricsAndFieldTrials()| related -------------- | 914 void ChromeBrowserMainParts::SetupMetrics() { |
| 915 TRACE_EVENT0("startup", "ChromeBrowserMainParts::SetupMetrics"); |
| 916 metrics::MetricsService* metrics = browser_process_->metrics_service(); |
| 917 metrics->AddSyntheticTrialObserver( |
| 918 variations::VariationsHttpHeaderProvider::GetInstance()); |
| 919 // Now that field trials have been created, initializes metrics recording. |
| 920 metrics->InitializeMetricsRecordingState(); |
| 921 |
| 922 const version_info::Channel channel = chrome::GetChannel(); |
| 923 |
| 924 // Enable profiler instrumentation depending on the channel. |
| 925 switch (channel) { |
| 926 case version_info::Channel::UNKNOWN: |
| 927 case version_info::Channel::CANARY: |
| 928 tracked_objects::ScopedTracker::Enable(); |
| 929 break; |
| 930 |
| 931 case version_info::Channel::DEV: |
| 932 case version_info::Channel::BETA: |
| 933 case version_info::Channel::STABLE: |
| 934 // Don't enable instrumentation. |
| 935 break; |
| 936 } |
| 937 } |
| 938 |
| 939 // ChromeBrowserMainParts: |SetupFieldTrials()| and |SetupMetrics()| related --- |
| 940 | 940 |
| 941 void ChromeBrowserMainParts::StartMetricsRecording() { | 941 void ChromeBrowserMainParts::StartMetricsRecording() { |
| 942 TRACE_EVENT0("startup", "ChromeBrowserMainParts::StartMetricsRecording"); | 942 TRACE_EVENT0("startup", "ChromeBrowserMainParts::StartMetricsRecording"); |
| 943 | 943 |
| 944 g_browser_process->metrics_service()->CheckForClonedInstall( | 944 g_browser_process->metrics_service()->CheckForClonedInstall( |
| 945 BrowserThread::GetTaskRunnerForThread(BrowserThread::FILE)); | 945 BrowserThread::GetTaskRunnerForThread(BrowserThread::FILE)); |
| 946 | 946 |
| 947 g_browser_process->GetMetricsServicesManager()->UpdateUploadPermissions(true); | 947 g_browser_process->GetMetricsServicesManager()->UpdateUploadPermissions(true); |
| 948 } | 948 } |
| 949 | 949 |
| (...skipping 363 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1313 // thread, which has a proper CFRunloop, instead of later on the I/O thread, | 1313 // thread, which has a proper CFRunloop, instead of later on the I/O thread, |
| 1314 // which doesn't. This ensures those notifications will get delivered | 1314 // which doesn't. This ensures those notifications will get delivered |
| 1315 // properly. See issue 37766. | 1315 // properly. See issue 37766. |
| 1316 // (Note that the callback mask here is empty. I don't want to register for | 1316 // (Note that the callback mask here is empty. I don't want to register for |
| 1317 // any callbacks, I just want to initialize the mechanism.) | 1317 // any callbacks, I just want to initialize the mechanism.) |
| 1318 SecKeychainAddCallback(&KeychainCallback, 0, NULL); | 1318 SecKeychainAddCallback(&KeychainCallback, 0, NULL); |
| 1319 #endif // defined(OS_MACOSX) | 1319 #endif // defined(OS_MACOSX) |
| 1320 | 1320 |
| 1321 #if defined(OS_CHROMEOS) | 1321 #if defined(OS_CHROMEOS) |
| 1322 // Must be done after g_browser_process is constructed, before | 1322 // Must be done after g_browser_process is constructed, before |
| 1323 // SetupMetricsAndFieldTrials(). | 1323 // SetupFieldTrials() and SetupMetrics(). |
| 1324 chromeos::CrosSettings::Initialize(); | 1324 chromeos::CrosSettings::Initialize(); |
| 1325 #endif // defined(OS_CHROMEOS) | 1325 #endif // defined(OS_CHROMEOS) |
| 1326 | 1326 |
| 1327 SetupOriginTrialsCommandLine(); | 1327 SetupOriginTrialsCommandLine(); |
| 1328 | 1328 |
| 1329 // Now the command line has been mutated based on about:flags, we can setup | 1329 // Now the command line has been mutated based on about:flags, we can |
| 1330 // metrics and initialize field trials. The field trials are needed by | 1330 // initialize field trials and setup metrics. The field trials are needed by |
| 1331 // IOThread's initialization which happens in BrowserProcess:PreCreateThreads. | 1331 // IOThread's initialization which happens in BrowserProcess:PreCreateThreads. |
| 1332 SetupMetricsAndFieldTrials(); | 1332 SetupFieldTrials(); |
| 1333 SetupMetrics(); |
| 1333 | 1334 |
| 1334 // ChromeOS needs ResourceBundle::InitSharedInstance to be called before this. | 1335 // ChromeOS needs ResourceBundle::InitSharedInstance to be called before this. |
| 1335 browser_process_->PreCreateThreads(); | 1336 browser_process_->PreCreateThreads(); |
| 1336 | 1337 |
| 1337 device::GeolocationProvider::SetGeolocationDelegate( | 1338 device::GeolocationProvider::SetGeolocationDelegate( |
| 1338 new ChromeGeolocationDelegate()); | 1339 new ChromeGeolocationDelegate()); |
| 1339 | 1340 |
| 1340 // This needs to be the last thing in PreCreateThreads() because the | 1341 // This needs to be the last thing in PreCreateThreads() because the |
| 1341 // TaskScheduler needs to be created before any other threads are (by | 1342 // TaskScheduler needs to be created before any other threads are (by |
| 1342 // contract) but it creates threads itself so instantiating it earlier is also | 1343 // contract) but it creates threads itself so instantiating it earlier is also |
| 1343 // incorrect. It also has to be after SetupMetricsAndFieldTrials() to allow it | 1344 // incorrect. It also has to be after SetupFieldTrials() to allow it to use |
| 1344 // to use field trials. Note: it could also be the first thing in | 1345 // field trials. Note: it could also be the first thing in CreateThreads() but |
| 1345 // CreateThreads() but being in chrome/ is convenient for now as the | 1346 // being in chrome/ is convenient for now as the initialization uses |
| 1346 // initialization uses variations parameters extensively. | 1347 // variations parameters extensively. |
| 1347 // | 1348 // |
| 1348 // To maintain scoping symmetry, if this line is moved, the corresponding | 1349 // To maintain scoping symmetry, if this line is moved, the corresponding |
| 1349 // shutdown call may also need to be moved. | 1350 // shutdown call may also need to be moved. |
| 1350 MaybeInitializeTaskScheduler(); | 1351 MaybeInitializeTaskScheduler(); |
| 1351 | 1352 |
| 1352 return content::RESULT_CODE_NORMAL_EXIT; | 1353 return content::RESULT_CODE_NORMAL_EXIT; |
| 1353 } | 1354 } |
| 1354 | 1355 |
| 1355 void ChromeBrowserMainParts::MojoShellConnectionStarted( | 1356 void ChromeBrowserMainParts::MojoShellConnectionStarted( |
| 1356 content::MojoShellConnection* connection) { | 1357 content::MojoShellConnection* connection) { |
| (...skipping 852 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2209 chromeos::CrosSettings::Shutdown(); | 2210 chromeos::CrosSettings::Shutdown(); |
| 2210 #endif // defined(OS_CHROMEOS) | 2211 #endif // defined(OS_CHROMEOS) |
| 2211 #endif // defined(OS_ANDROID) | 2212 #endif // defined(OS_ANDROID) |
| 2212 } | 2213 } |
| 2213 | 2214 |
| 2214 // Public members: | 2215 // Public members: |
| 2215 | 2216 |
| 2216 void ChromeBrowserMainParts::AddParts(ChromeBrowserMainExtraParts* parts) { | 2217 void ChromeBrowserMainParts::AddParts(ChromeBrowserMainExtraParts* parts) { |
| 2217 chrome_extra_parts_.push_back(parts); | 2218 chrome_extra_parts_.push_back(parts); |
| 2218 } | 2219 } |
| OLD | NEW |