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; |
| 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 const char* level_name; |
| 81 PrefHashFilter::EnforcementLevel level; |
| 82 } static const kEnforcementLevelMap[] = { |
| 83 { |
| 84 "no_enforcement", |
| 85 PrefHashFilter::NO_ENFORCEMENT |
| 86 }, |
| 87 { |
| 88 "enforce", |
| 89 PrefHashFilter::ENFORCE |
| 90 }, |
| 91 { |
| 92 "enforce_no_seeding", |
| 93 PrefHashFilter::ENFORCE_NO_SEEDING |
| 94 }, |
| 95 { |
| 96 "enforce_no_seeding_no_migration", |
| 97 PrefHashFilter::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 // ARRAYSIZE_UNSAFE must be used since the array is declared locally; it is |
| 106 // only unsafe because it could not trigger a compile error on some |
| 107 // non-array pointer types; this is fine since kEnforcementLevelMap is |
| 108 // clearly an array. |
| 109 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kEnforcementLevelMap); ++i) { |
| 110 if (kEnforcementLevelMap[i].level_name == group_name) |
| 111 return kEnforcementLevelMap[i].level; |
| 112 } |
| 113 } |
| 114 // TODO(gab): Switch default to ENFORCE_ALL when the field trial config is up. |
| 115 return PrefHashFilter::NO_ENFORCEMENT; |
| 116 } |
| 117 |
47 // Shows notifications which correspond to PersistentPrefStore's reading errors. | 118 // Shows notifications which correspond to PersistentPrefStore's reading errors. |
48 void HandleReadError(PersistentPrefStore::PrefReadError error) { | 119 void HandleReadError(PersistentPrefStore::PrefReadError error) { |
49 // Sample the histogram also for the successful case in order to get a | 120 // 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. | 121 // baseline on the success rate in addition to the error distribution. |
51 UMA_HISTOGRAM_ENUMERATION("PrefService.ReadError", error, | 122 UMA_HISTOGRAM_ENUMERATION("PrefService.ReadError", error, |
52 PersistentPrefStore::PREF_READ_ERROR_MAX_ENUM); | 123 PersistentPrefStore::PREF_READ_ERROR_MAX_ENUM); |
53 | 124 |
54 if (error != PersistentPrefStore::PREF_READ_ERROR_NONE) { | 125 if (error != PersistentPrefStore::PREF_READ_ERROR_NONE) { |
55 #if !defined(OS_CHROMEOS) | 126 #if !defined(OS_CHROMEOS) |
56 // Failing to load prefs on startup is a bad thing(TM). See bug 38352 for | 127 // 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 } | 190 } |
120 #endif | 191 #endif |
121 | 192 |
122 factory->set_async(async); | 193 factory->set_async(async); |
123 factory->set_extension_prefs(extension_prefs); | 194 factory->set_extension_prefs(extension_prefs); |
124 factory->set_command_line_prefs( | 195 factory->set_command_line_prefs( |
125 make_scoped_refptr( | 196 make_scoped_refptr( |
126 new CommandLinePrefStore(CommandLine::ForCurrentProcess()))); | 197 new CommandLinePrefStore(CommandLine::ForCurrentProcess()))); |
127 factory->set_read_error_callback(base::Bind(&HandleReadError)); | 198 factory->set_read_error_callback(base::Bind(&HandleReadError)); |
128 scoped_ptr<PrefFilter> pref_filter; | 199 scoped_ptr<PrefFilter> pref_filter; |
129 if (pref_hash_store) | 200 if (pref_hash_store) { |
130 pref_filter.reset(new PrefHashFilter(pref_hash_store.Pass())); | 201 pref_filter.reset(new PrefHashFilter(pref_hash_store.Pass(), |
| 202 kTrackedPrefs, |
| 203 arraysize(kTrackedPrefs), |
| 204 kTrackedPrefsReportingIDsCount, |
| 205 GetSettingsEnforcementLevel())); |
| 206 } |
131 factory->set_user_prefs( | 207 factory->set_user_prefs( |
132 new JsonPrefStore( | 208 new JsonPrefStore( |
133 pref_filename, | 209 pref_filename, |
134 pref_io_task_runner, | 210 pref_io_task_runner, |
135 pref_filter.Pass())); | 211 pref_filter.Pass())); |
136 } | 212 } |
137 | 213 |
138 } // namespace | 214 } // namespace |
139 | 215 |
140 namespace chrome_prefs { | 216 namespace chrome_prefs { |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
173 pref_io_task_runner, | 249 pref_io_task_runner, |
174 policy_service, | 250 policy_service, |
175 managed_user_settings, | 251 managed_user_settings, |
176 pref_hash_store.Pass(), | 252 pref_hash_store.Pass(), |
177 extension_prefs, | 253 extension_prefs, |
178 async); | 254 async); |
179 return factory.CreateSyncable(pref_registry.get()); | 255 return factory.CreateSyncable(pref_registry.get()); |
180 } | 256 } |
181 | 257 |
182 } // namespace chrome_prefs | 258 } // namespace chrome_prefs |
OLD | NEW |