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 CleanupPrefStoreAndMaybeLocalState( | |
gab
2014/06/06 21:54:59
s/LocalState/LegacyHashStore ?
here and below (si
erikwright (departed)
2014/06/10 20:27:48
Done.
| |
48 TrackedPreferencesMigrationDelegate* delegate, | |
49 const std::set<std::string>& keys_to_clean, | |
50 scoped_refptr<base::RefCountedData<int> > pending_cleanups); | |
51 | |
52 void ScheduleSourcePrefStoreAndLocalStateCleanup( | |
53 TrackedPreferencesMigrationDelegate* source_delegate, | |
54 TrackedPreferencesMigrationDelegate* destination_delegate, | |
55 const std::set<std::string>& keys_to_clean, | |
56 bool wait_for_commit_to_destination_store, | |
57 scoped_refptr<base::RefCountedData<int> > pending_cleanups); | |
51 | 58 |
52 // Proceeds with migration if both |unprotected_prefs_| and |protected_prefs_| | 59 // Proceeds with migration if both |unprotected_prefs_| and |protected_prefs_| |
53 // have been set. | 60 // have been set. |
54 void MigrateIfReady(); | 61 void MigrateIfReady(); |
55 | 62 |
56 const std::set<std::string> unprotected_pref_names_; | 63 const std::set<std::string> unprotected_pref_names_; |
57 const std::set<std::string> protected_pref_names_; | 64 const std::set<std::string> protected_pref_names_; |
58 | 65 |
59 const base::Callback<void(const std::string& key)> unprotected_store_cleaner_; | 66 scoped_ptr<TrackedPreferencesMigrationDelegate> unprotected_delegate_; |
60 const base::Callback<void(const std::string& key)> protected_store_cleaner_; | 67 scoped_ptr<TrackedPreferencesMigrationDelegate> protected_delegate_; |
61 const base::Callback<void(const base::Closure&)> | 68 scoped_ptr<PrefHashStore> legacy_pref_hash_store_; |
62 register_on_successful_unprotected_store_write_callback_; | 69 TrackedPreferencesMigrationDelegate::InterceptCompletionCallback |
63 const base::Callback<void(const base::Closure&)> | 70 unprotected_intercept_completion_callback_; |
64 register_on_successful_protected_store_write_callback_; | 71 TrackedPreferencesMigrationDelegate::InterceptCompletionCallback |
72 protected_intercept_completion_callback_; | |
65 | 73 |
66 InterceptablePrefFilter::FinalizeFilterOnLoadCallback | 74 base::DictionaryValue* unprotected_prefs_; |
67 finalize_unprotected_filter_on_load_; | 75 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 | 76 |
74 DISALLOW_COPY_AND_ASSIGN(TrackedPreferencesMigrator); | 77 DISALLOW_COPY_AND_ASSIGN(TrackedPreferencesMigrator); |
75 }; | 78 }; |
76 | 79 |
77 // Invokes |store_cleaner| for every |keys_to_clean|. | 80 // Invokes |store_cleaner| for every |keys_to_clean|. |
gab
2014/06/06 21:54:59
Expand method comment.
erikwright (departed)
2014/06/10 20:27:48
Done.
| |
78 void CleanupPrefStore( | 81 void TrackedPreferencesMigrator::CleanupPrefStoreAndMaybeLocalState( |
79 const base::Callback<void(const std::string& key)>& store_cleaner, | 82 TrackedPreferencesMigrationDelegate* delegate, |
80 const std::set<std::string>& keys_to_clean) { | 83 const std::set<std::string>& keys_to_clean, |
84 scoped_refptr<base::RefCountedData<int> > pending_commits) { | |
85 scoped_ptr<PrefHashStoreTransaction> hash_transaction( | |
86 delegate->GetPrefHashStore()->BeginTransaction()); | |
81 for (std::set<std::string>::const_iterator it = keys_to_clean.begin(); | 87 for (std::set<std::string>::const_iterator it = keys_to_clean.begin(); |
82 it != keys_to_clean.end(); ++it) { | 88 it != keys_to_clean.end(); ++it) { |
83 store_cleaner.Run(*it); | 89 delegate->CleanPreference(*it); |
90 hash_transaction->ClearHash(*it); | |
84 } | 91 } |
92 if (!--pending_commits->data) | |
gab
2014/06/06 21:54:59
s/!--pending_commits->data/--pending_commits->data
erikwright (departed)
2014/06/10 20:27:48
Done.
| |
93 this->legacy_pref_hash_store_->Reset(); | |
gab
2014/06/06 21:54:59
Instead of using the ref-counted |pending_commits|
erikwright (departed)
2014/06/10 20:27:48
Done.
| |
85 } | 94 } |
86 | 95 |
87 // If |wait_for_commit_to_destination_store|: schedules (via | 96 // If |wait_for_commit_to_destination_store|: schedules (via |
88 // |register_on_successful_destination_store_write_callback|) a cleanup of the | 97 // |register_on_successful_destination_store_write_callback|) a cleanup of the |
89 // |keys_to_clean| from the source pref store (through |source_store_cleaner|) | 98 // |keys_to_clean| from the source pref store (through |source_store_cleaner|) |
90 // once the destination pref store they were migrated to was successfully | 99 // once the destination pref store they were migrated to was successfully |
91 // written to disk. Otherwise, executes the cleanup right away. | 100 // written to disk. Otherwise, executes the cleanup right away. |
92 void ScheduleSourcePrefStoreCleanup( | 101 void TrackedPreferencesMigrator::ScheduleSourcePrefStoreAndLocalStateCleanup( |
93 const base::Callback<void(const base::Closure&)>& | 102 TrackedPreferencesMigrationDelegate* source_delegate, |
94 register_on_successful_destination_store_write_callback, | 103 TrackedPreferencesMigrationDelegate* destination_delegate, |
95 const base::Callback<void(const std::string& key)>& source_store_cleaner, | |
96 const std::set<std::string>& keys_to_clean, | 104 const std::set<std::string>& keys_to_clean, |
97 bool wait_for_commit_to_destination_store) { | 105 bool wait_for_commit_to_destination_store, |
106 scoped_refptr<base::RefCountedData<int> > pending_commits) { | |
98 DCHECK(!keys_to_clean.empty()); | 107 DCHECK(!keys_to_clean.empty()); |
99 if (wait_for_commit_to_destination_store) { | 108 if (wait_for_commit_to_destination_store) { |
100 register_on_successful_destination_store_write_callback.Run( | 109 destination_delegate->NotifyOnSuccessfulWrite(base::Bind( |
101 base::Bind(&CleanupPrefStore, source_store_cleaner, keys_to_clean)); | 110 &TrackedPreferencesMigrator::CleanupPrefStoreAndMaybeLocalState, |
111 this, | |
gab
2014/06/06 21:54:59
One of the reason this was previously bound to a f
erikwright (departed)
2014/06/10 20:27:48
The delegate impl is bound to the pref stores by w
gab
2014/06/11 18:23:55
This is not what I meant:
By binding the above ca
| |
112 source_delegate, | |
113 base::ConstRef(keys_to_clean), | |
114 pending_commits)); | |
102 } else { | 115 } else { |
103 CleanupPrefStore(source_store_cleaner, keys_to_clean); | 116 CleanupPrefStoreAndMaybeLocalState( |
117 source_delegate, keys_to_clean, pending_commits); | |
104 } | 118 } |
105 } | 119 } |
106 | 120 |
107 // Copies the value of each pref in |pref_names| which is set in |old_store|, | 121 // 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 | 122 // 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| | 123 // 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|. | 124 // to true if any value was copied to |new_store|. |
111 void MigratePrefsFromOldToNewStore(const std::set<std::string>& pref_names, | 125 void MigratePrefsFromOldToNewStore(const std::set<std::string>& pref_names, |
112 const base::DictionaryValue* old_store, | 126 const base::DictionaryValue* old_store, |
113 base::DictionaryValue* new_store, | 127 base::DictionaryValue* new_store, |
128 PrefHashStore* old_pref_hash_store, | |
129 PrefHashStore* new_pref_hash_store, | |
130 PrefHashStore* legacy_pref_hash_store, | |
114 bool* old_store_needs_cleanup, | 131 bool* old_store_needs_cleanup, |
115 bool* new_store_altered) { | 132 bool* new_store_altered) { |
133 scoped_ptr<PrefHashStoreTransaction> source_transaction( | |
134 old_pref_hash_store->BeginTransaction()); | |
135 scoped_ptr<PrefHashStoreTransaction> destination_transaction( | |
136 new_pref_hash_store->BeginTransaction()); | |
137 scoped_ptr<PrefHashStoreTransaction> legacy_transaction( | |
138 legacy_pref_hash_store->BeginTransaction()); | |
139 | |
116 for (std::set<std::string>::const_iterator it = pref_names.begin(); | 140 for (std::set<std::string>::const_iterator it = pref_names.begin(); |
117 it != pref_names.end(); ++it) { | 141 it != pref_names.end(); |
142 ++it) { | |
118 const std::string& pref_name = *it; | 143 const std::string& pref_name = *it; |
119 | 144 |
120 const base::Value* value_in_old_store = NULL; | 145 const base::Value* value_in_old_store = NULL; |
121 if (!old_store->Get(pref_name, &value_in_old_store)) | 146 const base::Value* value_in_new_store = NULL; |
122 continue; | 147 bool migrate_hash = !destination_transaction->GetHash(pref_name); |
148 if (old_store->Get(pref_name, &value_in_old_store)) { | |
149 // Whether this value ends up being copied below or was left behind by a | |
150 // previous incomplete migration, it should be cleaned up. | |
151 *old_store_needs_cleanup = true; | |
123 | 152 |
124 // Whether this value ends up being copied below or was left behind by a | 153 if (!new_store->Get(pref_name, &value_in_new_store)) { |
gab
2014/06/06 21:55:00
Remove the |value_in_new_store| variable, you can
erikwright (departed)
2014/06/10 20:27:48
Done.
| |
125 // previous incomplete migration, it should be cleaned up. | 154 // Copy the value from |old_store| to |new_store| rather than moving it |
126 *old_store_needs_cleanup = true; | 155 // to avoid data loss should |old_store| be flushed to disk without |
156 // |new_store| having equivalently been successfully flushed to disk | |
157 // (e.g., on crash or in cases where |new_store| is read-only following | |
158 // a read error on startup). | |
159 scoped_ptr<base::Value> value_copy(value_in_old_store->DeepCopy()); | |
160 value_in_new_store = value_copy.get(); | |
161 new_store->Set(pref_name, value_copy.release()); | |
162 *new_store_altered = true; | |
163 migrate_hash = true; | |
164 } | |
165 } | |
127 | 166 |
128 if (new_store->Get(pref_name, NULL)) | 167 if (migrate_hash) { |
129 continue; | 168 const base::Value* old_hash = source_transaction->GetHash(pref_name); |
130 | 169 if (!old_hash) |
131 // Copy the value from |old_store| to |new_store| rather than moving it to | 170 old_hash = legacy_transaction->GetHash(pref_name); |
132 // avoid data loss should |old_store| be flushed to disk without |new_store| | 171 destination_transaction->ImportHash(pref_name, old_hash); |
133 // having equivalently been successfully flushed to disk (e.g., on crash or | 172 *new_store_altered = true; |
134 // in cases where |new_store| is read-only following a read error on | 173 } |
135 // startup). | |
136 new_store->Set(pref_name, value_in_old_store->DeepCopy()); | |
137 *new_store_altered = true; | |
138 } | 174 } |
139 } | 175 } |
140 | 176 |
141 TrackedPreferencesMigrator::TrackedPreferencesMigrator( | 177 TrackedPreferencesMigrator::TrackedPreferencesMigrator( |
142 const std::set<std::string>& unprotected_pref_names, | 178 const std::set<std::string>& unprotected_pref_names, |
143 const std::set<std::string>& protected_pref_names, | 179 const std::set<std::string>& protected_pref_names, |
144 const base::Callback<void(const std::string& key)>& | 180 scoped_ptr<TrackedPreferencesMigrationDelegate> unprotected_delegate, |
145 unprotected_store_cleaner, | 181 scoped_ptr<TrackedPreferencesMigrationDelegate> protected_delegate, |
146 const base::Callback<void(const std::string& key)>& protected_store_cleaner, | 182 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), | 183 : unprotected_pref_names_(unprotected_pref_names), |
154 protected_pref_names_(protected_pref_names), | 184 protected_pref_names_(protected_pref_names), |
155 unprotected_store_cleaner_(unprotected_store_cleaner), | 185 unprotected_delegate_(unprotected_delegate.Pass()), |
156 protected_store_cleaner_(protected_store_cleaner), | 186 protected_delegate_(protected_delegate.Pass()), |
157 register_on_successful_unprotected_store_write_callback_( | 187 legacy_pref_hash_store_(legacy_pref_hash_store.Pass()), |
158 register_on_successful_unprotected_store_write_callback), | 188 unprotected_prefs_(NULL), |
159 register_on_successful_protected_store_write_callback_( | 189 protected_prefs_(NULL) { |
160 register_on_successful_protected_store_write_callback) { | |
161 // The callbacks bound below will own this TrackedPreferencesMigrator by | 190 // The callbacks bound below will own this TrackedPreferencesMigrator by |
162 // reference. | 191 // reference. |
163 unprotected_pref_filter->InterceptNextFilterOnLoad( | 192 unprotected_delegate_->InterceptLoadedPreferences( |
164 base::Bind(&TrackedPreferencesMigrator::InterceptFilterOnLoad, | 193 base::Bind(&TrackedPreferencesMigrator::InterceptFilterOnLoad, |
165 this, | 194 this, |
166 UNPROTECTED_PREF_FILTER)); | 195 UNPROTECTED_PREF_FILTER)); |
167 protected_pref_filter->InterceptNextFilterOnLoad( | 196 protected_delegate_->InterceptLoadedPreferences( |
168 base::Bind(&TrackedPreferencesMigrator::InterceptFilterOnLoad, | 197 base::Bind(&TrackedPreferencesMigrator::InterceptFilterOnLoad, |
169 this, | 198 this, |
170 PROTECTED_PREF_FILTER)); | 199 PROTECTED_PREF_FILTER)); |
171 } | 200 } |
172 | 201 |
173 TrackedPreferencesMigrator::~TrackedPreferencesMigrator() {} | 202 TrackedPreferencesMigrator::~TrackedPreferencesMigrator() {} |
174 | 203 |
175 void TrackedPreferencesMigrator::InterceptFilterOnLoad( | 204 void TrackedPreferencesMigrator::InterceptFilterOnLoad( |
176 PrefFilterID id, | 205 PrefFilterID id, |
177 const InterceptablePrefFilter::FinalizeFilterOnLoadCallback& | 206 const TrackedPreferencesMigrationDelegate::InterceptCompletionCallback& |
178 finalize_filter_on_load, | 207 completion_callback, |
179 scoped_ptr<base::DictionaryValue> prefs) { | 208 base::DictionaryValue* prefs) { |
180 switch (id) { | 209 switch (id) { |
181 case UNPROTECTED_PREF_FILTER: | 210 case UNPROTECTED_PREF_FILTER: |
182 finalize_unprotected_filter_on_load_ = finalize_filter_on_load; | 211 unprotected_intercept_completion_callback_ = completion_callback; |
183 unprotected_prefs_ = prefs.Pass(); | 212 unprotected_prefs_ = prefs; |
184 break; | 213 break; |
185 case PROTECTED_PREF_FILTER: | 214 case PROTECTED_PREF_FILTER: |
186 finalize_protected_filter_on_load_ = finalize_filter_on_load; | 215 protected_intercept_completion_callback_ = completion_callback; |
187 protected_prefs_ = prefs.Pass(); | 216 protected_prefs_ = prefs; |
188 break; | 217 break; |
189 } | 218 } |
190 | 219 |
191 MigrateIfReady(); | 220 MigrateIfReady(); |
192 } | 221 } |
193 | 222 |
194 void TrackedPreferencesMigrator::MigrateIfReady() { | 223 void TrackedPreferencesMigrator::MigrateIfReady() { |
195 // Wait for both stores to have been read before proceeding. | 224 // Wait for both stores to have been read before proceeding. |
196 if (!protected_prefs_ || !unprotected_prefs_) | 225 if (!protected_prefs_ || !unprotected_prefs_) |
197 return; | 226 return; |
198 | 227 |
199 bool protected_prefs_need_cleanup = false; | 228 bool protected_prefs_need_cleanup = false; |
200 bool unprotected_prefs_altered = false; | 229 bool unprotected_prefs_altered = false; |
201 MigratePrefsFromOldToNewStore(unprotected_pref_names_, | 230 MigratePrefsFromOldToNewStore(unprotected_pref_names_, |
202 protected_prefs_.get(), | 231 protected_prefs_, |
203 unprotected_prefs_.get(), | 232 unprotected_prefs_, |
233 protected_delegate_->GetPrefHashStore(), | |
234 unprotected_delegate_->GetPrefHashStore(), | |
235 legacy_pref_hash_store_.get(), | |
204 &protected_prefs_need_cleanup, | 236 &protected_prefs_need_cleanup, |
205 &unprotected_prefs_altered); | 237 &unprotected_prefs_altered); |
206 bool unprotected_prefs_need_cleanup = false; | 238 bool unprotected_prefs_need_cleanup = false; |
207 bool protected_prefs_altered = false; | 239 bool protected_prefs_altered = false; |
208 MigratePrefsFromOldToNewStore(protected_pref_names_, | 240 MigratePrefsFromOldToNewStore(protected_pref_names_, |
209 unprotected_prefs_.get(), | 241 unprotected_prefs_, |
210 protected_prefs_.get(), | 242 protected_prefs_, |
243 unprotected_delegate_->GetPrefHashStore(), | |
244 protected_delegate_->GetPrefHashStore(), | |
245 legacy_pref_hash_store_.get(), | |
211 &unprotected_prefs_need_cleanup, | 246 &unprotected_prefs_need_cleanup, |
212 &protected_prefs_altered); | 247 &protected_prefs_altered); |
213 | 248 |
214 // Hand the processed prefs back to their respective filters. | 249 // Hand the processed prefs back to their respective filters. |
215 finalize_unprotected_filter_on_load_.Run(unprotected_prefs_.Pass(), | 250 unprotected_intercept_completion_callback_.Run(unprotected_prefs_altered); |
216 unprotected_prefs_altered); | 251 protected_intercept_completion_callback_.Run(protected_prefs_altered); |
217 finalize_protected_filter_on_load_.Run(protected_prefs_.Pass(), | 252 scoped_refptr<base::RefCountedData<int> > pending_commits( |
218 protected_prefs_altered); | 253 new base::RefCountedData<int>((unprotected_prefs_altered ? 1 : 0) + |
219 | 254 (protected_prefs_altered ? 1 : 0))); |
220 if (unprotected_prefs_need_cleanup) { | 255 if (!pending_commits->data) { |
gab
2014/06/06 21:54:59
Above I suggested getting rid of |pending_commits|
erikwright (departed)
2014/06/10 20:27:48
Done.
| |
221 // Schedule a cleanup of the |protected_pref_names_| from the unprotected | 256 this->legacy_pref_hash_store_->Reset(); |
222 // prefs once the protected prefs were successfully written to disk (or | 257 } else { |
gab
2014/06/06 21:54:59
Remove this else conditional, the code below needs
erikwright (departed)
2014/06/10 20:27:48
Done.
| |
223 // do it immediately if |!protected_prefs_altered|). | 258 if (unprotected_prefs_need_cleanup) { |
224 ScheduleSourcePrefStoreCleanup( | 259 // Schedule a cleanup of the |protected_pref_names_| from the unprotected |
225 register_on_successful_protected_store_write_callback_, | 260 // prefs once the protected prefs were successfully written to disk (or |
226 unprotected_store_cleaner_, | 261 // do it immediately if |!protected_prefs_altered|). |
227 protected_pref_names_, | 262 ScheduleSourcePrefStoreAndLocalStateCleanup(unprotected_delegate_.get(), |
228 protected_prefs_altered); | 263 protected_delegate_.get(), |
229 } | 264 protected_pref_names_, |
230 | 265 protected_prefs_altered, |
231 if (protected_prefs_need_cleanup) { | 266 pending_commits); |
232 // Schedule a cleanup of the |unprotected_pref_names_| from the protected | 267 } |
233 // prefs once the unprotected prefs were successfully written to disk (or | 268 if (protected_prefs_need_cleanup) { |
234 // do it immediately if |!unprotected_prefs_altered|). | 269 // Schedule a cleanup of the |unprotected_pref_names_| from the protected |
235 ScheduleSourcePrefStoreCleanup( | 270 // prefs once the unprotected prefs were successfully written to disk (or |
236 register_on_successful_unprotected_store_write_callback_, | 271 // do it immediately if |!unprotected_prefs_altered|). |
237 protected_store_cleaner_, | 272 ScheduleSourcePrefStoreAndLocalStateCleanup(protected_delegate_.get(), |
238 unprotected_pref_names_, | 273 unprotected_delegate_.get(), |
239 unprotected_prefs_altered); | 274 unprotected_pref_names_, |
275 unprotected_prefs_altered, | |
276 pending_commits); | |
277 } | |
240 } | 278 } |
241 } | 279 } |
242 | 280 |
243 } // namespace | 281 } // namespace |
244 | 282 |
245 void SetupTrackedPreferencesMigration( | 283 void SetupTrackedPreferencesMigration( |
246 const std::set<std::string>& unprotected_pref_names, | 284 const std::set<std::string>& unprotected_pref_names, |
247 const std::set<std::string>& protected_pref_names, | 285 const std::set<std::string>& protected_pref_names, |
248 const base::Callback<void(const std::string& key)>& | 286 scoped_ptr<TrackedPreferencesMigrationDelegate> unprotected_delegate, |
249 unprotected_store_cleaner, | 287 scoped_ptr<TrackedPreferencesMigrationDelegate> protected_delegate, |
250 const base::Callback<void(const std::string& key)>& protected_store_cleaner, | 288 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( | 289 scoped_refptr<TrackedPreferencesMigrator> prefs_migrator( |
258 new TrackedPreferencesMigrator( | 290 new TrackedPreferencesMigrator(unprotected_pref_names, |
259 unprotected_pref_names, | 291 protected_pref_names, |
260 protected_pref_names, | 292 unprotected_delegate.Pass(), |
261 unprotected_store_cleaner, | 293 protected_delegate.Pass(), |
262 protected_store_cleaner, | 294 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 } | 295 } |
OLD | NEW |