Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(401)

Side by Side Diff: services/preferences/tracked/tracked_persistent_pref_store_factory.cc

Issue 2799043003: Revert of Pref service: add support for tracked prefs. (Closed)
Patch Set: Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « services/preferences/tracked/tracked_persistent_pref_store_factory.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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 RemoveValueSilently(const base::WeakPtr<JsonPrefStore> pref_store,
28 const std::string& key) {
29 if (pref_store) {
30 pref_store->RemoveValueSilently(
31 key, WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS);
32 }
33 }
34
35 std::unique_ptr<PrefHashStore> CreatePrefHashStore(
36 const prefs::mojom::TrackedPersistentPrefStoreConfiguration& config,
37 bool use_super_mac) {
38 return base::MakeUnique<PrefHashStoreImpl>(
39 config.seed, config.legacy_device_id, use_super_mac);
40 }
41
42 std::pair<std::unique_ptr<PrefHashStore>, std::unique_ptr<HashStoreContents>>
43 GetExternalVerificationPrefHashStorePair(
44 const prefs::mojom::TrackedPersistentPrefStoreConfiguration& config) {
45 #if defined(OS_WIN)
46 return std::make_pair(
47 base::MakeUnique<PrefHashStoreImpl>(config.registry_seed,
48 config.legacy_device_id,
49 false /* use_super_mac */),
50 base::MakeUnique<RegistryHashStoreContentsWin>(
51 config.registry_path, config.unprotected_pref_filename.DirName()
52 .BaseName()
53 .LossyDisplayName()));
54 #else
55 return std::make_pair(nullptr, nullptr);
56 #endif
57 }
58
59 } // namespace
60
61 PersistentPrefStore* CreateTrackedPersistentPrefStore(
62 prefs::mojom::TrackedPersistentPrefStoreConfigurationPtr config,
63 base::SequencedWorkerPool* worker_pool) {
64 auto io_task_runner = JsonPrefStore::GetTaskRunnerForFile(
65 config->unprotected_pref_filename.DirName(), worker_pool);
66
67 std::vector<prefs::mojom::TrackedPreferenceMetadataPtr>
68 unprotected_configuration;
69 std::vector<prefs::mojom::TrackedPreferenceMetadataPtr>
70 protected_configuration;
71 std::set<std::string> protected_pref_names;
72 std::set<std::string> unprotected_pref_names;
73 for (auto& metadata : config->tracking_configuration) {
74 if (metadata->enforcement_level > prefs::mojom::TrackedPreferenceMetadata::
75 EnforcementLevel::NO_ENFORCEMENT) {
76 protected_pref_names.insert(metadata->name);
77 protected_configuration.push_back(std::move(metadata));
78 } else {
79 unprotected_pref_names.insert(metadata->name);
80 unprotected_configuration.push_back(std::move(metadata));
81 }
82 }
83 config->tracking_configuration.clear();
84
85 std::unique_ptr<PrefHashFilter> unprotected_pref_hash_filter(
86 new PrefHashFilter(CreatePrefHashStore(*config, false),
87 GetExternalVerificationPrefHashStorePair(*config),
88 unprotected_configuration, nullptr,
89 config->validation_delegate.get(),
90 config->reporting_ids_count, false));
91 std::unique_ptr<PrefHashFilter> protected_pref_hash_filter(new PrefHashFilter(
92 CreatePrefHashStore(*config, true),
93 GetExternalVerificationPrefHashStorePair(*config),
94 protected_configuration, std::move(config->reset_on_load_observer),
95 config->validation_delegate.get(), config->reporting_ids_count, true));
96
97 PrefHashFilter* raw_unprotected_pref_hash_filter =
98 unprotected_pref_hash_filter.get();
99 PrefHashFilter* raw_protected_pref_hash_filter =
100 protected_pref_hash_filter.get();
101
102 scoped_refptr<JsonPrefStore> unprotected_pref_store(
103 new JsonPrefStore(config->unprotected_pref_filename, io_task_runner.get(),
104 std::move(unprotected_pref_hash_filter)));
105 scoped_refptr<JsonPrefStore> protected_pref_store(
106 new JsonPrefStore(config->protected_pref_filename, io_task_runner.get(),
107 std::move(protected_pref_hash_filter)));
108
109 SetupTrackedPreferencesMigration(
110 unprotected_pref_names, protected_pref_names,
111 base::Bind(&RemoveValueSilently, unprotected_pref_store->AsWeakPtr()),
112 base::Bind(&RemoveValueSilently, protected_pref_store->AsWeakPtr()),
113 base::Bind(&JsonPrefStore::RegisterOnNextSuccessfulWriteReply,
114 unprotected_pref_store->AsWeakPtr()),
115 base::Bind(&JsonPrefStore::RegisterOnNextSuccessfulWriteReply,
116 protected_pref_store->AsWeakPtr()),
117 CreatePrefHashStore(*config, false), CreatePrefHashStore(*config, true),
118 raw_unprotected_pref_hash_filter, raw_protected_pref_hash_filter);
119
120 return new SegregatedPrefStore(unprotected_pref_store, protected_pref_store,
121 protected_pref_names,
122 std::move(config->validation_delegate));
123 }
124
125 void InitializeMasterPrefsTracking(
126 prefs::mojom::TrackedPersistentPrefStoreConfigurationPtr configuration,
127 base::DictionaryValue* master_prefs) {
128 PrefHashFilter(CreatePrefHashStore(*configuration, false),
129 GetExternalVerificationPrefHashStorePair(*configuration),
130 configuration->tracking_configuration, nullptr, nullptr,
131 configuration->reporting_ids_count, false)
132 .Initialize(master_prefs);
133 }
OLDNEW
« no previous file with comments | « services/preferences/tracked/tracked_persistent_pref_store_factory.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698