| 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 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 113 } else { | 113 } else { |
| 114 CleanupPrefStore(source_store_cleaner, keys_to_clean); | 114 CleanupPrefStore(source_store_cleaner, keys_to_clean); |
| 115 } | 115 } |
| 116 } | 116 } |
| 117 | 117 |
| 118 // Removes hashes for |migrated_pref_names| from |origin_pref_store| using | 118 // Removes hashes for |migrated_pref_names| from |origin_pref_store| using |
| 119 // the configuration/implementation in |origin_pref_hash_store|. | 119 // the configuration/implementation in |origin_pref_hash_store|. |
| 120 void CleanupMigratedHashes(const std::set<std::string>& migrated_pref_names, | 120 void CleanupMigratedHashes(const std::set<std::string>& migrated_pref_names, |
| 121 PrefHashStore* origin_pref_hash_store, | 121 PrefHashStore* origin_pref_hash_store, |
| 122 base::DictionaryValue* origin_pref_store) { | 122 base::DictionaryValue* origin_pref_store) { |
| 123 DictionaryHashStoreContents dictionary_contents(origin_pref_store); |
| 123 std::unique_ptr<PrefHashStoreTransaction> transaction( | 124 std::unique_ptr<PrefHashStoreTransaction> transaction( |
| 124 origin_pref_hash_store->BeginTransaction( | 125 origin_pref_hash_store->BeginTransaction(&dictionary_contents)); |
| 125 std::unique_ptr<HashStoreContents>( | |
| 126 new DictionaryHashStoreContents(origin_pref_store)))); | |
| 127 for (std::set<std::string>::const_iterator it = migrated_pref_names.begin(); | 126 for (std::set<std::string>::const_iterator it = migrated_pref_names.begin(); |
| 128 it != migrated_pref_names.end(); | 127 it != migrated_pref_names.end(); |
| 129 ++it) { | 128 ++it) { |
| 130 transaction->ClearHash(*it); | 129 transaction->ClearHash(*it); |
| 131 } | 130 } |
| 132 } | 131 } |
| 133 | 132 |
| 134 // Copies the value of each pref in |pref_names| which is set in |old_store|, | 133 // Copies the value of each pref in |pref_names| which is set in |old_store|, |
| 135 // but not in |new_store| into |new_store|. Sets |old_store_needs_cleanup| to | 134 // but not in |new_store| into |new_store|. Sets |old_store_needs_cleanup| to |
| 136 // true if any old duplicates remain in |old_store| and sets |new_store_altered| | 135 // true if any old duplicates remain in |old_store| and sets |new_store_altered| |
| 137 // to true if any value was copied to |new_store|. | 136 // to true if any value was copied to |new_store|. |
| 138 void MigratePrefsFromOldToNewStore(const std::set<std::string>& pref_names, | 137 void MigratePrefsFromOldToNewStore(const std::set<std::string>& pref_names, |
| 139 base::DictionaryValue* old_store, | 138 base::DictionaryValue* old_store, |
| 140 base::DictionaryValue* new_store, | 139 base::DictionaryValue* new_store, |
| 141 PrefHashStore* new_hash_store, | 140 PrefHashStore* new_hash_store, |
| 142 bool* old_store_needs_cleanup, | 141 bool* old_store_needs_cleanup, |
| 143 bool* new_store_altered) { | 142 bool* new_store_altered) { |
| 144 const base::DictionaryValue* old_hash_store_contents = | 143 const base::DictionaryValue* old_hash_store_contents = |
| 145 DictionaryHashStoreContents(old_store).GetContents(); | 144 DictionaryHashStoreContents(old_store).GetContents(); |
| 145 DictionaryHashStoreContents dictionary_contents(new_store); |
| 146 std::unique_ptr<PrefHashStoreTransaction> new_hash_store_transaction( | 146 std::unique_ptr<PrefHashStoreTransaction> new_hash_store_transaction( |
| 147 new_hash_store->BeginTransaction(std::unique_ptr<HashStoreContents>( | 147 new_hash_store->BeginTransaction(&dictionary_contents)); |
| 148 new DictionaryHashStoreContents(new_store)))); | |
| 149 | 148 |
| 150 for (std::set<std::string>::const_iterator it = pref_names.begin(); | 149 for (std::set<std::string>::const_iterator it = pref_names.begin(); |
| 151 it != pref_names.end(); | 150 it != pref_names.end(); |
| 152 ++it) { | 151 ++it) { |
| 153 const std::string& pref_name = *it; | 152 const std::string& pref_name = *it; |
| 154 const base::Value* value_in_old_store = NULL; | 153 const base::Value* value_in_old_store = NULL; |
| 155 | 154 |
| 156 // If the destination does not have a hash for this pref we will | 155 // If the destination does not have a hash for this pref we will |
| 157 // unconditionally attempt to move it. | 156 // unconditionally attempt to move it. |
| 158 bool destination_hash_missing = | 157 bool destination_hash_missing = |
| (...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 334 scoped_refptr<TrackedPreferencesMigrator> prefs_migrator( | 333 scoped_refptr<TrackedPreferencesMigrator> prefs_migrator( |
| 335 new TrackedPreferencesMigrator( | 334 new TrackedPreferencesMigrator( |
| 336 unprotected_pref_names, protected_pref_names, | 335 unprotected_pref_names, protected_pref_names, |
| 337 unprotected_store_cleaner, protected_store_cleaner, | 336 unprotected_store_cleaner, protected_store_cleaner, |
| 338 register_on_successful_unprotected_store_write_callback, | 337 register_on_successful_unprotected_store_write_callback, |
| 339 register_on_successful_protected_store_write_callback, | 338 register_on_successful_protected_store_write_callback, |
| 340 std::move(unprotected_pref_hash_store), | 339 std::move(unprotected_pref_hash_store), |
| 341 std::move(protected_pref_hash_store), unprotected_pref_filter, | 340 std::move(protected_pref_hash_store), unprotected_pref_filter, |
| 342 protected_pref_filter)); | 341 protected_pref_filter)); |
| 343 } | 342 } |
| OLD | NEW |