OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/pref_hash_filter.h" | 5 #include "services/preferences/tracked/pref_hash_filter.h" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 #include <algorithm> | 8 #include <algorithm> |
9 #include <utility> | 9 #include <utility> |
10 | 10 |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
48 } // namespace | 48 } // namespace |
49 | 49 |
50 using PrefTrackingStrategy = | 50 using PrefTrackingStrategy = |
51 prefs::mojom::TrackedPreferenceMetadata::PrefTrackingStrategy; | 51 prefs::mojom::TrackedPreferenceMetadata::PrefTrackingStrategy; |
52 | 52 |
53 PrefHashFilter::PrefHashFilter( | 53 PrefHashFilter::PrefHashFilter( |
54 std::unique_ptr<PrefHashStore> pref_hash_store, | 54 std::unique_ptr<PrefHashStore> pref_hash_store, |
55 StoreContentsPair external_validation_hash_store_pair, | 55 StoreContentsPair external_validation_hash_store_pair, |
56 const std::vector<prefs::mojom::TrackedPreferenceMetadataPtr>& | 56 const std::vector<prefs::mojom::TrackedPreferenceMetadataPtr>& |
57 tracked_preferences, | 57 tracked_preferences, |
58 const base::Closure& on_reset_on_load, | 58 prefs::mojom::ResetOnLoadObserverPtr reset_on_load_observer, |
59 prefs::mojom::TrackedPreferenceValidationDelegate* delegate, | 59 prefs::mojom::TrackedPreferenceValidationDelegate* delegate, |
60 size_t reporting_ids_count, | 60 size_t reporting_ids_count, |
61 bool report_super_mac_validity) | 61 bool report_super_mac_validity) |
62 : pref_hash_store_(std::move(pref_hash_store)), | 62 : pref_hash_store_(std::move(pref_hash_store)), |
63 external_validation_hash_store_pair_( | 63 external_validation_hash_store_pair_( |
64 external_validation_hash_store_pair.first | 64 external_validation_hash_store_pair.first |
65 ? base::make_optional( | 65 ? base::make_optional( |
66 std::move(external_validation_hash_store_pair)) | 66 std::move(external_validation_hash_store_pair)) |
67 : base::nullopt), | 67 : base::nullopt), |
68 on_reset_on_load_(on_reset_on_load), | 68 reset_on_load_observer_(std::move(reset_on_load_observer)), |
69 report_super_mac_validity_(report_super_mac_validity) { | 69 report_super_mac_validity_(report_super_mac_validity) { |
70 DCHECK(pref_hash_store_); | 70 DCHECK(pref_hash_store_); |
71 DCHECK_GE(reporting_ids_count, tracked_preferences.size()); | 71 DCHECK_GE(reporting_ids_count, tracked_preferences.size()); |
72 // Verify that, if |external_validation_hash_store_pair_| is present, both its | 72 // Verify that, if |external_validation_hash_store_pair_| is present, both its |
73 // items are non-null. | 73 // items are non-null. |
74 DCHECK(!external_validation_hash_store_pair_.has_value() || | 74 DCHECK(!external_validation_hash_store_pair_.has_value() || |
75 (external_validation_hash_store_pair_->first && | 75 (external_validation_hash_store_pair_->first && |
76 external_validation_hash_store_pair_->second)); | 76 external_validation_hash_store_pair_->second)); |
77 | 77 |
78 for (size_t i = 0; i < tracked_preferences.size(); ++i) { | 78 for (size_t i = 0; i < tracked_preferences.size(); ++i) { |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
241 if (hash_store_transaction->StampSuperMac()) | 241 if (hash_store_transaction->StampSuperMac()) |
242 prefs_altered = true; | 242 prefs_altered = true; |
243 } | 243 } |
244 | 244 |
245 if (did_reset) { | 245 if (did_reset) { |
246 pref_store_contents->Set(user_prefs::kPreferenceResetTime, | 246 pref_store_contents->Set(user_prefs::kPreferenceResetTime, |
247 new base::Value(base::Int64ToString( | 247 new base::Value(base::Int64ToString( |
248 base::Time::Now().ToInternalValue()))); | 248 base::Time::Now().ToInternalValue()))); |
249 FilterUpdate(user_prefs::kPreferenceResetTime); | 249 FilterUpdate(user_prefs::kPreferenceResetTime); |
250 | 250 |
251 if (!on_reset_on_load_.is_null()) | 251 if (reset_on_load_observer_) |
252 on_reset_on_load_.Run(); | 252 reset_on_load_observer_->OnResetOnLoad(); |
253 } | 253 } |
254 on_reset_on_load_.Reset(); | 254 reset_on_load_observer_.reset(); |
255 | 255 |
256 UMA_HISTOGRAM_TIMES("Settings.FilterOnLoadTime", | 256 UMA_HISTOGRAM_TIMES("Settings.FilterOnLoadTime", |
257 base::TimeTicks::Now() - checkpoint); | 257 base::TimeTicks::Now() - checkpoint); |
258 | 258 |
259 post_filter_on_load_callback.Run(std::move(pref_store_contents), | 259 post_filter_on_load_callback.Run(std::move(pref_store_contents), |
260 prefs_altered); | 260 prefs_altered); |
261 } | 261 } |
262 | 262 |
263 // static | 263 // static |
264 void PrefHashFilter::ClearFromExternalStore( | 264 void PrefHashFilter::ClearFromExternalStore( |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
357 // which owns the pointers. | 357 // which owns the pointers. |
358 HashStoreContents* raw_contents = hash_store_contents_copy.get(); | 358 HashStoreContents* raw_contents = hash_store_contents_copy.get(); |
359 base::DictionaryValue* raw_changed_paths_macs = changed_paths_macs.get(); | 359 base::DictionaryValue* raw_changed_paths_macs = changed_paths_macs.get(); |
360 | 360 |
361 return std::make_pair( | 361 return std::make_pair( |
362 base::Bind(&ClearFromExternalStore, base::Unretained(raw_contents), | 362 base::Bind(&ClearFromExternalStore, base::Unretained(raw_contents), |
363 base::Unretained(raw_changed_paths_macs)), | 363 base::Unretained(raw_changed_paths_macs)), |
364 base::Bind(&FlushToExternalStore, base::Passed(&hash_store_contents_copy), | 364 base::Bind(&FlushToExternalStore, base::Passed(&hash_store_contents_copy), |
365 base::Passed(&changed_paths_macs))); | 365 base::Passed(&changed_paths_macs))); |
366 } | 366 } |
OLD | NEW |