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 <memory> | 7 #include <memory> |
8 #include <set> | 8 #include <set> |
9 #include <string> | 9 #include <string> |
10 #include <utility> | 10 #include <utility> |
(...skipping 29 matching lines...) Expand all Loading... |
40 const char kProtectedPrefValue[] = "protected_value"; | 40 const char kProtectedPrefValue[] = "protected_value"; |
41 const char kPreviouslyUnprotectedPrefValue[] = "previously_unprotected_value"; | 41 const char kPreviouslyUnprotectedPrefValue[] = "previously_unprotected_value"; |
42 const char kPreviouslyProtectedPrefValue[] = "previously_protected_value"; | 42 const char kPreviouslyProtectedPrefValue[] = "previously_protected_value"; |
43 | 43 |
44 // A simple InterceptablePrefFilter which doesn't do anything but hand the prefs | 44 // A simple InterceptablePrefFilter which doesn't do anything but hand the prefs |
45 // back downstream in FinalizeFilterOnLoad. | 45 // back downstream in FinalizeFilterOnLoad. |
46 class SimpleInterceptablePrefFilter : public InterceptablePrefFilter { | 46 class SimpleInterceptablePrefFilter : public InterceptablePrefFilter { |
47 public: | 47 public: |
48 // PrefFilter remaining implementation. | 48 // PrefFilter remaining implementation. |
49 void FilterUpdate(const std::string& path) override { ADD_FAILURE(); } | 49 void FilterUpdate(const std::string& path) override { ADD_FAILURE(); } |
50 void FilterSerializeData( | 50 base::Callback<void(bool)> FilterSerializeData( |
51 base::DictionaryValue* pref_store_contents) override { | 51 base::DictionaryValue* pref_store_contents) override { |
52 ADD_FAILURE(); | 52 ADD_FAILURE(); |
| 53 return base::Callback<void(bool)>(); |
53 } | 54 } |
54 | 55 |
55 private: | 56 private: |
56 // InterceptablePrefFilter implementation. | 57 // InterceptablePrefFilter implementation. |
57 void FinalizeFilterOnLoad( | 58 void FinalizeFilterOnLoad( |
58 const PostFilterOnLoadCallback& post_filter_on_load_callback, | 59 const PostFilterOnLoadCallback& post_filter_on_load_callback, |
59 std::unique_ptr<base::DictionaryValue> pref_store_contents, | 60 std::unique_ptr<base::DictionaryValue> pref_store_contents, |
60 bool prefs_altered) override { | 61 bool prefs_altered) override { |
61 post_filter_on_load_callback.Run(std::move(pref_store_contents), | 62 post_filter_on_load_callback.Run(std::move(pref_store_contents), |
62 prefs_altered); | 63 prefs_altered); |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
155 pref_hash_store.reset(new PrefHashStoreImpl(kSeed, kDeviceId, false)); | 156 pref_hash_store.reset(new PrefHashStoreImpl(kSeed, kDeviceId, false)); |
156 break; | 157 break; |
157 case MOCK_PROTECTED_PREF_STORE: | 158 case MOCK_PROTECTED_PREF_STORE: |
158 store = protected_prefs_.get(); | 159 store = protected_prefs_.get(); |
159 pref_hash_store.reset(new PrefHashStoreImpl(kSeed, kDeviceId, true)); | 160 pref_hash_store.reset(new PrefHashStoreImpl(kSeed, kDeviceId, true)); |
160 break; | 161 break; |
161 } | 162 } |
162 DCHECK(store); | 163 DCHECK(store); |
163 | 164 |
164 base::StringValue string_value(value); | 165 base::StringValue string_value(value); |
165 pref_hash_store | 166 DictionaryHashStoreContents contents(store); |
166 ->BeginTransaction(std::unique_ptr<HashStoreContents>( | 167 pref_hash_store->BeginTransaction(&contents)->StoreHash(key, &string_value); |
167 new DictionaryHashStoreContents(store))) | |
168 ->StoreHash(key, &string_value); | |
169 } | 168 } |
170 | 169 |
171 // Returns true if the store opposite to |store_id| is observed for its next | 170 // Returns true if the store opposite to |store_id| is observed for its next |
172 // successful write. | 171 // successful write. |
173 bool WasOnSuccessfulWriteCallbackRegistered(MockPrefStoreID store_id) { | 172 bool WasOnSuccessfulWriteCallbackRegistered(MockPrefStoreID store_id) { |
174 switch (store_id) { | 173 switch (store_id) { |
175 case MOCK_UNPROTECTED_PREF_STORE: | 174 case MOCK_UNPROTECTED_PREF_STORE: |
176 return !protected_store_successful_write_callback_.is_null(); | 175 return !protected_store_successful_write_callback_.is_null(); |
177 case MOCK_PROTECTED_PREF_STORE: | 176 case MOCK_PROTECTED_PREF_STORE: |
178 return !unprotected_store_successful_write_callback_.is_null(); | 177 return !unprotected_store_successful_write_callback_.is_null(); |
(...skipping 467 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
646 expected_unprotected_values); | 645 expected_unprotected_values); |
647 | 646 |
648 base::StringPairs expected_protected_values; | 647 base::StringPairs expected_protected_values; |
649 expected_protected_values.push_back(std::make_pair( | 648 expected_protected_values.push_back(std::make_pair( |
650 kProtectedPref, kProtectedPrefValue)); | 649 kProtectedPref, kProtectedPrefValue)); |
651 expected_protected_values.push_back(std::make_pair( | 650 expected_protected_values.push_back(std::make_pair( |
652 kPreviouslyUnprotectedPref, kPreviouslyUnprotectedPrefValue)); | 651 kPreviouslyUnprotectedPref, kPreviouslyUnprotectedPrefValue)); |
653 VerifyValuesStored(MOCK_PROTECTED_PREF_STORE, expected_protected_values); | 652 VerifyValuesStored(MOCK_PROTECTED_PREF_STORE, expected_protected_values); |
654 } | 653 } |
655 } | 654 } |
OLD | NEW |