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

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

Issue 2782803002: Move tracked prefs into services/preferences/tracked. (Closed)
Patch Set: rebase 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
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 "chrome/common/chrome_features.h" 19 #include "chrome/common/chrome_features.h"
20 #include "components/pref_registry/pref_registry_syncable.h" 20 #include "components/pref_registry/pref_registry_syncable.h"
21 #include "components/prefs/json_pref_store.h" 21 #include "components/prefs/json_pref_store.h"
22 #include "components/prefs/persistent_pref_store.h" 22 #include "components/prefs/persistent_pref_store.h"
23 #include "components/prefs/pref_registry_simple.h" 23 #include "components/prefs/pref_registry_simple.h"
24 #include "components/user_prefs/tracked/pref_hash_store_impl.h"
25 #include "components/user_prefs/tracked/segregated_pref_store.h"
26 #include "components/user_prefs/tracked/tracked_preferences_migration.h"
27 #include "services/preferences/public/cpp/persistent_pref_store_client.h" 24 #include "services/preferences/public/cpp/persistent_pref_store_client.h"
28 #include "services/preferences/public/interfaces/preferences.mojom.h" 25 #include "services/preferences/public/interfaces/preferences.mojom.h"
26 #include "services/preferences/tracked/pref_hash_filter.h"
27 #include "services/preferences/tracked/pref_hash_store_impl.h"
28 #include "services/preferences/tracked/segregated_pref_store.h"
29 #include "services/preferences/tracked/tracked_preferences_migration.h"
29 #include "services/service_manager/public/cpp/connector.h" 30 #include "services/service_manager/public/cpp/connector.h"
30 31
31 #if defined(OS_WIN) 32 #if defined(OS_WIN)
32 #include "chrome/install_static/install_util.h" 33 #include "chrome/install_static/install_util.h"
33 #include "components/user_prefs/tracked/registry_hash_store_contents_win.h" 34 #include "services/preferences/tracked/registry_hash_store_contents_win.h"
34 #endif 35 #endif
35 36
36 namespace { 37 namespace {
37 38
39 using EnforcementLevel =
40 prefs::mojom::TrackedPreferenceMetadata::EnforcementLevel;
41
38 void RemoveValueSilently(const base::WeakPtr<JsonPrefStore> pref_store, 42 void RemoveValueSilently(const base::WeakPtr<JsonPrefStore> pref_store,
39 const std::string& key) { 43 const std::string& key) {
40 if (pref_store) { 44 if (pref_store) {
41 pref_store->RemoveValueSilently( 45 pref_store->RemoveValueSilently(
42 key, WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS); 46 key, WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS);
43 } 47 }
44 } 48 }
45 49
46 #if defined(OS_WIN) 50 #if defined(OS_WIN)
47 // Forces a different registry key to be used for storing preference validation 51 // Forces a different registry key to be used for storing preference validation
48 // MACs. See |SetPreferenceValidationRegistryPathForTesting|. 52 // MACs. See |SetPreferenceValidationRegistryPathForTesting|.
49 const base::string16* g_preference_validation_registry_path_for_testing = 53 const base::string16* g_preference_validation_registry_path_for_testing =
50 nullptr; 54 nullptr;
51 #endif // OS_WIN 55 #endif // OS_WIN
52 56
53 } // namespace 57 } // namespace
54 58
55 // Preference tracking and protection is not required on platforms where other 59 // Preference tracking and protection is not required on platforms where other
56 // apps do not have access to chrome's persistent storage. 60 // apps do not have access to chrome's persistent storage.
57 const bool ProfilePrefStoreManager::kPlatformSupportsPreferenceTracking = 61 const bool ProfilePrefStoreManager::kPlatformSupportsPreferenceTracking =
58 #if defined(OS_ANDROID) || defined(OS_CHROMEOS) 62 #if defined(OS_ANDROID) || defined(OS_CHROMEOS)
59 false; 63 false;
60 #else 64 #else
61 true; 65 true;
62 #endif 66 #endif
63 67
64 ProfilePrefStoreManager::ProfilePrefStoreManager( 68 ProfilePrefStoreManager::ProfilePrefStoreManager(
65 const base::FilePath& profile_path, 69 const base::FilePath& profile_path,
66 const std::vector<PrefHashFilter::TrackedPreferenceMetadata>& 70 std::vector<prefs::mojom::TrackedPreferenceMetadataPtr>
67 tracking_configuration, 71 tracking_configuration,
68 size_t reporting_ids_count, 72 size_t reporting_ids_count,
69 const std::string& seed, 73 const std::string& seed,
70 const std::string& legacy_device_id, 74 const std::string& legacy_device_id,
71 PrefService* local_state) 75 PrefService* local_state)
72 : profile_path_(profile_path), 76 : profile_path_(profile_path),
73 tracking_configuration_(tracking_configuration), 77 tracking_configuration_(std::move(tracking_configuration)),
74 reporting_ids_count_(reporting_ids_count), 78 reporting_ids_count_(reporting_ids_count),
75 seed_(seed), 79 seed_(seed),
76 legacy_device_id_(legacy_device_id), 80 legacy_device_id_(legacy_device_id),
77 local_state_(local_state) {} 81 local_state_(local_state) {}
78 82
79 ProfilePrefStoreManager::~ProfilePrefStoreManager() {} 83 ProfilePrefStoreManager::~ProfilePrefStoreManager() {}
80 84
81 // static 85 // static
82 void ProfilePrefStoreManager::RegisterProfilePrefs( 86 void ProfilePrefStoreManager::RegisterProfilePrefs(
83 user_prefs::PrefRegistrySyncable* registry) { 87 user_prefs::PrefRegistrySyncable* registry) {
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 connector->BindInterface(prefs::mojom::kServiceName, &pref_connector); 119 connector->BindInterface(prefs::mojom::kServiceName, &pref_connector);
116 return new prefs::PersistentPrefStoreClient(std::move(pref_connector), 120 return new prefs::PersistentPrefStoreClient(std::move(pref_connector),
117 std::move(pref_registry)); 121 std::move(pref_registry));
118 } 122 }
119 if (!kPlatformSupportsPreferenceTracking) { 123 if (!kPlatformSupportsPreferenceTracking) {
120 return new JsonPrefStore(profile_path_.Append(chrome::kPreferencesFilename), 124 return new JsonPrefStore(profile_path_.Append(chrome::kPreferencesFilename),
121 io_task_runner.get(), 125 io_task_runner.get(),
122 std::unique_ptr<PrefFilter>()); 126 std::unique_ptr<PrefFilter>());
123 } 127 }
124 128
125 std::vector<PrefHashFilter::TrackedPreferenceMetadata> 129 std::vector<prefs::mojom::TrackedPreferenceMetadataPtr>
126 unprotected_configuration; 130 unprotected_configuration;
127 std::vector<PrefHashFilter::TrackedPreferenceMetadata> 131 std::vector<prefs::mojom::TrackedPreferenceMetadataPtr>
128 protected_configuration; 132 protected_configuration;
129 std::set<std::string> protected_pref_names; 133 std::set<std::string> protected_pref_names;
130 std::set<std::string> unprotected_pref_names; 134 std::set<std::string> unprotected_pref_names;
131 for (std::vector<PrefHashFilter::TrackedPreferenceMetadata>::const_iterator 135 for (auto& metadata : tracking_configuration_) {
132 it = tracking_configuration_.begin(); 136 if (metadata->enforcement_level > EnforcementLevel::NO_ENFORCEMENT) {
133 it != tracking_configuration_.end(); 137 protected_pref_names.insert(metadata->name);
134 ++it) { 138 protected_configuration.push_back(std::move(metadata));
135 if (it->enforcement_level >
136 PrefHashFilter::EnforcementLevel::NO_ENFORCEMENT) {
137 protected_configuration.push_back(*it);
138 protected_pref_names.insert(it->name);
139 } else { 139 } else {
140 unprotected_configuration.push_back(*it); 140 unprotected_pref_names.insert(metadata->name);
141 unprotected_pref_names.insert(it->name); 141 unprotected_configuration.push_back(std::move(metadata));
142 } 142 }
143 } 143 }
144 tracking_configuration_.clear();
144 145
145 std::unique_ptr<PrefHashFilter> unprotected_pref_hash_filter( 146 std::unique_ptr<PrefHashFilter> unprotected_pref_hash_filter(
146 new PrefHashFilter(GetPrefHashStore(false), 147 new PrefHashFilter(GetPrefHashStore(false),
147 GetExternalVerificationPrefHashStorePair(), 148 GetExternalVerificationPrefHashStorePair(),
148 unprotected_configuration, base::Closure(), 149 unprotected_configuration, base::Closure(),
149 validation_delegate, reporting_ids_count_, false)); 150 validation_delegate, reporting_ids_count_, false));
150 std::unique_ptr<PrefHashFilter> protected_pref_hash_filter(new PrefHashFilter( 151 std::unique_ptr<PrefHashFilter> protected_pref_hash_filter(new PrefHashFilter(
151 GetPrefHashStore(true), GetExternalVerificationPrefHashStorePair(), 152 GetPrefHashStore(true), GetExternalVerificationPrefHashStorePair(),
152 protected_configuration, on_reset_on_load, validation_delegate, 153 protected_configuration, on_reset_on_load, validation_delegate,
153 reporting_ids_count_, true)); 154 reporting_ids_count_, true));
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
242 const base::Closure& on_reset_on_load, 243 const base::Closure& on_reset_on_load,
243 service_manager::Connector* connector) { 244 service_manager::Connector* connector) {
244 auto config = prefs::mojom::PersistentPrefStoreConfiguration::New(); 245 auto config = prefs::mojom::PersistentPrefStoreConfiguration::New();
245 config->set_simple_configuration( 246 config->set_simple_configuration(
246 prefs::mojom::SimplePersistentPrefStoreConfiguration::New( 247 prefs::mojom::SimplePersistentPrefStoreConfiguration::New(
247 profile_path_.Append(chrome::kPreferencesFilename))); 248 profile_path_.Append(chrome::kPreferencesFilename)));
248 prefs::mojom::PrefServiceControlPtr control; 249 prefs::mojom::PrefServiceControlPtr control;
249 connector->BindInterface(prefs::mojom::kServiceName, &control); 250 connector->BindInterface(prefs::mojom::kServiceName, &control);
250 control->Init(std::move(config)); 251 control->Init(std::move(config));
251 } 252 }
OLDNEW
« no previous file with comments | « chrome/browser/prefs/profile_pref_store_manager.h ('k') | chrome/browser/prefs/profile_pref_store_manager_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698