OLD | NEW |
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 "components/user_prefs/tracked/tracked_preferences_migration.h" | 5 #include "components/user_prefs/tracked/tracked_preferences_migration.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" |
(...skipping 16 matching lines...) Expand all Loading... |
27 const std::set<std::string>& unprotected_pref_names, | 27 const std::set<std::string>& unprotected_pref_names, |
28 const std::set<std::string>& protected_pref_names, | 28 const std::set<std::string>& protected_pref_names, |
29 const base::Callback<void(const std::string& key)>& | 29 const base::Callback<void(const std::string& key)>& |
30 unprotected_store_cleaner, | 30 unprotected_store_cleaner, |
31 const base::Callback<void(const std::string& key)>& | 31 const base::Callback<void(const std::string& key)>& |
32 protected_store_cleaner, | 32 protected_store_cleaner, |
33 const base::Callback<void(const base::Closure&)>& | 33 const base::Callback<void(const base::Closure&)>& |
34 register_on_successful_unprotected_store_write_callback, | 34 register_on_successful_unprotected_store_write_callback, |
35 const base::Callback<void(const base::Closure&)>& | 35 const base::Callback<void(const base::Closure&)>& |
36 register_on_successful_protected_store_write_callback, | 36 register_on_successful_protected_store_write_callback, |
37 scoped_ptr<PrefHashStore> unprotected_pref_hash_store, | 37 std::unique_ptr<PrefHashStore> unprotected_pref_hash_store, |
38 scoped_ptr<PrefHashStore> protected_pref_hash_store, | 38 std::unique_ptr<PrefHashStore> protected_pref_hash_store, |
39 scoped_ptr<HashStoreContents> legacy_pref_hash_store, | 39 std::unique_ptr<HashStoreContents> legacy_pref_hash_store, |
40 InterceptablePrefFilter* unprotected_pref_filter, | 40 InterceptablePrefFilter* unprotected_pref_filter, |
41 InterceptablePrefFilter* protected_pref_filter); | 41 InterceptablePrefFilter* protected_pref_filter); |
42 | 42 |
43 private: | 43 private: |
44 friend class base::RefCounted<TrackedPreferencesMigrator>; | 44 friend class base::RefCounted<TrackedPreferencesMigrator>; |
45 | 45 |
46 enum PrefFilterID { | 46 enum PrefFilterID { |
47 UNPROTECTED_PREF_FILTER, | 47 UNPROTECTED_PREF_FILTER, |
48 PROTECTED_PREF_FILTER | 48 PROTECTED_PREF_FILTER |
49 }; | 49 }; |
50 | 50 |
51 ~TrackedPreferencesMigrator(); | 51 ~TrackedPreferencesMigrator(); |
52 | 52 |
53 // Stores the data coming in from the filter identified by |id| into this | 53 // Stores the data coming in from the filter identified by |id| into this |
54 // class and then calls MigrateIfReady(); | 54 // class and then calls MigrateIfReady(); |
55 void InterceptFilterOnLoad( | 55 void InterceptFilterOnLoad( |
56 PrefFilterID id, | 56 PrefFilterID id, |
57 const InterceptablePrefFilter::FinalizeFilterOnLoadCallback& | 57 const InterceptablePrefFilter::FinalizeFilterOnLoadCallback& |
58 finalize_filter_on_load, | 58 finalize_filter_on_load, |
59 scoped_ptr<base::DictionaryValue> prefs); | 59 std::unique_ptr<base::DictionaryValue> prefs); |
60 | 60 |
61 // Proceeds with migration if both |unprotected_prefs_| and |protected_prefs_| | 61 // Proceeds with migration if both |unprotected_prefs_| and |protected_prefs_| |
62 // have been set. | 62 // have been set. |
63 void MigrateIfReady(); | 63 void MigrateIfReady(); |
64 | 64 |
65 const std::set<std::string> unprotected_pref_names_; | 65 const std::set<std::string> unprotected_pref_names_; |
66 const std::set<std::string> protected_pref_names_; | 66 const std::set<std::string> protected_pref_names_; |
67 | 67 |
68 const base::Callback<void(const std::string& key)> unprotected_store_cleaner_; | 68 const base::Callback<void(const std::string& key)> unprotected_store_cleaner_; |
69 const base::Callback<void(const std::string& key)> protected_store_cleaner_; | 69 const base::Callback<void(const std::string& key)> protected_store_cleaner_; |
70 const base::Callback<void(const base::Closure&)> | 70 const base::Callback<void(const base::Closure&)> |
71 register_on_successful_unprotected_store_write_callback_; | 71 register_on_successful_unprotected_store_write_callback_; |
72 const base::Callback<void(const base::Closure&)> | 72 const base::Callback<void(const base::Closure&)> |
73 register_on_successful_protected_store_write_callback_; | 73 register_on_successful_protected_store_write_callback_; |
74 | 74 |
75 InterceptablePrefFilter::FinalizeFilterOnLoadCallback | 75 InterceptablePrefFilter::FinalizeFilterOnLoadCallback |
76 finalize_unprotected_filter_on_load_; | 76 finalize_unprotected_filter_on_load_; |
77 InterceptablePrefFilter::FinalizeFilterOnLoadCallback | 77 InterceptablePrefFilter::FinalizeFilterOnLoadCallback |
78 finalize_protected_filter_on_load_; | 78 finalize_protected_filter_on_load_; |
79 | 79 |
80 scoped_ptr<PrefHashStore> unprotected_pref_hash_store_; | 80 std::unique_ptr<PrefHashStore> unprotected_pref_hash_store_; |
81 scoped_ptr<PrefHashStore> protected_pref_hash_store_; | 81 std::unique_ptr<PrefHashStore> protected_pref_hash_store_; |
82 scoped_ptr<HashStoreContents> legacy_pref_hash_store_; | 82 std::unique_ptr<HashStoreContents> legacy_pref_hash_store_; |
83 | 83 |
84 scoped_ptr<base::DictionaryValue> unprotected_prefs_; | 84 std::unique_ptr<base::DictionaryValue> unprotected_prefs_; |
85 scoped_ptr<base::DictionaryValue> protected_prefs_; | 85 std::unique_ptr<base::DictionaryValue> protected_prefs_; |
86 | 86 |
87 DISALLOW_COPY_AND_ASSIGN(TrackedPreferencesMigrator); | 87 DISALLOW_COPY_AND_ASSIGN(TrackedPreferencesMigrator); |
88 }; | 88 }; |
89 | 89 |
90 // Invokes |store_cleaner| for every |keys_to_clean|. | 90 // Invokes |store_cleaner| for every |keys_to_clean|. |
91 void CleanupPrefStore( | 91 void CleanupPrefStore( |
92 const base::Callback<void(const std::string& key)>& store_cleaner, | 92 const base::Callback<void(const std::string& key)>& store_cleaner, |
93 const std::set<std::string>& keys_to_clean) { | 93 const std::set<std::string>& keys_to_clean) { |
94 for (std::set<std::string>::const_iterator it = keys_to_clean.begin(); | 94 for (std::set<std::string>::const_iterator it = keys_to_clean.begin(); |
95 it != keys_to_clean.end(); ++it) { | 95 it != keys_to_clean.end(); ++it) { |
(...skipping 19 matching lines...) Expand all Loading... |
115 } else { | 115 } else { |
116 CleanupPrefStore(source_store_cleaner, keys_to_clean); | 116 CleanupPrefStore(source_store_cleaner, keys_to_clean); |
117 } | 117 } |
118 } | 118 } |
119 | 119 |
120 // Removes hashes for |migrated_pref_names| from |origin_pref_store| using | 120 // Removes hashes for |migrated_pref_names| from |origin_pref_store| using |
121 // the configuration/implementation in |origin_pref_hash_store|. | 121 // the configuration/implementation in |origin_pref_hash_store|. |
122 void CleanupMigratedHashes(const std::set<std::string>& migrated_pref_names, | 122 void CleanupMigratedHashes(const std::set<std::string>& migrated_pref_names, |
123 PrefHashStore* origin_pref_hash_store, | 123 PrefHashStore* origin_pref_hash_store, |
124 base::DictionaryValue* origin_pref_store) { | 124 base::DictionaryValue* origin_pref_store) { |
125 scoped_ptr<PrefHashStoreTransaction> transaction( | 125 std::unique_ptr<PrefHashStoreTransaction> transaction( |
126 origin_pref_hash_store->BeginTransaction(scoped_ptr<HashStoreContents>( | 126 origin_pref_hash_store->BeginTransaction( |
127 new DictionaryHashStoreContents(origin_pref_store)))); | 127 std::unique_ptr<HashStoreContents>( |
| 128 new DictionaryHashStoreContents(origin_pref_store)))); |
128 for (std::set<std::string>::const_iterator it = migrated_pref_names.begin(); | 129 for (std::set<std::string>::const_iterator it = migrated_pref_names.begin(); |
129 it != migrated_pref_names.end(); | 130 it != migrated_pref_names.end(); |
130 ++it) { | 131 ++it) { |
131 transaction->ClearHash(*it); | 132 transaction->ClearHash(*it); |
132 } | 133 } |
133 } | 134 } |
134 | 135 |
135 // Copies the value of each pref in |pref_names| which is set in |old_store|, | 136 // Copies the value of each pref in |pref_names| which is set in |old_store|, |
136 // but not in |new_store| into |new_store|. Sets |old_store_needs_cleanup| to | 137 // but not in |new_store| into |new_store|. Sets |old_store_needs_cleanup| to |
137 // true if any old duplicates remain in |old_store| and sets |new_store_altered| | 138 // true if any old duplicates remain in |old_store| and sets |new_store_altered| |
138 // to true if any value was copied to |new_store|. | 139 // to true if any value was copied to |new_store|. |
139 void MigratePrefsFromOldToNewStore(const std::set<std::string>& pref_names, | 140 void MigratePrefsFromOldToNewStore(const std::set<std::string>& pref_names, |
140 base::DictionaryValue* old_store, | 141 base::DictionaryValue* old_store, |
141 base::DictionaryValue* new_store, | 142 base::DictionaryValue* new_store, |
142 PrefHashStore* new_hash_store, | 143 PrefHashStore* new_hash_store, |
143 HashStoreContents* legacy_hash_store, | 144 HashStoreContents* legacy_hash_store, |
144 bool* old_store_needs_cleanup, | 145 bool* old_store_needs_cleanup, |
145 bool* new_store_altered, | 146 bool* new_store_altered, |
146 bool* used_legacy_pref_hashes) { | 147 bool* used_legacy_pref_hashes) { |
147 const base::DictionaryValue* old_hash_store_contents = | 148 const base::DictionaryValue* old_hash_store_contents = |
148 DictionaryHashStoreContents(old_store).GetContents(); | 149 DictionaryHashStoreContents(old_store).GetContents(); |
149 const base::DictionaryValue* legacy_hash_store_contents = | 150 const base::DictionaryValue* legacy_hash_store_contents = |
150 legacy_hash_store->GetContents(); | 151 legacy_hash_store->GetContents(); |
151 scoped_ptr<PrefHashStoreTransaction> new_hash_store_transaction( | 152 std::unique_ptr<PrefHashStoreTransaction> new_hash_store_transaction( |
152 new_hash_store->BeginTransaction(scoped_ptr<HashStoreContents>( | 153 new_hash_store->BeginTransaction(std::unique_ptr<HashStoreContents>( |
153 new DictionaryHashStoreContents(new_store)))); | 154 new DictionaryHashStoreContents(new_store)))); |
154 | 155 |
155 for (std::set<std::string>::const_iterator it = pref_names.begin(); | 156 for (std::set<std::string>::const_iterator it = pref_names.begin(); |
156 it != pref_names.end(); | 157 it != pref_names.end(); |
157 ++it) { | 158 ++it) { |
158 const std::string& pref_name = *it; | 159 const std::string& pref_name = *it; |
159 const base::Value* value_in_old_store = NULL; | 160 const base::Value* value_in_old_store = NULL; |
160 | 161 |
161 // If the destination does not have a hash for this pref we will | 162 // If the destination does not have a hash for this pref we will |
162 // unconditionally attempt to move it. | 163 // unconditionally attempt to move it. |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
209 TrackedPreferencesMigrator::TrackedPreferencesMigrator( | 210 TrackedPreferencesMigrator::TrackedPreferencesMigrator( |
210 const std::set<std::string>& unprotected_pref_names, | 211 const std::set<std::string>& unprotected_pref_names, |
211 const std::set<std::string>& protected_pref_names, | 212 const std::set<std::string>& protected_pref_names, |
212 const base::Callback<void(const std::string& key)>& | 213 const base::Callback<void(const std::string& key)>& |
213 unprotected_store_cleaner, | 214 unprotected_store_cleaner, |
214 const base::Callback<void(const std::string& key)>& protected_store_cleaner, | 215 const base::Callback<void(const std::string& key)>& protected_store_cleaner, |
215 const base::Callback<void(const base::Closure&)>& | 216 const base::Callback<void(const base::Closure&)>& |
216 register_on_successful_unprotected_store_write_callback, | 217 register_on_successful_unprotected_store_write_callback, |
217 const base::Callback<void(const base::Closure&)>& | 218 const base::Callback<void(const base::Closure&)>& |
218 register_on_successful_protected_store_write_callback, | 219 register_on_successful_protected_store_write_callback, |
219 scoped_ptr<PrefHashStore> unprotected_pref_hash_store, | 220 std::unique_ptr<PrefHashStore> unprotected_pref_hash_store, |
220 scoped_ptr<PrefHashStore> protected_pref_hash_store, | 221 std::unique_ptr<PrefHashStore> protected_pref_hash_store, |
221 scoped_ptr<HashStoreContents> legacy_pref_hash_store, | 222 std::unique_ptr<HashStoreContents> legacy_pref_hash_store, |
222 InterceptablePrefFilter* unprotected_pref_filter, | 223 InterceptablePrefFilter* unprotected_pref_filter, |
223 InterceptablePrefFilter* protected_pref_filter) | 224 InterceptablePrefFilter* protected_pref_filter) |
224 : unprotected_pref_names_(unprotected_pref_names), | 225 : unprotected_pref_names_(unprotected_pref_names), |
225 protected_pref_names_(protected_pref_names), | 226 protected_pref_names_(protected_pref_names), |
226 unprotected_store_cleaner_(unprotected_store_cleaner), | 227 unprotected_store_cleaner_(unprotected_store_cleaner), |
227 protected_store_cleaner_(protected_store_cleaner), | 228 protected_store_cleaner_(protected_store_cleaner), |
228 register_on_successful_unprotected_store_write_callback_( | 229 register_on_successful_unprotected_store_write_callback_( |
229 register_on_successful_unprotected_store_write_callback), | 230 register_on_successful_unprotected_store_write_callback), |
230 register_on_successful_protected_store_write_callback_( | 231 register_on_successful_protected_store_write_callback_( |
231 register_on_successful_protected_store_write_callback), | 232 register_on_successful_protected_store_write_callback), |
(...skipping 11 matching lines...) Expand all Loading... |
243 this, | 244 this, |
244 PROTECTED_PREF_FILTER)); | 245 PROTECTED_PREF_FILTER)); |
245 } | 246 } |
246 | 247 |
247 TrackedPreferencesMigrator::~TrackedPreferencesMigrator() {} | 248 TrackedPreferencesMigrator::~TrackedPreferencesMigrator() {} |
248 | 249 |
249 void TrackedPreferencesMigrator::InterceptFilterOnLoad( | 250 void TrackedPreferencesMigrator::InterceptFilterOnLoad( |
250 PrefFilterID id, | 251 PrefFilterID id, |
251 const InterceptablePrefFilter::FinalizeFilterOnLoadCallback& | 252 const InterceptablePrefFilter::FinalizeFilterOnLoadCallback& |
252 finalize_filter_on_load, | 253 finalize_filter_on_load, |
253 scoped_ptr<base::DictionaryValue> prefs) { | 254 std::unique_ptr<base::DictionaryValue> prefs) { |
254 switch (id) { | 255 switch (id) { |
255 case UNPROTECTED_PREF_FILTER: | 256 case UNPROTECTED_PREF_FILTER: |
256 finalize_unprotected_filter_on_load_ = finalize_filter_on_load; | 257 finalize_unprotected_filter_on_load_ = finalize_filter_on_load; |
257 unprotected_prefs_ = std::move(prefs); | 258 unprotected_prefs_ = std::move(prefs); |
258 break; | 259 break; |
259 case PROTECTED_PREF_FILTER: | 260 case PROTECTED_PREF_FILTER: |
260 finalize_protected_filter_on_load_ = finalize_filter_on_load; | 261 finalize_protected_filter_on_load_ = finalize_filter_on_load; |
261 protected_prefs_ = std::move(prefs); | 262 protected_prefs_ = std::move(prefs); |
262 break; | 263 break; |
263 } | 264 } |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
344 void SetupTrackedPreferencesMigration( | 345 void SetupTrackedPreferencesMigration( |
345 const std::set<std::string>& unprotected_pref_names, | 346 const std::set<std::string>& unprotected_pref_names, |
346 const std::set<std::string>& protected_pref_names, | 347 const std::set<std::string>& protected_pref_names, |
347 const base::Callback<void(const std::string& key)>& | 348 const base::Callback<void(const std::string& key)>& |
348 unprotected_store_cleaner, | 349 unprotected_store_cleaner, |
349 const base::Callback<void(const std::string& key)>& protected_store_cleaner, | 350 const base::Callback<void(const std::string& key)>& protected_store_cleaner, |
350 const base::Callback<void(const base::Closure&)>& | 351 const base::Callback<void(const base::Closure&)>& |
351 register_on_successful_unprotected_store_write_callback, | 352 register_on_successful_unprotected_store_write_callback, |
352 const base::Callback<void(const base::Closure&)>& | 353 const base::Callback<void(const base::Closure&)>& |
353 register_on_successful_protected_store_write_callback, | 354 register_on_successful_protected_store_write_callback, |
354 scoped_ptr<PrefHashStore> unprotected_pref_hash_store, | 355 std::unique_ptr<PrefHashStore> unprotected_pref_hash_store, |
355 scoped_ptr<PrefHashStore> protected_pref_hash_store, | 356 std::unique_ptr<PrefHashStore> protected_pref_hash_store, |
356 scoped_ptr<HashStoreContents> legacy_pref_hash_store, | 357 std::unique_ptr<HashStoreContents> legacy_pref_hash_store, |
357 InterceptablePrefFilter* unprotected_pref_filter, | 358 InterceptablePrefFilter* unprotected_pref_filter, |
358 InterceptablePrefFilter* protected_pref_filter) { | 359 InterceptablePrefFilter* protected_pref_filter) { |
359 scoped_refptr<TrackedPreferencesMigrator> prefs_migrator( | 360 scoped_refptr<TrackedPreferencesMigrator> prefs_migrator( |
360 new TrackedPreferencesMigrator( | 361 new TrackedPreferencesMigrator( |
361 unprotected_pref_names, protected_pref_names, | 362 unprotected_pref_names, protected_pref_names, |
362 unprotected_store_cleaner, protected_store_cleaner, | 363 unprotected_store_cleaner, protected_store_cleaner, |
363 register_on_successful_unprotected_store_write_callback, | 364 register_on_successful_unprotected_store_write_callback, |
364 register_on_successful_protected_store_write_callback, | 365 register_on_successful_protected_store_write_callback, |
365 std::move(unprotected_pref_hash_store), | 366 std::move(unprotected_pref_hash_store), |
366 std::move(protected_pref_hash_store), | 367 std::move(protected_pref_hash_store), |
367 std::move(legacy_pref_hash_store), unprotected_pref_filter, | 368 std::move(legacy_pref_hash_store), unprotected_pref_filter, |
368 protected_pref_filter)); | 369 protected_pref_filter)); |
369 } | 370 } |
OLD | NEW |