1 // Copyright 2016 The Chromium Authors 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #include "components/metrics/enabled_state_provider.h" 6 7 #include "base/base_switches.h" 8 #include "base/command_line.h" 9 10 namespace metrics { 11 12 namespace { 13 // Some browser_tests enable metrics reporting independent of the presence of 14 // kForceFieldTrials: 15 // - MetricsServiceBrowserFilesTest.FilesRemain 16 // - MetricsInternalsUIBrowserTestWithLog.All 17 bool g_ignore_force_field_trials_for_testing = false; 18 } // namespace 19 IsReportingEnabled() const20bool EnabledStateProvider::IsReportingEnabled() const { 21 // Disable metrics reporting when field trials are forced, as otherwise this 22 // would pollute experiment results in UMA. Note: This is done here and not 23 // in IsConsentGiven() as we do not want this to affect field trial entropy 24 // logic (i.e. high entropy source should still be used if UMA is on). 25 return IsConsentGiven() && 26 (g_ignore_force_field_trials_for_testing || 27 !base::CommandLine::ForCurrentProcess()->HasSwitch( 28 switches::kForceFieldTrials)); 29 } 30 SetIgnoreForceFieldTrialsForTesting(bool ignore_trials)31void EnabledStateProvider::SetIgnoreForceFieldTrialsForTesting( 32 bool ignore_trials) { 33 g_ignore_force_field_trials_for_testing = ignore_trials; 34 } 35 36 } // namespace metrics 37