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/prefs/chrome_pref_service_factory.h" | 5 #include "chrome/browser/prefs/chrome_pref_service_factory.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/debug/trace_event.h" | 8 #include "base/debug/trace_event.h" |
9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
11 #include "base/metrics/field_trial.h" | |
11 #include "base/metrics/histogram.h" | 12 #include "base/metrics/histogram.h" |
12 #include "base/prefs/default_pref_store.h" | 13 #include "base/prefs/default_pref_store.h" |
13 #include "base/prefs/json_pref_store.h" | 14 #include "base/prefs/json_pref_store.h" |
14 #include "base/prefs/pref_notifier_impl.h" | 15 #include "base/prefs/pref_notifier_impl.h" |
15 #include "base/prefs/pref_registry.h" | 16 #include "base/prefs/pref_registry.h" |
16 #include "base/prefs/pref_service.h" | 17 #include "base/prefs/pref_service.h" |
17 #include "base/prefs/pref_value_store.h" | 18 #include "base/prefs/pref_value_store.h" |
18 #include "chrome/browser/browser_process.h" | 19 #include "chrome/browser/browser_process.h" |
19 #include "chrome/browser/prefs/command_line_pref_store.h" | 20 #include "chrome/browser/prefs/command_line_pref_store.h" |
20 #include "chrome/browser/prefs/pref_hash_filter.h" | 21 #include "chrome/browser/prefs/pref_hash_filter.h" |
21 #include "chrome/browser/prefs/pref_hash_store.h" | 22 #include "chrome/browser/prefs/pref_hash_store.h" |
22 #include "chrome/browser/prefs/pref_model_associator.h" | 23 #include "chrome/browser/prefs/pref_model_associator.h" |
23 #include "chrome/browser/prefs/pref_service_syncable.h" | 24 #include "chrome/browser/prefs/pref_service_syncable.h" |
24 #include "chrome/browser/prefs/pref_service_syncable_factory.h" | 25 #include "chrome/browser/prefs/pref_service_syncable_factory.h" |
25 #include "chrome/browser/ui/profile_error_dialog.h" | 26 #include "chrome/browser/ui/profile_error_dialog.h" |
27 #include "chrome/common/pref_names.h" | |
26 #include "components/user_prefs/pref_registry_syncable.h" | 28 #include "components/user_prefs/pref_registry_syncable.h" |
27 #include "content/public/browser/browser_context.h" | 29 #include "content/public/browser/browser_context.h" |
28 #include "content/public/browser/browser_thread.h" | 30 #include "content/public/browser/browser_thread.h" |
29 #include "grit/chromium_strings.h" | 31 #include "grit/chromium_strings.h" |
30 #include "grit/generated_resources.h" | 32 #include "grit/generated_resources.h" |
31 | 33 |
32 #if defined(ENABLE_CONFIGURATION_POLICY) | 34 #if defined(ENABLE_CONFIGURATION_POLICY) |
33 #include "chrome/browser/policy/browser_policy_connector.h" | 35 #include "chrome/browser/policy/browser_policy_connector.h" |
34 #include "components/policy/core/browser/configuration_policy_pref_store.h" | 36 #include "components/policy/core/browser/configuration_policy_pref_store.h" |
35 #include "components/policy/core/common/policy_types.h" | 37 #include "components/policy/core/common/policy_types.h" |
36 #endif | 38 #endif |
37 | 39 |
38 #if defined(ENABLE_MANAGED_USERS) | 40 #if defined(ENABLE_MANAGED_USERS) |
39 #include "chrome/browser/managed_mode/supervised_user_pref_store.h" | 41 #include "chrome/browser/managed_mode/supervised_user_pref_store.h" |
40 #endif | 42 #endif |
41 | 43 |
42 using content::BrowserContext; | 44 using content::BrowserContext; |
43 using content::BrowserThread; | 45 using content::BrowserThread; |
44 | 46 |
45 namespace { | 47 namespace { |
46 | 48 |
49 // These preferences must be kept in sync with the TrackedPreference enum in | |
50 // tools/metrics/histograms/histograms.xml. To add a new preference, append it | |
51 // to the array and add a corresponding value to the histogram enum. Each | |
52 // tracked preference must be given a unique reporting ID. | |
53 const PrefHashFilter::TrackedPreference kTrackedPrefs[] = { | |
54 { 0, prefs::kShowHomeButton, true }, | |
55 { 1, prefs::kHomePageIsNewTabPage, true }, | |
56 { 2, prefs::kHomePage, true }, | |
57 { 3, prefs::kRestoreOnStartup, true }, | |
58 { 4, prefs::kURLsToRestoreOnStartup, true }, | |
59 { 5, prefs::kExtensionsPref, false }, | |
60 { 6, prefs::kGoogleServicesLastUsername, true }, | |
61 { 7, prefs::kSearchProviderOverrides, true }, | |
62 { 8, prefs::kDefaultSearchProviderSearchURL, true }, | |
63 { 9, prefs::kDefaultSearchProviderKeyword, true }, | |
64 { 10, prefs::kDefaultSearchProviderName, true }, | |
65 #if !defined(OS_ANDROID) | |
66 { 11, prefs::kPinnedTabs, true }, | |
67 #endif | |
68 { 12, prefs::kExtensionKnownDisabled, true }, | |
69 { 13, prefs::kProfileResetPromptMemento, true }, | |
70 }; | |
71 | |
72 // The count of tracked preferences IDs across all platforms. | |
73 const size_t kTrackedPrefsReportingIDsCount = 14; | |
gab
2014/01/02 18:40:22
@erikwright pointed out that this might not be nec
Mark P
2014/01/02 19:32:46
erikwright@ is correct that this is not strictly n
| |
74 COMPILE_ASSERT(kTrackedPrefsReportingIDsCount >= arraysize(kTrackedPrefs), | |
75 need_to_increment_ids_count); | |
76 | |
77 PrefHashFilter::EnforcementLevel GetSettingsEnforcementLevel() { | |
78 static const char kSettingsEnforcementExperiment[] = "SettingsEnforcement"; | |
79 struct { | |
80 PrefHashFilter::EnforcementLevel level; | |
erikwright (departed)
2014/01/03 19:08:13
nit: I would reverse this since, intuitively, a ma
gab
2014/01/03 19:26:09
Reversed the mapping (i.e., name first).
I still
| |
81 const char* level_name; | |
82 } static const kEnforcementLevelMap[] = { | |
83 { | |
84 PrefHashFilter::NO_ENFORCEMENT, | |
85 "no_enforcement" | |
86 }, | |
87 { | |
88 PrefHashFilter::ENFORCE, | |
89 "enforce" | |
90 }, | |
91 { | |
92 PrefHashFilter::ENFORCE_NO_SEEDING, | |
93 "enforce_no_seeding" | |
94 }, | |
95 { | |
96 PrefHashFilter::ENFORCE_NO_SEEDING_NO_MIGRATION, | |
97 "enforce_no_seeding_no_migration" | |
98 }, | |
99 }; | |
100 | |
101 base::FieldTrial* trial = | |
102 base::FieldTrialList::Find(kSettingsEnforcementExperiment); | |
103 if (trial) { | |
104 const std::string& group_name = trial->group_name(); | |
105 for (size_t i = 0; i < arraysize(kEnforcementLevelMap); ++i) { | |
106 if (kEnforcementLevelMap[i].level_name == group_name) | |
107 return kEnforcementLevelMap[i].level; | |
108 } | |
109 } | |
110 // TODO(gab): Switch default to ENFORCE_ALL when field trial config is up. | |
111 return PrefHashFilter::NO_ENFORCEMENT; | |
112 } | |
113 | |
47 // Shows notifications which correspond to PersistentPrefStore's reading errors. | 114 // Shows notifications which correspond to PersistentPrefStore's reading errors. |
48 void HandleReadError(PersistentPrefStore::PrefReadError error) { | 115 void HandleReadError(PersistentPrefStore::PrefReadError error) { |
49 // Sample the histogram also for the successful case in order to get a | 116 // Sample the histogram also for the successful case in order to get a |
50 // baseline on the success rate in addition to the error distribution. | 117 // baseline on the success rate in addition to the error distribution. |
51 UMA_HISTOGRAM_ENUMERATION("PrefService.ReadError", error, | 118 UMA_HISTOGRAM_ENUMERATION("PrefService.ReadError", error, |
52 PersistentPrefStore::PREF_READ_ERROR_MAX_ENUM); | 119 PersistentPrefStore::PREF_READ_ERROR_MAX_ENUM); |
53 | 120 |
54 if (error != PersistentPrefStore::PREF_READ_ERROR_NONE) { | 121 if (error != PersistentPrefStore::PREF_READ_ERROR_NONE) { |
55 #if !defined(OS_CHROMEOS) | 122 #if !defined(OS_CHROMEOS) |
56 // Failing to load prefs on startup is a bad thing(TM). See bug 38352 for | 123 // Failing to load prefs on startup is a bad thing(TM). See bug 38352 for |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
119 } | 186 } |
120 #endif | 187 #endif |
121 | 188 |
122 factory->set_async(async); | 189 factory->set_async(async); |
123 factory->set_extension_prefs(extension_prefs); | 190 factory->set_extension_prefs(extension_prefs); |
124 factory->set_command_line_prefs( | 191 factory->set_command_line_prefs( |
125 make_scoped_refptr( | 192 make_scoped_refptr( |
126 new CommandLinePrefStore(CommandLine::ForCurrentProcess()))); | 193 new CommandLinePrefStore(CommandLine::ForCurrentProcess()))); |
127 factory->set_read_error_callback(base::Bind(&HandleReadError)); | 194 factory->set_read_error_callback(base::Bind(&HandleReadError)); |
128 scoped_ptr<PrefFilter> pref_filter; | 195 scoped_ptr<PrefFilter> pref_filter; |
129 if (pref_hash_store) | 196 if (pref_hash_store) { |
130 pref_filter.reset(new PrefHashFilter(pref_hash_store.Pass())); | 197 pref_filter.reset(new PrefHashFilter(pref_hash_store.Pass(), |
198 kTrackedPrefs, | |
199 arraysize(kTrackedPrefs), | |
200 kTrackedPrefsReportingIDsCount, | |
201 GetSettingsEnforcementLevel())); | |
202 } | |
131 factory->set_user_prefs( | 203 factory->set_user_prefs( |
132 new JsonPrefStore( | 204 new JsonPrefStore( |
133 pref_filename, | 205 pref_filename, |
134 pref_io_task_runner, | 206 pref_io_task_runner, |
135 pref_filter.Pass())); | 207 pref_filter.Pass())); |
136 } | 208 } |
137 | 209 |
138 } // namespace | 210 } // namespace |
139 | 211 |
140 namespace chrome_prefs { | 212 namespace chrome_prefs { |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
173 pref_io_task_runner, | 245 pref_io_task_runner, |
174 policy_service, | 246 policy_service, |
175 managed_user_settings, | 247 managed_user_settings, |
176 pref_hash_store.Pass(), | 248 pref_hash_store.Pass(), |
177 extension_prefs, | 249 extension_prefs, |
178 async); | 250 async); |
179 return factory.CreateSyncable(pref_registry.get()); | 251 return factory.CreateSyncable(pref_registry.get()); |
180 } | 252 } |
181 | 253 |
182 } // namespace chrome_prefs | 254 } // namespace chrome_prefs |
OLD | NEW |