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/tracked/tracked_persistent_pref_store_factory.h" | |
6 | |
7 #include <memory> | |
8 #include <set> | |
9 #include <string> | |
10 #include <utility> | |
11 #include <vector> | |
12 | |
13 #include "components/prefs/json_pref_store.h" | |
14 #include "components/prefs/pref_filter.h" | |
15 #include "services/preferences/public/interfaces/tracked_preference_validation_d elegate.mojom.h" | |
16 #include "services/preferences/tracked/pref_hash_filter.h" | |
17 #include "services/preferences/tracked/pref_hash_store_impl.h" | |
18 #include "services/preferences/tracked/segregated_pref_store.h" | |
19 #include "services/preferences/tracked/tracked_preferences_migration.h" | |
20 | |
21 #if defined(OS_WIN) | |
22 #include "services/preferences/tracked/registry_hash_store_contents_win.h" | |
23 #endif | |
24 | |
25 namespace { | |
26 | |
27 void ForwardToResetOnLoadObserver( | |
28 prefs::mojom::ResetOnLoadObserverPtr observer) { | |
29 if (observer) | |
30 observer->OnResetOnLoad(); | |
31 } | |
32 | |
33 void RemoveValueSilently(const base::WeakPtr<JsonPrefStore> pref_store, | |
34 const std::string& key) { | |
35 if (pref_store) { | |
36 pref_store->RemoveValueSilently( | |
37 key, WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS); | |
38 } | |
39 } | |
40 | |
41 std::unique_ptr<PrefHashStore> CreatePrefHashStore( | |
42 const prefs::mojom::TrackedPersistentPrefStoreConfiguration& config, | |
43 bool use_super_mac) { | |
44 return base::MakeUnique<PrefHashStoreImpl>( | |
45 config.seed, config.legacy_device_id, use_super_mac); | |
46 } | |
47 | |
48 std::pair<std::unique_ptr<PrefHashStore>, std::unique_ptr<HashStoreContents>> | |
49 GetExternalVerificationPrefHashStorePair( | |
50 const prefs::mojom::TrackedPersistentPrefStoreConfiguration& config) { | |
51 #if defined(OS_WIN) | |
52 return std::make_pair( | |
53 base::MakeUnique<PrefHashStoreImpl>(config.registry_seed, | |
54 config.legacy_device_id, | |
55 false /* use_super_mac */), | |
56 base::MakeUnique<RegistryHashStoreContentsWin>( | |
57 config.registry_path, config.unprotected_pref_filename.DirName() | |
58 .BaseName() | |
59 .LossyDisplayName())); | |
60 #else | |
61 return std::make_pair(nullptr, nullptr); | |
62 #endif | |
63 } | |
64 | |
65 } // namespace | |
66 | |
67 PersistentPrefStore* CreateTrackedPersistentPrefStore( | |
68 prefs::mojom::TrackedPersistentPrefStoreConfigurationPtr config, | |
69 base::SequencedWorkerPool* worker_pool) { | |
70 auto io_task_runner = JsonPrefStore::GetTaskRunnerForFile( | |
71 config->unprotected_pref_filename.DirName(), worker_pool); | |
72 | |
73 std::vector<prefs::mojom::TrackedPreferenceMetadataPtr> | |
74 unprotected_configuration; | |
75 std::vector<prefs::mojom::TrackedPreferenceMetadataPtr> | |
76 protected_configuration; | |
77 std::set<std::string> protected_pref_names; | |
78 std::set<std::string> unprotected_pref_names; | |
79 for (auto& metadata : config->tracking_configuration) { | |
80 if (metadata->enforcement_level > prefs::mojom::TrackedPreferenceMetadata:: | |
81 EnforcementLevel::NO_ENFORCEMENT) { | |
82 protected_pref_names.insert(metadata->name); | |
83 protected_configuration.push_back(std::move(metadata)); | |
84 } else { | |
85 unprotected_pref_names.insert(metadata->name); | |
86 unprotected_configuration.push_back(std::move(metadata)); | |
87 } | |
88 } | |
89 config->tracking_configuration.clear(); | |
90 | |
91 auto on_reset_on_load = | |
92 base::Bind(&ForwardToResetOnLoadObserver, | |
93 base::Passed(&config->reset_on_load_observer)); | |
94 std::unique_ptr<PrefHashFilter> unprotected_pref_hash_filter( | |
95 new PrefHashFilter(CreatePrefHashStore(*config, false), | |
96 GetExternalVerificationPrefHashStorePair(*config), | |
97 unprotected_configuration, base::Closure(), | |
98 config->validation_delegate.get(), | |
99 config->reporting_ids_count, false)); | |
100 std::unique_ptr<PrefHashFilter> protected_pref_hash_filter(new PrefHashFilter( | |
101 CreatePrefHashStore(*config, true), | |
102 GetExternalVerificationPrefHashStorePair(*config), | |
103 protected_configuration, on_reset_on_load, | |
104 config->validation_delegate.get(), config->reporting_ids_count, true)); | |
105 | |
106 PrefHashFilter* raw_unprotected_pref_hash_filter = | |
107 unprotected_pref_hash_filter.get(); | |
108 PrefHashFilter* raw_protected_pref_hash_filter = | |
109 protected_pref_hash_filter.get(); | |
110 | |
111 scoped_refptr<JsonPrefStore> unprotected_pref_store( | |
112 new JsonPrefStore(config->unprotected_pref_filename, io_task_runner.get(), | |
113 std::move(unprotected_pref_hash_filter))); | |
114 scoped_refptr<JsonPrefStore> protected_pref_store( | |
115 new JsonPrefStore(config->protected_pref_filename, io_task_runner.get(), | |
116 std::move(protected_pref_hash_filter))); | |
117 | |
118 SetupTrackedPreferencesMigration( | |
119 unprotected_pref_names, protected_pref_names, | |
120 base::Bind(&RemoveValueSilently, unprotected_pref_store->AsWeakPtr()), | |
121 base::Bind(&RemoveValueSilently, protected_pref_store->AsWeakPtr()), | |
122 base::Bind(&JsonPrefStore::RegisterOnNextSuccessfulWriteReply, | |
123 unprotected_pref_store->AsWeakPtr()), | |
124 base::Bind(&JsonPrefStore::RegisterOnNextSuccessfulWriteReply, | |
125 protected_pref_store->AsWeakPtr()), | |
126 CreatePrefHashStore(*config, false), CreatePrefHashStore(*config, true), | |
127 raw_unprotected_pref_hash_filter, raw_protected_pref_hash_filter); | |
128 | |
129 return new SegregatedPrefStore(unprotected_pref_store, protected_pref_store, | |
130 protected_pref_names, | |
131 std::move(config->validation_delegate)); | |
132 } | |
133 | |
134 void InitializeMasterPrefsTracking( | |
135 prefs::mojom::TrackedPersistentPrefStoreConfigurationPtr configuration, | |
136 base::DictionaryValue* master_prefs) { | |
137 PrefHashFilter(CreatePrefHashStore(*configuration, false), | |
138 GetExternalVerificationPrefHashStorePair(*configuration), | |
139 configuration->tracking_configuration, base::Closure(), NULL, | |
Bernhard Bauer
2017/03/30 20:11:57
Nit: nullptr instead of NULL
Sam McNally
2017/03/30 23:24:08
Done.
| |
140 configuration->reporting_ids_count, false) | |
141 .Initialize(master_prefs); | |
142 } | |
OLD | NEW |