Chromium Code Reviews| 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 "chrome/browser/prefs/tracked/tracked_preferences_migration.h" | 5 #include "chrome/browser/prefs/tracked/tracked_preferences_migration.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/callback.h" | 8 #include "base/callback.h" |
| 9 #include "base/macros.h" | 9 #include "base/macros.h" |
| 10 #include "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
| 11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
| 12 #include "base/values.h" | 12 #include "base/values.h" |
| 13 #include "chrome/browser/prefs/interceptable_pref_filter.h" | 13 #include "chrome/browser/prefs/interceptable_pref_filter.h" |
| 14 #include "chrome/browser/prefs/pref_hash_store.h" | |
| 15 #include "chrome/browser/prefs/pref_hash_store_transaction.h" | |
| 14 | 16 |
| 15 namespace { | 17 namespace { |
| 16 | 18 |
| 17 class TrackedPreferencesMigrator | 19 class TrackedPreferencesMigrator |
| 18 : public base::RefCounted<TrackedPreferencesMigrator> { | 20 : public base::RefCounted<TrackedPreferencesMigrator> { |
| 19 public: | 21 public: |
| 20 TrackedPreferencesMigrator( | 22 TrackedPreferencesMigrator( |
| 21 const std::set<std::string>& unprotected_pref_names, | 23 const std::set<std::string>& unprotected_pref_names, |
| 22 const std::set<std::string>& protected_pref_names, | 24 const std::set<std::string>& protected_pref_names, |
| 23 const base::Callback<void(const std::string& key)>& | 25 scoped_ptr<TrackedPreferencesMigrationDelegate> unprotected_delegate, |
| 24 unprotected_store_cleaner, | 26 scoped_ptr<TrackedPreferencesMigrationDelegate> protected_delegate, |
| 25 const base::Callback<void(const std::string& key)>& | 27 scoped_ptr<PrefHashStore> legacy_pref_hash_store); |
| 26 protected_store_cleaner, | |
| 27 const base::Callback<void(const base::Closure&)>& | |
| 28 register_on_successful_unprotected_store_write_callback, | |
| 29 const base::Callback<void(const base::Closure&)>& | |
| 30 register_on_successful_protected_store_write_callback, | |
| 31 InterceptablePrefFilter* unprotected_pref_filter, | |
| 32 InterceptablePrefFilter* protected_pref_filter); | |
| 33 | 28 |
| 34 private: | 29 private: |
| 35 friend class base::RefCounted<TrackedPreferencesMigrator>; | 30 friend class base::RefCounted<TrackedPreferencesMigrator>; |
| 36 | 31 |
| 37 enum PrefFilterID { | 32 enum PrefFilterID { |
| 38 UNPROTECTED_PREF_FILTER, | 33 UNPROTECTED_PREF_FILTER, |
| 39 PROTECTED_PREF_FILTER | 34 PROTECTED_PREF_FILTER |
| 40 }; | 35 }; |
| 41 | 36 |
| 42 ~TrackedPreferencesMigrator(); | 37 ~TrackedPreferencesMigrator(); |
| 43 | 38 |
| 44 // Stores the data coming in from the filter identified by |id| into this | 39 // Stores the data coming in from the filter identified by |id| into this |
| 45 // class and then calls MigrateIfReady(); | 40 // class and then calls MigrateIfReady(); |
| 46 void InterceptFilterOnLoad( | 41 void InterceptFilterOnLoad( |
| 47 PrefFilterID id, | 42 PrefFilterID id, |
| 48 const InterceptablePrefFilter::FinalizeFilterOnLoadCallback& | 43 const InterceptablePrefFilter::FinalizeFilterOnLoadCallback& |
| 49 finalize_filter_on_load, | 44 finalize_filter_on_load, |
| 50 scoped_ptr<base::DictionaryValue> prefs); | 45 base::DictionaryValue* prefs); |
| 46 | |
| 47 void CleanupPrefStore( | |
| 48 TrackedPreferencesMigrationDelegate* delegate, | |
| 49 const std::set<std::string>& keys_to_clean); | |
| 50 | |
| 51 void ScheduleSourcePrefStoreCleanup( | |
| 52 TrackedPreferencesMigrationDelegate* source_delegate, | |
| 53 TrackedPreferencesMigrationDelegate* destination_delegate, | |
| 54 const std::set<std::string>& keys_to_clean, | |
| 55 bool wait_for_commit_to_destination_store); | |
| 51 | 56 |
| 52 // Proceeds with migration if both |unprotected_prefs_| and |protected_prefs_| | 57 // Proceeds with migration if both |unprotected_prefs_| and |protected_prefs_| |
| 53 // have been set. | 58 // have been set. |
| 54 void MigrateIfReady(); | 59 void MigrateIfReady(); |
| 55 | 60 |
| 56 const std::set<std::string> unprotected_pref_names_; | 61 const std::set<std::string> unprotected_pref_names_; |
| 57 const std::set<std::string> protected_pref_names_; | 62 const std::set<std::string> protected_pref_names_; |
| 58 | 63 |
| 59 const base::Callback<void(const std::string& key)> unprotected_store_cleaner_; | 64 scoped_ptr<TrackedPreferencesMigrationDelegate> unprotected_delegate_; |
| 60 const base::Callback<void(const std::string& key)> protected_store_cleaner_; | 65 scoped_ptr<TrackedPreferencesMigrationDelegate> protected_delegate_; |
| 61 const base::Callback<void(const base::Closure&)> | 66 scoped_ptr<PrefHashStore> legacy_pref_hash_store_; |
| 62 register_on_successful_unprotected_store_write_callback_; | 67 TrackedPreferencesMigrationDelegate::InterceptCompletionCallback |
| 63 const base::Callback<void(const base::Closure&)> | 68 unprotected_intercept_completion_callback_; |
| 64 register_on_successful_protected_store_write_callback_; | 69 TrackedPreferencesMigrationDelegate::InterceptCompletionCallback |
| 70 protected_intercept_completion_callback_; | |
| 65 | 71 |
| 66 InterceptablePrefFilter::FinalizeFilterOnLoadCallback | 72 base::DictionaryValue* unprotected_prefs_; |
| 67 finalize_unprotected_filter_on_load_; | 73 base::DictionaryValue* protected_prefs_; |
| 68 InterceptablePrefFilter::FinalizeFilterOnLoadCallback | |
| 69 finalize_protected_filter_on_load_; | |
| 70 | |
| 71 scoped_ptr<base::DictionaryValue> unprotected_prefs_; | |
| 72 scoped_ptr<base::DictionaryValue> protected_prefs_; | |
| 73 | 74 |
| 74 DISALLOW_COPY_AND_ASSIGN(TrackedPreferencesMigrator); | 75 DISALLOW_COPY_AND_ASSIGN(TrackedPreferencesMigrator); |
| 75 }; | 76 }; |
| 76 | 77 |
| 77 // Invokes |store_cleaner| for every |keys_to_clean|. | 78 // Removes the value and hash of each preference in |keys_to_clean| using |
| 78 void CleanupPrefStore( | 79 // |delegate|. |
| 79 const base::Callback<void(const std::string& key)>& store_cleaner, | 80 void TrackedPreferencesMigrator::CleanupPrefStore( |
| 81 TrackedPreferencesMigrationDelegate* delegate, | |
| 80 const std::set<std::string>& keys_to_clean) { | 82 const std::set<std::string>& keys_to_clean) { |
| 83 if (!delegate->IsValid()) | |
| 84 return; | |
| 85 | |
| 86 DCHECK(delegate->GetPrefHashStore()); | |
| 87 | |
| 88 scoped_ptr<PrefHashStoreTransaction> hash_transaction( | |
| 89 delegate->GetPrefHashStore()->BeginTransaction()); | |
| 81 for (std::set<std::string>::const_iterator it = keys_to_clean.begin(); | 90 for (std::set<std::string>::const_iterator it = keys_to_clean.begin(); |
| 82 it != keys_to_clean.end(); ++it) { | 91 it != keys_to_clean.end(); ++it) { |
| 83 store_cleaner.Run(*it); | 92 delegate->CleanPreference(*it); |
| 93 hash_transaction->ClearHash(*it); | |
| 84 } | 94 } |
| 85 } | 95 } |
| 86 | 96 |
| 87 // If |wait_for_commit_to_destination_store|: schedules (via | 97 // If |wait_for_commit_to_destination_store|: schedules (via |
| 88 // |register_on_successful_destination_store_write_callback|) a cleanup of the | 98 // |register_on_successful_destination_store_write_callback|) a cleanup of the |
| 89 // |keys_to_clean| from the source pref store (through |source_store_cleaner|) | 99 // |keys_to_clean| from the source pref store (through |source_store_cleaner|) |
| 90 // once the destination pref store they were migrated to was successfully | 100 // once the destination pref store they were migrated to was successfully |
| 91 // written to disk. Otherwise, executes the cleanup right away. | 101 // written to disk. Otherwise, executes the cleanup right away. |
| 92 void ScheduleSourcePrefStoreCleanup( | 102 void |
| 93 const base::Callback<void(const base::Closure&)>& | 103 TrackedPreferencesMigrator::ScheduleSourcePrefStoreCleanup( |
|
gab
2014/06/11 18:23:55
This fits on the previous line I think.
| |
| 94 register_on_successful_destination_store_write_callback, | 104 TrackedPreferencesMigrationDelegate* source_delegate, |
| 95 const base::Callback<void(const std::string& key)>& source_store_cleaner, | 105 TrackedPreferencesMigrationDelegate* destination_delegate, |
| 96 const std::set<std::string>& keys_to_clean, | 106 const std::set<std::string>& keys_to_clean, |
| 97 bool wait_for_commit_to_destination_store) { | 107 bool wait_for_commit_to_destination_store) { |
| 108 DCHECK(source_delegate->IsValid()); | |
| 109 DCHECK(destination_delegate->IsValid()); | |
| 110 | |
| 98 DCHECK(!keys_to_clean.empty()); | 111 DCHECK(!keys_to_clean.empty()); |
| 99 if (wait_for_commit_to_destination_store) { | 112 if (wait_for_commit_to_destination_store) { |
| 100 register_on_successful_destination_store_write_callback.Run( | 113 destination_delegate->NotifyOnSuccessfulWrite(base::Bind( |
| 101 base::Bind(&CleanupPrefStore, source_store_cleaner, keys_to_clean)); | 114 &TrackedPreferencesMigrator::CleanupPrefStore, |
| 115 this, | |
| 116 source_delegate, | |
| 117 base::ConstRef(keys_to_clean))); | |
| 102 } else { | 118 } else { |
| 103 CleanupPrefStore(source_store_cleaner, keys_to_clean); | 119 CleanupPrefStore(source_delegate, keys_to_clean); |
| 104 } | 120 } |
| 105 } | 121 } |
| 106 | 122 |
| 107 // Copies the value of each pref in |pref_names| which is set in |old_store|, | 123 // Copies the value of each pref in |pref_names| which is set in |old_store|, |
| 108 // but not in |new_store| into |new_store|. Sets |old_store_needs_cleanup| to | 124 // but not in |new_store| into |new_store|. Sets |old_store_needs_cleanup| to |
| 109 // true if any old duplicates remain in |old_store| and sets |new_store_altered| | 125 // true if any old duplicates remain in |old_store| and sets |new_store_altered| |
| 110 // to true if any value was copied to |new_store|. | 126 // to true if any value was copied to |new_store|. |
|
gab
2014/06/11 18:23:55
Update this comment.
| |
| 111 void MigratePrefsFromOldToNewStore(const std::set<std::string>& pref_names, | 127 void MigratePrefsFromOldToNewStore(const std::set<std::string>& pref_names, |
| 112 const base::DictionaryValue* old_store, | 128 const base::DictionaryValue* old_store, |
| 113 base::DictionaryValue* new_store, | 129 base::DictionaryValue* new_store, |
| 130 PrefHashStore* old_pref_hash_store, | |
| 131 PrefHashStore* new_pref_hash_store, | |
| 132 PrefHashStore* legacy_pref_hash_store, | |
| 114 bool* old_store_needs_cleanup, | 133 bool* old_store_needs_cleanup, |
| 115 bool* new_store_altered) { | 134 bool* new_store_altered) { |
| 135 scoped_ptr<PrefHashStoreTransaction> source_transaction( | |
| 136 old_pref_hash_store->BeginTransaction()); | |
| 137 scoped_ptr<PrefHashStoreTransaction> destination_transaction( | |
| 138 new_pref_hash_store->BeginTransaction()); | |
| 139 scoped_ptr<PrefHashStoreTransaction> legacy_transaction( | |
| 140 legacy_pref_hash_store->BeginTransaction()); | |
| 141 | |
| 116 for (std::set<std::string>::const_iterator it = pref_names.begin(); | 142 for (std::set<std::string>::const_iterator it = pref_names.begin(); |
| 117 it != pref_names.end(); ++it) { | 143 it != pref_names.end(); |
| 144 ++it) { | |
| 118 const std::string& pref_name = *it; | 145 const std::string& pref_name = *it; |
| 119 | 146 |
| 120 const base::Value* value_in_old_store = NULL; | 147 const base::Value* value_in_old_store = NULL; |
| 121 if (!old_store->Get(pref_name, &value_in_old_store)) | 148 // If the destination does not have a hash for this pref we will |
| 122 continue; | 149 // unconditionally attempt to move it. |
| 150 bool destination_hash_missing = | |
| 151 !destination_transaction->GetHash(pref_name); | |
|
gab
2014/06/11 18:23:55
Inline this in conditional on line 172; no need to
| |
| 152 // If we migrate the value we will also attempt to migrate the hash. | |
| 153 bool migrated_value = false; | |
| 154 if (old_store->Get(pref_name, &value_in_old_store)) { | |
| 155 // Whether this value ends up being copied below or was left behind by a | |
| 156 // previous incomplete migration, it should be cleaned up. | |
| 157 *old_store_needs_cleanup = true; | |
| 123 | 158 |
| 124 // Whether this value ends up being copied below or was left behind by a | 159 if (!new_store->Get(pref_name, NULL)) { |
| 125 // previous incomplete migration, it should be cleaned up. | 160 // Copy the value from |old_store| to |new_store| rather than moving it |
| 126 *old_store_needs_cleanup = true; | 161 // to avoid data loss should |old_store| be flushed to disk without |
| 162 // |new_store| having equivalently been successfully flushed to disk | |
| 163 // (e.g., on crash or in cases where |new_store| is read-only following | |
| 164 // a read error on startup). | |
| 165 scoped_ptr<base::Value> value_copy(value_in_old_store->DeepCopy()); | |
| 166 new_store->Set(pref_name, value_copy.release()); | |
| 167 migrated_value = true; | |
| 168 *new_store_altered = true; | |
| 169 } | |
| 170 } | |
| 127 | 171 |
| 128 if (new_store->Get(pref_name, NULL)) | 172 if (destination_hash_missing || migrated_value) { |
| 129 continue; | 173 const base::Value* old_hash = source_transaction->GetHash(pref_name); |
| 130 | 174 if (!old_hash) |
| 131 // Copy the value from |old_store| to |new_store| rather than moving it to | 175 old_hash = legacy_transaction->GetHash(pref_name); |
| 132 // avoid data loss should |old_store| be flushed to disk without |new_store| | 176 if (old_hash || !destination_hash_missing) { |
|
gab
2014/06/11 18:23:55
I don't think this conditional is necessary.
You
| |
| 133 // having equivalently been successfully flushed to disk (e.g., on crash or | 177 destination_transaction->ImportHash(pref_name, old_hash); |
| 134 // in cases where |new_store| is read-only following a read error on | 178 *new_store_altered = true; |
| 135 // startup). | 179 } |
| 136 new_store->Set(pref_name, value_in_old_store->DeepCopy()); | 180 } |
| 137 *new_store_altered = true; | |
| 138 } | 181 } |
| 139 } | 182 } |
| 140 | 183 |
| 141 TrackedPreferencesMigrator::TrackedPreferencesMigrator( | 184 TrackedPreferencesMigrator::TrackedPreferencesMigrator( |
| 142 const std::set<std::string>& unprotected_pref_names, | 185 const std::set<std::string>& unprotected_pref_names, |
| 143 const std::set<std::string>& protected_pref_names, | 186 const std::set<std::string>& protected_pref_names, |
| 144 const base::Callback<void(const std::string& key)>& | 187 scoped_ptr<TrackedPreferencesMigrationDelegate> unprotected_delegate, |
| 145 unprotected_store_cleaner, | 188 scoped_ptr<TrackedPreferencesMigrationDelegate> protected_delegate, |
| 146 const base::Callback<void(const std::string& key)>& protected_store_cleaner, | 189 scoped_ptr<PrefHashStore> legacy_pref_hash_store) |
| 147 const base::Callback<void(const base::Closure&)>& | |
| 148 register_on_successful_unprotected_store_write_callback, | |
| 149 const base::Callback<void(const base::Closure&)>& | |
| 150 register_on_successful_protected_store_write_callback, | |
| 151 InterceptablePrefFilter* unprotected_pref_filter, | |
| 152 InterceptablePrefFilter* protected_pref_filter) | |
| 153 : unprotected_pref_names_(unprotected_pref_names), | 190 : unprotected_pref_names_(unprotected_pref_names), |
| 154 protected_pref_names_(protected_pref_names), | 191 protected_pref_names_(protected_pref_names), |
| 155 unprotected_store_cleaner_(unprotected_store_cleaner), | 192 unprotected_delegate_(unprotected_delegate.Pass()), |
| 156 protected_store_cleaner_(protected_store_cleaner), | 193 protected_delegate_(protected_delegate.Pass()), |
| 157 register_on_successful_unprotected_store_write_callback_( | 194 legacy_pref_hash_store_(legacy_pref_hash_store.Pass()), |
| 158 register_on_successful_unprotected_store_write_callback), | 195 unprotected_prefs_(NULL), |
| 159 register_on_successful_protected_store_write_callback_( | 196 protected_prefs_(NULL) { |
| 160 register_on_successful_protected_store_write_callback) { | |
| 161 // The callbacks bound below will own this TrackedPreferencesMigrator by | 197 // The callbacks bound below will own this TrackedPreferencesMigrator by |
| 162 // reference. | 198 // reference. |
| 163 unprotected_pref_filter->InterceptNextFilterOnLoad( | 199 unprotected_delegate_->InterceptLoadedPreferences( |
| 164 base::Bind(&TrackedPreferencesMigrator::InterceptFilterOnLoad, | 200 base::Bind(&TrackedPreferencesMigrator::InterceptFilterOnLoad, |
| 165 this, | 201 this, |
| 166 UNPROTECTED_PREF_FILTER)); | 202 UNPROTECTED_PREF_FILTER)); |
| 167 protected_pref_filter->InterceptNextFilterOnLoad( | 203 protected_delegate_->InterceptLoadedPreferences( |
| 168 base::Bind(&TrackedPreferencesMigrator::InterceptFilterOnLoad, | 204 base::Bind(&TrackedPreferencesMigrator::InterceptFilterOnLoad, |
| 169 this, | 205 this, |
| 170 PROTECTED_PREF_FILTER)); | 206 PROTECTED_PREF_FILTER)); |
| 171 } | 207 } |
| 172 | 208 |
| 173 TrackedPreferencesMigrator::~TrackedPreferencesMigrator() {} | 209 TrackedPreferencesMigrator::~TrackedPreferencesMigrator() {} |
| 174 | 210 |
| 175 void TrackedPreferencesMigrator::InterceptFilterOnLoad( | 211 void TrackedPreferencesMigrator::InterceptFilterOnLoad( |
| 176 PrefFilterID id, | 212 PrefFilterID id, |
| 177 const InterceptablePrefFilter::FinalizeFilterOnLoadCallback& | 213 const TrackedPreferencesMigrationDelegate::InterceptCompletionCallback& |
| 178 finalize_filter_on_load, | 214 completion_callback, |
| 179 scoped_ptr<base::DictionaryValue> prefs) { | 215 base::DictionaryValue* prefs) { |
| 180 switch (id) { | 216 switch (id) { |
| 181 case UNPROTECTED_PREF_FILTER: | 217 case UNPROTECTED_PREF_FILTER: |
| 182 finalize_unprotected_filter_on_load_ = finalize_filter_on_load; | 218 unprotected_intercept_completion_callback_ = completion_callback; |
| 183 unprotected_prefs_ = prefs.Pass(); | 219 unprotected_prefs_ = prefs; |
| 184 break; | 220 break; |
| 185 case PROTECTED_PREF_FILTER: | 221 case PROTECTED_PREF_FILTER: |
| 186 finalize_protected_filter_on_load_ = finalize_filter_on_load; | 222 protected_intercept_completion_callback_ = completion_callback; |
| 187 protected_prefs_ = prefs.Pass(); | 223 protected_prefs_ = prefs; |
| 188 break; | 224 break; |
| 189 } | 225 } |
| 190 | 226 |
| 191 MigrateIfReady(); | 227 MigrateIfReady(); |
| 192 } | 228 } |
| 193 | 229 |
| 194 void TrackedPreferencesMigrator::MigrateIfReady() { | 230 void TrackedPreferencesMigrator::MigrateIfReady() { |
| 231 if (!protected_delegate_->IsValid() || !unprotected_delegate_->IsValid()) { | |
|
gab
2014/06/11 18:23:55
This is not possible since the read tasks [1] and
| |
| 232 // We started shutting down before both stores had loaded. Don't call either | |
| 233 // of the completion callbacks, as the preferences are not fit to be used. | |
| 234 unprotected_prefs_ = NULL; | |
| 235 unprotected_intercept_completion_callback_.Reset(); | |
| 236 protected_prefs_ = NULL; | |
| 237 protected_intercept_completion_callback_.Reset(); | |
| 238 return; | |
| 239 } | |
| 240 | |
| 195 // Wait for both stores to have been read before proceeding. | 241 // Wait for both stores to have been read before proceeding. |
| 196 if (!protected_prefs_ || !unprotected_prefs_) | 242 if (!protected_prefs_ || !unprotected_prefs_) |
| 197 return; | 243 return; |
| 198 | 244 |
| 199 bool protected_prefs_need_cleanup = false; | 245 bool protected_prefs_need_cleanup = false; |
| 200 bool unprotected_prefs_altered = false; | 246 bool unprotected_prefs_altered = false; |
| 201 MigratePrefsFromOldToNewStore(unprotected_pref_names_, | 247 MigratePrefsFromOldToNewStore(unprotected_pref_names_, |
| 202 protected_prefs_.get(), | 248 protected_prefs_, |
| 203 unprotected_prefs_.get(), | 249 unprotected_prefs_, |
| 250 protected_delegate_->GetPrefHashStore(), | |
| 251 unprotected_delegate_->GetPrefHashStore(), | |
| 252 legacy_pref_hash_store_.get(), | |
| 204 &protected_prefs_need_cleanup, | 253 &protected_prefs_need_cleanup, |
| 205 &unprotected_prefs_altered); | 254 &unprotected_prefs_altered); |
| 206 bool unprotected_prefs_need_cleanup = false; | 255 bool unprotected_prefs_need_cleanup = false; |
| 207 bool protected_prefs_altered = false; | 256 bool protected_prefs_altered = false; |
| 208 MigratePrefsFromOldToNewStore(protected_pref_names_, | 257 MigratePrefsFromOldToNewStore(protected_pref_names_, |
| 209 unprotected_prefs_.get(), | 258 unprotected_prefs_, |
| 210 protected_prefs_.get(), | 259 protected_prefs_, |
| 260 unprotected_delegate_->GetPrefHashStore(), | |
| 261 protected_delegate_->GetPrefHashStore(), | |
| 262 legacy_pref_hash_store_.get(), | |
| 211 &unprotected_prefs_need_cleanup, | 263 &unprotected_prefs_need_cleanup, |
| 212 &protected_prefs_altered); | 264 &protected_prefs_altered); |
| 213 | 265 |
| 214 // Hand the processed prefs back to their respective filters. | 266 // Allow processing of the preference stores to continue. |
| 215 finalize_unprotected_filter_on_load_.Run(unprotected_prefs_.Pass(), | 267 unprotected_prefs_ = NULL; |
| 216 unprotected_prefs_altered); | 268 unprotected_intercept_completion_callback_.Run(unprotected_prefs_altered); |
| 217 finalize_protected_filter_on_load_.Run(protected_prefs_.Pass(), | 269 protected_prefs_ = NULL; |
| 218 protected_prefs_altered); | 270 protected_intercept_completion_callback_.Run(protected_prefs_altered); |
| 219 | |
| 220 if (unprotected_prefs_need_cleanup) { | 271 if (unprotected_prefs_need_cleanup) { |
| 221 // Schedule a cleanup of the |protected_pref_names_| from the unprotected | 272 // Schedule a cleanup of the |protected_pref_names_| from the unprotected |
| 222 // prefs once the protected prefs were successfully written to disk (or | 273 // prefs once the protected prefs were successfully written to disk (or |
| 223 // do it immediately if |!protected_prefs_altered|). | 274 // do it immediately if |!protected_prefs_altered|). |
| 224 ScheduleSourcePrefStoreCleanup( | 275 ScheduleSourcePrefStoreCleanup(unprotected_delegate_.get(), |
| 225 register_on_successful_protected_store_write_callback_, | 276 protected_delegate_.get(), |
| 226 unprotected_store_cleaner_, | 277 protected_pref_names_, |
| 227 protected_pref_names_, | 278 protected_prefs_altered); |
| 228 protected_prefs_altered); | |
| 229 } | 279 } |
| 230 | |
| 231 if (protected_prefs_need_cleanup) { | 280 if (protected_prefs_need_cleanup) { |
| 232 // Schedule a cleanup of the |unprotected_pref_names_| from the protected | 281 // Schedule a cleanup of the |unprotected_pref_names_| from the protected |
| 233 // prefs once the unprotected prefs were successfully written to disk (or | 282 // prefs once the unprotected prefs were successfully written to disk (or |
| 234 // do it immediately if |!unprotected_prefs_altered|). | 283 // do it immediately if |!unprotected_prefs_altered|). |
| 235 ScheduleSourcePrefStoreCleanup( | 284 ScheduleSourcePrefStoreCleanup(protected_delegate_.get(), |
| 236 register_on_successful_unprotected_store_write_callback_, | 285 unprotected_delegate_.get(), |
| 237 protected_store_cleaner_, | 286 unprotected_pref_names_, |
| 238 unprotected_pref_names_, | 287 unprotected_prefs_altered); |
| 239 unprotected_prefs_altered); | |
| 240 } | 288 } |
| 289 | |
| 290 if (!unprotected_prefs_altered && !protected_prefs_altered) | |
| 291 this->legacy_pref_hash_store_->Reset(); | |
| 241 } | 292 } |
| 242 | 293 |
| 243 } // namespace | 294 } // namespace |
| 244 | 295 |
| 245 void SetupTrackedPreferencesMigration( | 296 void SetupTrackedPreferencesMigration( |
| 246 const std::set<std::string>& unprotected_pref_names, | 297 const std::set<std::string>& unprotected_pref_names, |
| 247 const std::set<std::string>& protected_pref_names, | 298 const std::set<std::string>& protected_pref_names, |
| 248 const base::Callback<void(const std::string& key)>& | 299 scoped_ptr<TrackedPreferencesMigrationDelegate> unprotected_delegate, |
| 249 unprotected_store_cleaner, | 300 scoped_ptr<TrackedPreferencesMigrationDelegate> protected_delegate, |
| 250 const base::Callback<void(const std::string& key)>& protected_store_cleaner, | 301 scoped_ptr<PrefHashStore> legacy_pref_hash_store) { |
| 251 const base::Callback<void(const base::Closure&)>& | |
| 252 register_on_successful_unprotected_store_write_callback, | |
| 253 const base::Callback<void(const base::Closure&)>& | |
| 254 register_on_successful_protected_store_write_callback, | |
| 255 InterceptablePrefFilter* unprotected_pref_filter, | |
| 256 InterceptablePrefFilter* protected_pref_filter) { | |
| 257 scoped_refptr<TrackedPreferencesMigrator> prefs_migrator( | 302 scoped_refptr<TrackedPreferencesMigrator> prefs_migrator( |
| 258 new TrackedPreferencesMigrator( | 303 new TrackedPreferencesMigrator(unprotected_pref_names, |
| 259 unprotected_pref_names, | 304 protected_pref_names, |
| 260 protected_pref_names, | 305 unprotected_delegate.Pass(), |
| 261 unprotected_store_cleaner, | 306 protected_delegate.Pass(), |
| 262 protected_store_cleaner, | 307 legacy_pref_hash_store.Pass())); |
| 263 register_on_successful_unprotected_store_write_callback, | |
| 264 register_on_successful_protected_store_write_callback, | |
| 265 unprotected_pref_filter, | |
| 266 protected_pref_filter)); | |
| 267 } | 308 } |
| OLD | NEW |