| 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 "services/preferences/tracked/tracked_preferences_migration.h" | 5 #include "services/preferences/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" |
| 11 #include "base/macros.h" | 11 #include "base/macros.h" |
| 12 #include "base/memory/ptr_util.h" |
| 12 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
| 13 #include "base/metrics/histogram.h" | 14 #include "base/metrics/histogram.h" |
| 14 #include "base/values.h" | 15 #include "base/values.h" |
| 15 #include "services/preferences/tracked/dictionary_hash_store_contents.h" | 16 #include "services/preferences/tracked/dictionary_hash_store_contents.h" |
| 16 #include "services/preferences/tracked/hash_store_contents.h" | 17 #include "services/preferences/tracked/hash_store_contents.h" |
| 17 #include "services/preferences/tracked/interceptable_pref_filter.h" | 18 #include "services/preferences/tracked/interceptable_pref_filter.h" |
| 18 #include "services/preferences/tracked/pref_hash_store.h" | 19 #include "services/preferences/tracked/pref_hash_store.h" |
| 19 #include "services/preferences/tracked/pref_hash_store_transaction.h" | 20 #include "services/preferences/tracked/pref_hash_store_transaction.h" |
| 20 | 21 |
| 21 namespace { | 22 namespace { |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 157 // Whether this value ends up being copied below or was left behind by a | 158 // Whether this value ends up being copied below or was left behind by a |
| 158 // previous incomplete migration, it should be cleaned up. | 159 // previous incomplete migration, it should be cleaned up. |
| 159 *old_store_needs_cleanup = true; | 160 *old_store_needs_cleanup = true; |
| 160 | 161 |
| 161 if (!new_store->Get(pref_name, NULL)) { | 162 if (!new_store->Get(pref_name, NULL)) { |
| 162 // Copy the value from |old_store| to |new_store| rather than moving it | 163 // Copy the value from |old_store| to |new_store| rather than moving it |
| 163 // to avoid data loss should |old_store| be flushed to disk without | 164 // to avoid data loss should |old_store| be flushed to disk without |
| 164 // |new_store| having equivalently been successfully flushed to disk | 165 // |new_store| having equivalently been successfully flushed to disk |
| 165 // (e.g., on crash or in cases where |new_store| is read-only following | 166 // (e.g., on crash or in cases where |new_store| is read-only following |
| 166 // a read error on startup). | 167 // a read error on startup). |
| 167 new_store->Set(pref_name, value_in_old_store->DeepCopy()); | 168 new_store->Set(pref_name, |
| 169 base::MakeUnique<base::Value>(*value_in_old_store)); |
| 168 migrated_value = true; | 170 migrated_value = true; |
| 169 *new_store_altered = true; | 171 *new_store_altered = true; |
| 170 } | 172 } |
| 171 } | 173 } |
| 172 | 174 |
| 173 if (destination_hash_missing || migrated_value) { | 175 if (destination_hash_missing || migrated_value) { |
| 174 const base::Value* old_hash = NULL; | 176 const base::Value* old_hash = NULL; |
| 175 if (old_hash_store_contents) | 177 if (old_hash_store_contents) |
| 176 old_hash_store_contents->Get(pref_name, &old_hash); | 178 old_hash_store_contents->Get(pref_name, &old_hash); |
| 177 if (old_hash) { | 179 if (old_hash) { |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 324 scoped_refptr<TrackedPreferencesMigrator> prefs_migrator( | 326 scoped_refptr<TrackedPreferencesMigrator> prefs_migrator( |
| 325 new TrackedPreferencesMigrator( | 327 new TrackedPreferencesMigrator( |
| 326 unprotected_pref_names, protected_pref_names, | 328 unprotected_pref_names, protected_pref_names, |
| 327 unprotected_store_cleaner, protected_store_cleaner, | 329 unprotected_store_cleaner, protected_store_cleaner, |
| 328 register_on_successful_unprotected_store_write_callback, | 330 register_on_successful_unprotected_store_write_callback, |
| 329 register_on_successful_protected_store_write_callback, | 331 register_on_successful_protected_store_write_callback, |
| 330 std::move(unprotected_pref_hash_store), | 332 std::move(unprotected_pref_hash_store), |
| 331 std::move(protected_pref_hash_store), unprotected_pref_filter, | 333 std::move(protected_pref_hash_store), unprotected_pref_filter, |
| 332 protected_pref_filter)); | 334 protected_pref_filter)); |
| 333 } | 335 } |
| OLD | NEW |