OLD | NEW |
(Empty) | |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "services/preferences/public/cpp/tracked_persistent_pref_store_factory.
h" |
| 6 |
| 7 #include <set> |
| 8 #include <utility> |
| 9 |
| 10 #include "components/prefs/json_pref_store.h" |
| 11 #include "components/prefs/pref_filter.h" |
| 12 #include "components/user_prefs/tracked/pref_hash_store_impl.h" |
| 13 #include "components/user_prefs/tracked/segregated_pref_store.h" |
| 14 #include "components/user_prefs/tracked/tracked_preferences_migration.h" |
| 15 #include "services/preferences/public/interfaces/tracked_preference_validation_d
elegate.mojom.h" |
| 16 |
| 17 #if defined(OS_WIN) |
| 18 #include "components/user_prefs/tracked/registry_hash_store_contents_win.h" |
| 19 #endif |
| 20 |
| 21 namespace prefs { |
| 22 namespace { |
| 23 |
| 24 void RemoveValueSilently(const base::WeakPtr<JsonPrefStore> pref_store, |
| 25 const std::string& key) { |
| 26 if (pref_store) { |
| 27 pref_store->RemoveValueSilently( |
| 28 key, WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS); |
| 29 } |
| 30 } |
| 31 |
| 32 std::unique_ptr<PrefHashStore> CreatePrefHashStore( |
| 33 const std::string& seed, |
| 34 const std::string& legacy_device_id, |
| 35 bool use_super_mac) { |
| 36 return base::MakeUnique<PrefHashStoreImpl>(seed, legacy_device_id, |
| 37 use_super_mac); |
| 38 } |
| 39 |
| 40 std::pair<std::unique_ptr<PrefHashStore>, std::unique_ptr<HashStoreContents>> |
| 41 GetExternalVerificationPrefHashStorePair(const std::string& seed, |
| 42 const std::string& legacy_device_id, |
| 43 const base::string16& registry_path, |
| 44 const base::FilePath& prefs_path) { |
| 45 #if defined(OS_WIN) |
| 46 return std::make_pair( |
| 47 base::MakeUnique<PrefHashStoreImpl>(seed, legacy_device_id, |
| 48 false /* use_super_mac */), |
| 49 base::MakeUnique<RegistryHashStoreContentsWin>( |
| 50 registry_path, prefs_path.DirName().BaseName().LossyDisplayName())); |
| 51 #else |
| 52 return std::make_pair(nullptr, nullptr); |
| 53 #endif |
| 54 } |
| 55 |
| 56 } // namespace |
| 57 |
| 58 PersistentPrefStore* CreateTrackedPersistentPrefStore( |
| 59 scoped_refptr<base::SequencedTaskRunner> io_task_runner, |
| 60 const base::FilePath& unprotected_pref_filename, |
| 61 const base::FilePath& protected_pref_filename, |
| 62 const std::vector<PrefHashFilter::TrackedPreferenceMetadata>& |
| 63 tracking_configuration, |
| 64 uint64_t reporting_ids_count, |
| 65 const std::string& seed, |
| 66 const std::string& legacy_device_id, |
| 67 const base::string16& registry_path, |
| 68 mojom::TrackedPreferenceValidationDelegate* validation_delegate, |
| 69 const base::Closure& on_reset_on_load) { |
| 70 std::vector<PrefHashFilter::TrackedPreferenceMetadata> |
| 71 unprotected_configuration; |
| 72 std::vector<PrefHashFilter::TrackedPreferenceMetadata> |
| 73 protected_configuration; |
| 74 std::set<std::string> protected_pref_names; |
| 75 std::set<std::string> unprotected_pref_names; |
| 76 for (const auto& metadata : tracking_configuration) { |
| 77 if (metadata.enforcement_level > |
| 78 mojom::TrackedPreferenceMetadata::EnforcementLevel::NO_ENFORCEMENT) { |
| 79 protected_configuration.push_back(metadata); |
| 80 protected_pref_names.insert(metadata.name); |
| 81 } else { |
| 82 unprotected_configuration.push_back(metadata); |
| 83 unprotected_pref_names.insert(metadata.name); |
| 84 } |
| 85 } |
| 86 |
| 87 std::unique_ptr<PrefHashFilter> unprotected_pref_hash_filter( |
| 88 new PrefHashFilter( |
| 89 CreatePrefHashStore(seed, legacy_device_id, false), |
| 90 GetExternalVerificationPrefHashStorePair( |
| 91 seed, legacy_device_id, registry_path, unprotected_pref_filename), |
| 92 unprotected_configuration, base::Closure(), validation_delegate, |
| 93 reporting_ids_count, false)); |
| 94 std::unique_ptr<PrefHashFilter> protected_pref_hash_filter(new PrefHashFilter( |
| 95 CreatePrefHashStore(seed, legacy_device_id, true), |
| 96 GetExternalVerificationPrefHashStorePair( |
| 97 seed, legacy_device_id, registry_path, unprotected_pref_filename), |
| 98 protected_configuration, on_reset_on_load, validation_delegate, |
| 99 reporting_ids_count, true)); |
| 100 |
| 101 PrefHashFilter* raw_unprotected_pref_hash_filter = |
| 102 unprotected_pref_hash_filter.get(); |
| 103 PrefHashFilter* raw_protected_pref_hash_filter = |
| 104 protected_pref_hash_filter.get(); |
| 105 |
| 106 scoped_refptr<JsonPrefStore> unprotected_pref_store( |
| 107 new JsonPrefStore(unprotected_pref_filename, io_task_runner.get(), |
| 108 std::move(unprotected_pref_hash_filter))); |
| 109 scoped_refptr<JsonPrefStore> protected_pref_store( |
| 110 new JsonPrefStore(protected_pref_filename, io_task_runner.get(), |
| 111 std::move(protected_pref_hash_filter))); |
| 112 |
| 113 SetupTrackedPreferencesMigration( |
| 114 unprotected_pref_names, protected_pref_names, |
| 115 base::Bind(&RemoveValueSilently, unprotected_pref_store->AsWeakPtr()), |
| 116 base::Bind(&RemoveValueSilently, protected_pref_store->AsWeakPtr()), |
| 117 base::Bind(&JsonPrefStore::RegisterOnNextSuccessfulWriteReply, |
| 118 unprotected_pref_store->AsWeakPtr()), |
| 119 base::Bind(&JsonPrefStore::RegisterOnNextSuccessfulWriteReply, |
| 120 protected_pref_store->AsWeakPtr()), |
| 121 CreatePrefHashStore(seed, legacy_device_id, false), |
| 122 CreatePrefHashStore(seed, legacy_device_id, true), |
| 123 raw_unprotected_pref_hash_filter, raw_protected_pref_hash_filter); |
| 124 |
| 125 return new SegregatedPrefStore(unprotected_pref_store, protected_pref_store, |
| 126 protected_pref_names); |
| 127 } |
| 128 |
| 129 } // namespace prefs |
OLD | NEW |