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
3 // found in the LICENSE file.
5 #include "chrome/browser/net/async_dns_field_trial.h"
7 #include "base/metrics/field_trial.h"
8 #include "base/metrics/histogram.h"
9 #include "base/strings/string_util.h"
10 #include "build/build_config.h"
12 namespace chrome_browser_net
{
16 // Source of the default value of the async DNS pref; used in histograms.
17 enum PrefDefaultSource
{
21 MAX_PREF_DEFAULT_SOURCE
24 // Source of the actual value of the async DNS pref; used in histograms.
37 void HistogramPrefDefaultSource(PrefDefaultSource source
, bool enabled
) {
39 UMA_HISTOGRAM_ENUMERATION("AsyncDNS.PrefDefaultSource_Enabled",
41 MAX_PREF_DEFAULT_SOURCE
);
43 UMA_HISTOGRAM_ENUMERATION("AsyncDNS.PrefDefaultSource_Disabled",
45 MAX_PREF_DEFAULT_SOURCE
);
49 void HistogramPrefSource(PrefSource source
, bool enabled
) {
51 UMA_HISTOGRAM_ENUMERATION("AsyncDNS.PrefSource_Enabled",
55 UMA_HISTOGRAM_ENUMERATION("AsyncDNS.PrefSource_Disabled",
63 bool ConfigureAsyncDnsFieldTrial() {
64 #if defined(OS_ANDROID) || defined(OS_IOS)
65 // There is no DnsConfigService on those platforms so disable the field trial.
66 HistogramPrefDefaultSource(PLATFORM
, false);
70 #if defined(OS_CHROMEOS) || defined(OS_MACOSX)
71 const bool kDefault
= true;
73 const bool kDefault
= false;
76 // Configure the AsyncDns field trial as follows:
77 // groups AsyncDnsA and AsyncDnsB: return true,
78 // groups SystemDnsA and SystemDnsB: return false,
79 // otherwise (trial absent): return default.
80 std::string group_name
= base::FieldTrialList::FindFullName("AsyncDns");
81 if (!group_name
.empty()) {
82 const bool enabled
= base::StartsWith(group_name
, "AsyncDns",
83 base::CompareCase::INSENSITIVE_ASCII
);
84 HistogramPrefDefaultSource(FIELD_TRIAL
, enabled
);
87 HistogramPrefDefaultSource(HARD_CODED_DEFAULT
, kDefault
);
91 void LogAsyncDnsPrefSource(const PrefService::Preference
* pref
) {
94 const base::Value
* value
= pref
->GetValue();
98 bool got_value
= value
->GetAsBoolean(&enabled
);
101 if (pref
->IsManaged())
102 HistogramPrefSource(MANAGED_PREF
, enabled
);
103 else if (pref
->IsExtensionControlled())
104 HistogramPrefSource(EXTENSION_PREF
, enabled
);
105 else if (pref
->IsUserControlled())
106 HistogramPrefSource(USER_PREF
, enabled
);
107 else if (pref
->IsDefaultValue())
108 HistogramPrefSource(DEFAULT_PREF
, enabled
);
110 HistogramPrefSource(UNKNOWN_PREF
, enabled
);
113 } // namespace chrome_browser_net