Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(206)

Side by Side Diff: chrome/browser/chrome_browser_main.cc

Issue 2342993002: Rearrange SetupMetricsAndFieldTrials to SetupFieldTrials and SetupMetrics (Closed)
Patch Set: CR Feedback Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/browser/chrome_browser_main.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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
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 }
940 938
941 void ChromeBrowserMainParts::StartMetricsRecording() { 939 void ChromeBrowserMainParts::StartMetricsRecording() {
942 TRACE_EVENT0("startup", "ChromeBrowserMainParts::StartMetricsRecording"); 940 TRACE_EVENT0("startup", "ChromeBrowserMainParts::StartMetricsRecording");
943 941
944 g_browser_process->metrics_service()->CheckForClonedInstall( 942 g_browser_process->metrics_service()->CheckForClonedInstall(
945 BrowserThread::GetTaskRunnerForThread(BrowserThread::FILE)); 943 BrowserThread::GetTaskRunnerForThread(BrowserThread::FILE));
946 944
947 g_browser_process->GetMetricsServicesManager()->UpdateUploadPermissions(true); 945 g_browser_process->GetMetricsServicesManager()->UpdateUploadPermissions(true);
948 } 946 }
949 947
(...skipping 363 matching lines...) Expand 10 before | Expand all | Expand 10 after
1313 // thread, which has a proper CFRunloop, instead of later on the I/O thread, 1311 // 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 1312 // which doesn't. This ensures those notifications will get delivered
1315 // properly. See issue 37766. 1313 // properly. See issue 37766.
1316 // (Note that the callback mask here is empty. I don't want to register for 1314 // (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.) 1315 // any callbacks, I just want to initialize the mechanism.)
1318 SecKeychainAddCallback(&KeychainCallback, 0, NULL); 1316 SecKeychainAddCallback(&KeychainCallback, 0, NULL);
1319 #endif // defined(OS_MACOSX) 1317 #endif // defined(OS_MACOSX)
1320 1318
1321 #if defined(OS_CHROMEOS) 1319 #if defined(OS_CHROMEOS)
1322 // Must be done after g_browser_process is constructed, before 1320 // Must be done after g_browser_process is constructed, before
1323 // SetupMetricsAndFieldTrials(). 1321 // SetupFieldTrials() and SetupMetrics().
1324 chromeos::CrosSettings::Initialize(); 1322 chromeos::CrosSettings::Initialize();
1325 #endif // defined(OS_CHROMEOS) 1323 #endif // defined(OS_CHROMEOS)
1326 1324
1327 SetupOriginTrialsCommandLine(); 1325 SetupOriginTrialsCommandLine();
1328 1326
1329 // Now the command line has been mutated based on about:flags, we can setup 1327 // 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 1328 // initialize field trials and setup metrics. The field trials are needed by
1331 // IOThread's initialization which happens in BrowserProcess:PreCreateThreads. 1329 // IOThread's initialization which happens in BrowserProcess:PreCreateThreads.
1332 SetupMetricsAndFieldTrials(); 1330 SetupFieldTrials();
1331 SetupMetrics();
1333 1332
1334 // ChromeOS needs ResourceBundle::InitSharedInstance to be called before this. 1333 // ChromeOS needs ResourceBundle::InitSharedInstance to be called before this.
1335 browser_process_->PreCreateThreads(); 1334 browser_process_->PreCreateThreads();
1336 1335
1337 device::GeolocationProvider::SetGeolocationDelegate( 1336 device::GeolocationProvider::SetGeolocationDelegate(
1338 new ChromeGeolocationDelegate()); 1337 new ChromeGeolocationDelegate());
1339 1338
1340 // This needs to be the last thing in PreCreateThreads() because the 1339 // This needs to be the last thing in PreCreateThreads() because the
1341 // TaskScheduler needs to be created before any other threads are (by 1340 // TaskScheduler needs to be created before any other threads are (by
1342 // contract) but it creates threads itself so instantiating it earlier is also 1341 // contract) but it creates threads itself so instantiating it earlier is also
1343 // incorrect. It also has to be after SetupMetricsAndFieldTrials() to allow it 1342 // 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 1343 // 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 1344 // being in chrome/ is convenient for now as the initialization uses
1346 // initialization uses variations parameters extensively. 1345 // variations parameters extensively.
1347 // 1346 //
1348 // To maintain scoping symmetry, if this line is moved, the corresponding 1347 // To maintain scoping symmetry, if this line is moved, the corresponding
1349 // shutdown call may also need to be moved. 1348 // shutdown call may also need to be moved.
1350 MaybeInitializeTaskScheduler(); 1349 MaybeInitializeTaskScheduler();
1351 1350
1352 return content::RESULT_CODE_NORMAL_EXIT; 1351 return content::RESULT_CODE_NORMAL_EXIT;
1353 } 1352 }
1354 1353
1355 void ChromeBrowserMainParts::MojoShellConnectionStarted( 1354 void ChromeBrowserMainParts::MojoShellConnectionStarted(
1356 content::MojoShellConnection* connection) { 1355 content::MojoShellConnection* connection) {
(...skipping 852 matching lines...) Expand 10 before | Expand all | Expand 10 after
2209 chromeos::CrosSettings::Shutdown(); 2208 chromeos::CrosSettings::Shutdown();
2210 #endif // defined(OS_CHROMEOS) 2209 #endif // defined(OS_CHROMEOS)
2211 #endif // defined(OS_ANDROID) 2210 #endif // defined(OS_ANDROID)
2212 } 2211 }
2213 2212
2214 // Public members: 2213 // Public members:
2215 2214
2216 void ChromeBrowserMainParts::AddParts(ChromeBrowserMainExtraParts* parts) { 2215 void ChromeBrowserMainParts::AddParts(ChromeBrowserMainExtraParts* parts) {
2217 chrome_extra_parts_.push_back(parts); 2216 chrome_extra_parts_.push_back(parts);
2218 } 2217 }
OLDNEW
« no previous file with comments | « chrome/browser/chrome_browser_main.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698