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

Side by Side Diff: chrome/browser/prefs/profile_pref_store_manager.cc

Issue 2745563005: Pref service: add support for tracked prefs. (Closed)
Patch Set: around go the deps Created 3 years, 9 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "chrome/browser/prefs/profile_pref_store_manager.h" 5 #include "chrome/browser/prefs/profile_pref_store_manager.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/callback.h" 10 #include "base/callback.h"
11 #include "base/files/file_util.h" 11 #include "base/files/file_util.h"
12 #include "base/json/json_file_value_serializer.h" 12 #include "base/json/json_file_value_serializer.h"
13 #include "base/logging.h" 13 #include "base/logging.h"
14 #include "base/memory/ptr_util.h" 14 #include "base/memory/ptr_util.h"
15 #include "base/metrics/histogram_macros.h" 15 #include "base/metrics/histogram_macros.h"
16 #include "base/sequenced_task_runner.h" 16 #include "base/sequenced_task_runner.h"
17 #include "build/build_config.h" 17 #include "build/build_config.h"
18 #include "chrome/common/chrome_constants.h" 18 #include "chrome/common/chrome_constants.h"
19 #include "components/pref_registry/pref_registry_syncable.h" 19 #include "components/pref_registry/pref_registry_syncable.h"
20 #include "components/prefs/json_pref_store.h" 20 #include "components/prefs/json_pref_store.h"
21 #include "components/prefs/persistent_pref_store.h" 21 #include "components/prefs/persistent_pref_store.h"
22 #include "components/prefs/pref_registry_simple.h" 22 #include "components/prefs/pref_registry_simple.h"
23 #include "components/user_prefs/tracked/pref_hash_store_impl.h" 23 #include "components/user_prefs/tracked/pref_hash_store_impl.h"
24 #include "components/user_prefs/tracked/segregated_pref_store.h" 24 #include "components/user_prefs/tracked/segregated_pref_store.h"
25 #include "components/user_prefs/tracked/tracked_preferences_migration.h" 25 #include "components/user_prefs/tracked/tracked_preferences_migration.h"
26 #include "services/preferences/public/cpp/tracked_persistent_pref_store_factory. h"
27 #include "services/preferences/public/interfaces/preferences_configuration.mojom .h"
26 28
27 #if defined(OS_WIN) 29 #if defined(OS_WIN)
28 #include "chrome/install_static/install_util.h" 30 #include "chrome/install_static/install_util.h"
29 #include "components/user_prefs/tracked/registry_hash_store_contents_win.h" 31 #include "components/user_prefs/tracked/registry_hash_store_contents_win.h"
30 #endif 32 #endif
31 33
32 namespace { 34 namespace {
33 35
34 void RemoveValueSilently(const base::WeakPtr<JsonPrefStore> pref_store,
35 const std::string& key) {
36 if (pref_store) {
37 pref_store->RemoveValueSilently(
38 key, WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS);
39 }
40 }
41
42 #if defined(OS_WIN) 36 #if defined(OS_WIN)
43 // Forces a different registry key to be used for storing preference validation 37 // Forces a different registry key to be used for storing preference validation
44 // MACs. See |SetPreferenceValidationRegistryPathForTesting|. 38 // MACs. See |SetPreferenceValidationRegistryPathForTesting|.
45 const base::string16* g_preference_validation_registry_path_for_testing = 39 const base::string16* g_preference_validation_registry_path_for_testing =
46 nullptr; 40 nullptr;
47 #endif // OS_WIN 41 #endif // OS_WIN
48 42
49 } // namespace 43 } // namespace
50 44
51 // Preference tracking and protection is not required on platforms where other 45 // Preference tracking and protection is not required on platforms where other
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 #if defined(OS_WIN) 87 #if defined(OS_WIN)
94 // static 88 // static
95 void ProfilePrefStoreManager::SetPreferenceValidationRegistryPathForTesting( 89 void ProfilePrefStoreManager::SetPreferenceValidationRegistryPathForTesting(
96 const base::string16* path) { 90 const base::string16* path) {
97 DCHECK(!path->empty()); 91 DCHECK(!path->empty());
98 g_preference_validation_registry_path_for_testing = path; 92 g_preference_validation_registry_path_for_testing = path;
99 } 93 }
100 #endif // OS_WIN 94 #endif // OS_WIN
101 95
102 PersistentPrefStore* ProfilePrefStoreManager::CreateProfilePrefStore( 96 PersistentPrefStore* ProfilePrefStoreManager::CreateProfilePrefStore(
103 const scoped_refptr<base::SequencedTaskRunner>& io_task_runner, 97 const scoped_refptr<base::SequencedTaskRunner>& io_task_runner,
gab 2017/03/13 16:52:02 C++11 adjustment: Take scoped_refptr by value and
Sam McNally 2017/03/14 02:01:35 Done.
104 const base::Closure& on_reset_on_load, 98 const base::Closure& on_reset_on_load,
105 prefs::mojom::TrackedPreferenceValidationDelegate* validation_delegate) { 99 prefs::mojom::TrackedPreferenceValidationDelegate* validation_delegate) {
106 std::unique_ptr<PrefFilter> pref_filter; 100 std::unique_ptr<PrefFilter> pref_filter;
gab 2017/03/13 16:52:02 Unused?
Sam McNally 2017/03/14 02:01:35 Done.
107 if (!kPlatformSupportsPreferenceTracking) { 101 if (!kPlatformSupportsPreferenceTracking) {
108 return new JsonPrefStore(profile_path_.Append(chrome::kPreferencesFilename), 102 return new JsonPrefStore(profile_path_.Append(chrome::kPreferencesFilename),
109 io_task_runner.get(), 103 io_task_runner.get(),
110 std::unique_ptr<PrefFilter>()); 104 std::unique_ptr<PrefFilter>());
111 } 105 }
112 106 return prefs::CreateTrackedPersistentPrefStore(
113 std::vector<PrefHashFilter::TrackedPreferenceMetadata> 107 io_task_runner, profile_path_.Append(chrome::kPreferencesFilename),
114 unprotected_configuration;
115 std::vector<PrefHashFilter::TrackedPreferenceMetadata>
116 protected_configuration;
117 std::set<std::string> protected_pref_names;
118 std::set<std::string> unprotected_pref_names;
119 for (std::vector<PrefHashFilter::TrackedPreferenceMetadata>::const_iterator
120 it = tracking_configuration_.begin();
121 it != tracking_configuration_.end();
122 ++it) {
123 if (it->enforcement_level > PrefHashFilter::NO_ENFORCEMENT) {
124 protected_configuration.push_back(*it);
125 protected_pref_names.insert(it->name);
126 } else {
127 unprotected_configuration.push_back(*it);
128 unprotected_pref_names.insert(it->name);
129 }
130 }
131
132 std::unique_ptr<PrefHashFilter> unprotected_pref_hash_filter(
133 new PrefHashFilter(GetPrefHashStore(false),
134 GetExternalVerificationPrefHashStorePair(),
135 unprotected_configuration, base::Closure(),
136 validation_delegate, reporting_ids_count_, false));
137 std::unique_ptr<PrefHashFilter> protected_pref_hash_filter(new PrefHashFilter(
138 GetPrefHashStore(true), GetExternalVerificationPrefHashStorePair(),
gab 2017/03/13 16:52:02 It's weird to drop usage of GetExternalVerificatio
Sam McNally 2017/03/14 02:01:35 In the longer term, the configuration will only be
139 protected_configuration, on_reset_on_load, validation_delegate,
140 reporting_ids_count_, true));
141
142 PrefHashFilter* raw_unprotected_pref_hash_filter =
143 unprotected_pref_hash_filter.get();
144 PrefHashFilter* raw_protected_pref_hash_filter =
145 protected_pref_hash_filter.get();
146
147 scoped_refptr<JsonPrefStore> unprotected_pref_store(new JsonPrefStore(
148 profile_path_.Append(chrome::kPreferencesFilename), io_task_runner.get(),
149 std::move(unprotected_pref_hash_filter)));
150 // TODO(gab): Remove kDeprecatedProtectedPreferencesFilename as an alternate
gab 2017/03/13 16:52:01 Could you do this cleanup in a precursor CL (and a
Sam McNally 2017/03/14 02:01:35 https://codereview.chromium.org/2751603002/
151 // file in M40+.
152 scoped_refptr<JsonPrefStore> protected_pref_store(new JsonPrefStore(
153 profile_path_.Append(chrome::kSecurePreferencesFilename), 108 profile_path_.Append(chrome::kSecurePreferencesFilename),
154 profile_path_.Append(chrome::kProtectedPreferencesFilenameDeprecated), 109 tracking_configuration_, reporting_ids_count_, seed_, legacy_device_id_,
155 io_task_runner.get(), std::move(protected_pref_hash_filter))); 110 #if defined(OS_WIN)
156 111 g_preference_validation_registry_path_for_testing
157 SetupTrackedPreferencesMigration( 112 ? *g_preference_validation_registry_path_for_testing
158 unprotected_pref_names, protected_pref_names, 113 : install_static::GetRegistryPath(),
159 base::Bind(&RemoveValueSilently, unprotected_pref_store->AsWeakPtr()), 114 #else
160 base::Bind(&RemoveValueSilently, protected_pref_store->AsWeakPtr()), 115 base::string16(),
161 base::Bind(&JsonPrefStore::RegisterOnNextSuccessfulWriteReply, 116 #endif
162 unprotected_pref_store->AsWeakPtr()), 117 validation_delegate, on_reset_on_load);
163 base::Bind(&JsonPrefStore::RegisterOnNextSuccessfulWriteReply,
164 protected_pref_store->AsWeakPtr()),
165 GetPrefHashStore(false), GetPrefHashStore(true),
166 raw_unprotected_pref_hash_filter, raw_protected_pref_hash_filter);
167
168 return new SegregatedPrefStore(unprotected_pref_store, protected_pref_store,
169 protected_pref_names);
170 } 118 }
171 119
172 bool ProfilePrefStoreManager::InitializePrefsFromMasterPrefs( 120 bool ProfilePrefStoreManager::InitializePrefsFromMasterPrefs(
173 std::unique_ptr<base::DictionaryValue> master_prefs) { 121 std::unique_ptr<base::DictionaryValue> master_prefs) {
174 // Create the profile directory if it doesn't exist yet (very possible on 122 // Create the profile directory if it doesn't exist yet (very possible on
175 // first run). 123 // first run).
176 if (!base::CreateDirectory(profile_path_)) 124 if (!base::CreateDirectory(profile_path_))
177 return false; 125 return false;
178 126
179 if (kPlatformSupportsPreferenceTracking) { 127 if (kPlatformSupportsPreferenceTracking) {
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
220 ? base::MakeUnique<RegistryHashStoreContentsWin>( 168 ? base::MakeUnique<RegistryHashStoreContentsWin>(
221 *g_preference_validation_registry_path_for_testing, 169 *g_preference_validation_registry_path_for_testing,
222 profile_path_.BaseName().LossyDisplayName()) 170 profile_path_.BaseName().LossyDisplayName())
223 : base::MakeUnique<RegistryHashStoreContentsWin>( 171 : base::MakeUnique<RegistryHashStoreContentsWin>(
224 install_static::GetRegistryPath(), 172 install_static::GetRegistryPath(),
225 profile_path_.BaseName().LossyDisplayName())); 173 profile_path_.BaseName().LossyDisplayName()));
226 #else 174 #else
227 return std::make_pair(nullptr, nullptr); 175 return std::make_pair(nullptr, nullptr);
228 #endif 176 #endif
229 } 177 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698