Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(339)

Side by Side Diff: chrome/browser/prefs/profile_pref_store_manager.cc

Issue 2396443002: Revert of Integrate registry_hash_store_contents with the rest of tracked prefs. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/profile_pref_store_manager.h" 5 #include "chrome/browser/prefs/profile_pref_store_manager.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/callback.h" 10 #include "base/callback.h"
11 #include "base/files/file_util.h" 11 #include "base/files/file_util.h"
12 #include "base/json/json_file_value_serializer.h" 12 #include "base/json/json_file_value_serializer.h"
13 #include "base/logging.h" 13 #include "base/logging.h"
14 #include "base/memory/ptr_util.h"
15 #include "base/metrics/histogram_macros.h" 14 #include "base/metrics/histogram_macros.h"
16 #include "base/sequenced_task_runner.h" 15 #include "base/sequenced_task_runner.h"
17 #include "build/build_config.h" 16 #include "build/build_config.h"
18 #include "chrome/common/chrome_constants.h" 17 #include "chrome/common/chrome_constants.h"
19 #include "components/pref_registry/pref_registry_syncable.h" 18 #include "components/pref_registry/pref_registry_syncable.h"
20 #include "components/prefs/json_pref_store.h" 19 #include "components/prefs/json_pref_store.h"
21 #include "components/prefs/persistent_pref_store.h" 20 #include "components/prefs/persistent_pref_store.h"
22 #include "components/prefs/pref_registry_simple.h" 21 #include "components/prefs/pref_registry_simple.h"
23 #include "components/user_prefs/tracked/pref_hash_store_impl.h" 22 #include "components/user_prefs/tracked/pref_hash_store_impl.h"
24 #include "components/user_prefs/tracked/segregated_pref_store.h" 23 #include "components/user_prefs/tracked/segregated_pref_store.h"
25 #include "components/user_prefs/tracked/tracked_preferences_migration.h" 24 #include "components/user_prefs/tracked/tracked_preferences_migration.h"
26 25
27 #if defined(OS_WIN)
28 #include "chrome/installer/util/browser_distribution.h"
29 #include "components/user_prefs/tracked/registry_hash_store_contents_win.h"
30 #endif
31
32 namespace { 26 namespace {
33 27
34 void RemoveValueSilently(const base::WeakPtr<JsonPrefStore> pref_store, 28 void RemoveValueSilently(const base::WeakPtr<JsonPrefStore> pref_store,
35 const std::string& key) { 29 const std::string& key) {
36 if (pref_store) { 30 if (pref_store) {
37 pref_store->RemoveValueSilently( 31 pref_store->RemoveValueSilently(
38 key, WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS); 32 key, WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS);
39 } 33 }
40 } 34 }
41 35
42 #if defined(OS_WIN)
43 // Forces a different registry key to be used for storing preference validation
44 // MACs. See |SetPreferenceValidationRegistryPathForTesting|.
45 const base::string16* g_preference_validation_registry_path_for_testing =
46 nullptr;
47 #endif // OS_WIN
48
49 } // namespace 36 } // namespace
50 37
51 // Preference tracking and protection is not required on platforms where other 38 // Preference tracking and protection is not required on platforms where other
52 // apps do not have access to chrome's persistent storage. 39 // apps do not have access to chrome's persistent storage.
53 const bool ProfilePrefStoreManager::kPlatformSupportsPreferenceTracking = 40 const bool ProfilePrefStoreManager::kPlatformSupportsPreferenceTracking =
54 #if defined(OS_ANDROID) || defined(OS_CHROMEOS) 41 #if defined(OS_ANDROID) || defined(OS_CHROMEOS)
55 false; 42 false;
56 #else 43 #else
57 true; 44 true;
58 #endif 45 #endif
(...skipping 24 matching lines...) Expand all
83 // static 70 // static
84 base::Time ProfilePrefStoreManager::GetResetTime(PrefService* pref_service) { 71 base::Time ProfilePrefStoreManager::GetResetTime(PrefService* pref_service) {
85 return PrefHashFilter::GetResetTime(pref_service); 72 return PrefHashFilter::GetResetTime(pref_service);
86 } 73 }
87 74
88 // static 75 // static
89 void ProfilePrefStoreManager::ClearResetTime(PrefService* pref_service) { 76 void ProfilePrefStoreManager::ClearResetTime(PrefService* pref_service) {
90 PrefHashFilter::ClearResetTime(pref_service); 77 PrefHashFilter::ClearResetTime(pref_service);
91 } 78 }
92 79
93 #if defined(OS_WIN)
94 // static
95 void ProfilePrefStoreManager::SetPreferenceValidationRegistryPathForTesting(
96 const base::string16* path) {
97 DCHECK(!path->empty());
98 g_preference_validation_registry_path_for_testing = path;
99 }
100 #endif // OS_WIN
101
102 PersistentPrefStore* ProfilePrefStoreManager::CreateProfilePrefStore( 80 PersistentPrefStore* ProfilePrefStoreManager::CreateProfilePrefStore(
103 const scoped_refptr<base::SequencedTaskRunner>& io_task_runner, 81 const scoped_refptr<base::SequencedTaskRunner>& io_task_runner,
104 const base::Closure& on_reset_on_load, 82 const base::Closure& on_reset_on_load,
105 TrackedPreferenceValidationDelegate* validation_delegate) { 83 TrackedPreferenceValidationDelegate* validation_delegate) {
106 std::unique_ptr<PrefFilter> pref_filter; 84 std::unique_ptr<PrefFilter> pref_filter;
107 if (!kPlatformSupportsPreferenceTracking) { 85 if (!kPlatformSupportsPreferenceTracking) {
108 return new JsonPrefStore(profile_path_.Append(chrome::kPreferencesFilename), 86 return new JsonPrefStore(profile_path_.Append(chrome::kPreferencesFilename),
109 io_task_runner.get(), 87 io_task_runner.get(),
110 std::unique_ptr<PrefFilter>()); 88 std::unique_ptr<PrefFilter>());
111 } 89 }
(...skipping 11 matching lines...) Expand all
123 if (it->enforcement_level > PrefHashFilter::NO_ENFORCEMENT) { 101 if (it->enforcement_level > PrefHashFilter::NO_ENFORCEMENT) {
124 protected_configuration.push_back(*it); 102 protected_configuration.push_back(*it);
125 protected_pref_names.insert(it->name); 103 protected_pref_names.insert(it->name);
126 } else { 104 } else {
127 unprotected_configuration.push_back(*it); 105 unprotected_configuration.push_back(*it);
128 unprotected_pref_names.insert(it->name); 106 unprotected_pref_names.insert(it->name);
129 } 107 }
130 } 108 }
131 109
132 std::unique_ptr<PrefHashFilter> unprotected_pref_hash_filter( 110 std::unique_ptr<PrefHashFilter> unprotected_pref_hash_filter(
133 new PrefHashFilter(GetPrefHashStore(false), 111 new PrefHashFilter(GetPrefHashStore(false), unprotected_configuration,
134 GetExternalVerificationPrefHashStorePair(), 112 base::Closure(), validation_delegate,
135 unprotected_configuration, base::Closure(), 113 reporting_ids_count_, false));
136 validation_delegate, reporting_ids_count_, false));
137 std::unique_ptr<PrefHashFilter> protected_pref_hash_filter(new PrefHashFilter( 114 std::unique_ptr<PrefHashFilter> protected_pref_hash_filter(new PrefHashFilter(
138 GetPrefHashStore(true), GetExternalVerificationPrefHashStorePair(), 115 GetPrefHashStore(true), protected_configuration, on_reset_on_load,
139 protected_configuration, on_reset_on_load, validation_delegate, 116 validation_delegate, reporting_ids_count_, true));
140 reporting_ids_count_, true));
141 117
142 PrefHashFilter* raw_unprotected_pref_hash_filter = 118 PrefHashFilter* raw_unprotected_pref_hash_filter =
143 unprotected_pref_hash_filter.get(); 119 unprotected_pref_hash_filter.get();
144 PrefHashFilter* raw_protected_pref_hash_filter = 120 PrefHashFilter* raw_protected_pref_hash_filter =
145 protected_pref_hash_filter.get(); 121 protected_pref_hash_filter.get();
146 122
147 scoped_refptr<JsonPrefStore> unprotected_pref_store(new JsonPrefStore( 123 scoped_refptr<JsonPrefStore> unprotected_pref_store(new JsonPrefStore(
148 profile_path_.Append(chrome::kPreferencesFilename), io_task_runner.get(), 124 profile_path_.Append(chrome::kPreferencesFilename), io_task_runner.get(),
149 std::move(unprotected_pref_hash_filter))); 125 std::move(unprotected_pref_hash_filter)));
150 // TODO(gab): Remove kDeprecatedProtectedPreferencesFilename as an alternate 126 // TODO(gab): Remove kDeprecatedProtectedPreferencesFilename as an alternate
(...skipping 25 matching lines...) Expand all
176 if (!base::CreateDirectory(profile_path_)) 152 if (!base::CreateDirectory(profile_path_))
177 return false; 153 return false;
178 154
179 const base::DictionaryValue* to_serialize = &master_prefs; 155 const base::DictionaryValue* to_serialize = &master_prefs;
180 std::unique_ptr<base::DictionaryValue> copy; 156 std::unique_ptr<base::DictionaryValue> copy;
181 157
182 if (kPlatformSupportsPreferenceTracking) { 158 if (kPlatformSupportsPreferenceTracking) {
183 copy.reset(master_prefs.DeepCopy()); 159 copy.reset(master_prefs.DeepCopy());
184 to_serialize = copy.get(); 160 to_serialize = copy.get();
185 PrefHashFilter(GetPrefHashStore(false), 161 PrefHashFilter(GetPrefHashStore(false),
186 GetExternalVerificationPrefHashStorePair(), 162 tracking_configuration_,
187 tracking_configuration_, base::Closure(), NULL, 163 base::Closure(),
188 reporting_ids_count_, false) 164 NULL,
189 .Initialize(copy.get()); 165 reporting_ids_count_,
166 false).Initialize(copy.get());
190 } 167 }
191 168
192 // This will write out to a single combined file which will be immediately 169 // This will write out to a single combined file which will be immediately
193 // migrated to two files on load. 170 // migrated to two files on load.
194 JSONFileValueSerializer serializer( 171 JSONFileValueSerializer serializer(
195 profile_path_.Append(chrome::kPreferencesFilename)); 172 profile_path_.Append(chrome::kPreferencesFilename));
196 173
197 // Call Serialize (which does IO) on the main thread, which would _normally_ 174 // Call Serialize (which does IO) on the main thread, which would _normally_
198 // be verboten. In this case however, we require this IO to synchronously 175 // be verboten. In this case however, we require this IO to synchronously
199 // complete before Chrome can start (as master preferences seed the Local 176 // complete before Chrome can start (as master preferences seed the Local
200 // State and Preferences files). This won't trip ThreadIORestrictions as they 177 // State and Preferences files). This won't trip ThreadIORestrictions as they
201 // won't have kicked in yet on the main thread. 178 // won't have kicked in yet on the main thread.
202 bool success = serializer.Serialize(*to_serialize); 179 bool success = serializer.Serialize(*to_serialize);
203 180
204 UMA_HISTOGRAM_BOOLEAN("Settings.InitializedFromMasterPrefs", success); 181 UMA_HISTOGRAM_BOOLEAN("Settings.InitializedFromMasterPrefs", success);
205 return success; 182 return success;
206 } 183 }
207 184
208 std::unique_ptr<PrefHashStore> ProfilePrefStoreManager::GetPrefHashStore( 185 std::unique_ptr<PrefHashStore> ProfilePrefStoreManager::GetPrefHashStore(
209 bool use_super_mac) { 186 bool use_super_mac) {
210 DCHECK(kPlatformSupportsPreferenceTracking); 187 DCHECK(kPlatformSupportsPreferenceTracking);
211 188
212 return std::unique_ptr<PrefHashStore>( 189 return std::unique_ptr<PrefHashStore>(
213 new PrefHashStoreImpl(seed_, device_id_, use_super_mac)); 190 new PrefHashStoreImpl(seed_, device_id_, use_super_mac));
214 } 191 }
215
216 std::pair<std::unique_ptr<PrefHashStore>, std::unique_ptr<HashStoreContents>>
217 ProfilePrefStoreManager::GetExternalVerificationPrefHashStorePair() {
218 DCHECK(kPlatformSupportsPreferenceTracking);
219 #if defined(OS_WIN)
220 return std::make_pair(
221 base::MakeUnique<PrefHashStoreImpl>(
222 "ChromeRegistryHashStoreValidationSeed", device_id_,
223 false /* use_super_mac */),
224 g_preference_validation_registry_path_for_testing
225 ? base::MakeUnique<RegistryHashStoreContentsWin>(
226 *g_preference_validation_registry_path_for_testing,
227 profile_path_.BaseName().LossyDisplayName())
228 : base::MakeUnique<RegistryHashStoreContentsWin>(
229 BrowserDistribution::GetDistribution()->GetRegistryPath(),
230 profile_path_.BaseName().LossyDisplayName()));
231 #else
232 return std::make_pair(nullptr, nullptr);
233 #endif
234 }
OLDNEW
« no previous file with comments | « chrome/browser/prefs/profile_pref_store_manager.h ('k') | chrome/browser/prefs/tracked/pref_hash_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698