Only grant permissions to new extensions from sync if they have the expected version
[chromium-blink-merge.git] / chrome / browser / net / async_dns_field_trial.cc
blobb8ce85fd4226bfe993f2770be84eb32ae2e70b38
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 {
14 namespace {
16 // Source of the default value of the async DNS pref; used in histograms.
17 enum PrefDefaultSource {
18 PLATFORM,
19 FIELD_TRIAL,
20 HARD_CODED_DEFAULT,
21 MAX_PREF_DEFAULT_SOURCE
24 // Source of the actual value of the async DNS pref; used in histograms.
25 enum PrefSource {
26 MANAGED_PREF,
27 SUPERVISED_PREF,
28 EXTENSION_PREF,
29 COMMAND_LINE_PREF,
30 USER_PREF,
31 RECOMMENDED_PREF,
32 DEFAULT_PREF,
33 UNKNOWN_PREF,
34 MAX_PREF_SOURCE
37 void HistogramPrefDefaultSource(PrefDefaultSource source, bool enabled) {
38 if (enabled) {
39 UMA_HISTOGRAM_ENUMERATION("AsyncDNS.PrefDefaultSource_Enabled",
40 source,
41 MAX_PREF_DEFAULT_SOURCE);
42 } else {
43 UMA_HISTOGRAM_ENUMERATION("AsyncDNS.PrefDefaultSource_Disabled",
44 source,
45 MAX_PREF_DEFAULT_SOURCE);
49 void HistogramPrefSource(PrefSource source, bool enabled) {
50 if (enabled) {
51 UMA_HISTOGRAM_ENUMERATION("AsyncDNS.PrefSource_Enabled",
52 source,
53 MAX_PREF_SOURCE);
54 } else {
55 UMA_HISTOGRAM_ENUMERATION("AsyncDNS.PrefSource_Disabled",
56 source,
57 MAX_PREF_SOURCE);
61 } // namespace
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);
67 return false;
68 #endif
70 #if defined(OS_CHROMEOS) || defined(OS_MACOSX)
71 const bool kDefault = true;
72 #else
73 const bool kDefault = false;
74 #endif
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);
85 return enabled;
87 HistogramPrefDefaultSource(HARD_CODED_DEFAULT, kDefault);
88 return kDefault;
91 void LogAsyncDnsPrefSource(const PrefService::Preference* pref) {
92 CHECK(pref);
94 const base::Value* value = pref->GetValue();
95 CHECK(value);
97 bool enabled;
98 bool got_value = value->GetAsBoolean(&enabled);
99 CHECK(got_value);
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);
109 else
110 HistogramPrefSource(UNKNOWN_PREF, enabled);
113 } // namespace chrome_browser_net