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 mojom::TrackedPersistentPrefStoreConfigurationPtr config, | |
61 mojom::TrackedPreferenceValidationDelegate* validation_delegate, | |
62 const base::Closure& on_reset_on_load) { | |
63 std::vector<PrefHashFilter::TrackedPreferenceMetadata> | |
64 unprotected_configuration; | |
65 std::vector<PrefHashFilter::TrackedPreferenceMetadata> | |
66 protected_configuration; | |
67 std::set<std::string> protected_pref_names; | |
68 std::set<std::string> unprotected_pref_names; | |
69 for (const auto& metadata : config->tracking_configuration) { | |
70 PrefHashFilter::TrackedPreferenceMetadata metadata_view = { | |
71 metadata->reporting_id, metadata->name.c_str(), | |
72 metadata->enforcement_level, metadata->strategy, | |
73 metadata->value_type, | |
74 }; | |
75 if (metadata->enforcement_level > | |
76 mojom::TrackedPreferenceMetadata::EnforcementLevel::NO_ENFORCEMENT) { | |
77 protected_configuration.push_back(metadata_view); | |
78 protected_pref_names.insert(metadata->name); | |
79 } else { | |
80 unprotected_configuration.push_back(metadata_view); | |
81 unprotected_pref_names.insert(metadata->name); | |
82 } | |
83 } | |
84 | |
85 std::unique_ptr<PrefHashFilter> unprotected_pref_hash_filter( | |
86 new PrefHashFilter( | |
87 CreatePrefHashStore(config->seed, config->legacy_device_id, false), | |
88 GetExternalVerificationPrefHashStorePair( | |
89 config->seed, config->legacy_device_id, config->registry_path, | |
gab
2017/03/28 16:42:08
This is the wrong seed, the external hash store us
Sam McNally
2017/03/30 09:06:05
Done.
| |
90 config->unprotected_pref_filename), | |
91 unprotected_configuration, base::Closure(), validation_delegate, | |
92 config->reporting_ids_count, false)); | |
93 std::unique_ptr<PrefHashFilter> protected_pref_hash_filter(new PrefHashFilter( | |
94 CreatePrefHashStore(config->seed, config->legacy_device_id, true), | |
95 GetExternalVerificationPrefHashStorePair( | |
96 config->seed, config->legacy_device_id, config->registry_path, | |
97 config->unprotected_pref_filename), | |
98 protected_configuration, on_reset_on_load, validation_delegate, | |
99 config->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(config->unprotected_pref_filename, io_task_runner.get(), | |
108 std::move(unprotected_pref_hash_filter))); | |
109 scoped_refptr<JsonPrefStore> protected_pref_store( | |
110 new JsonPrefStore(config->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(config->seed, config->legacy_device_id, false), | |
122 CreatePrefHashStore(config->seed, config->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 |