Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 116 &pref_connector); | 120 &pref_connector); |
| 117 return new prefs::PersistentPrefStoreClient(std::move(pref_connector), | 121 return new prefs::PersistentPrefStoreClient(std::move(pref_connector), |
| 118 std::move(pref_registry)); | 122 std::move(pref_registry)); |
| 119 } | 123 } |
| 120 if (!kPlatformSupportsPreferenceTracking) { | 124 if (!kPlatformSupportsPreferenceTracking) { |
| 121 return new JsonPrefStore(profile_path_.Append(chrome::kPreferencesFilename), | 125 return new JsonPrefStore(profile_path_.Append(chrome::kPreferencesFilename), |
| 122 io_task_runner.get(), | 126 io_task_runner.get(), |
| 123 std::unique_ptr<PrefFilter>()); | 127 std::unique_ptr<PrefFilter>()); |
| 124 } | 128 } |
| 125 | 129 |
| 126 std::vector<PrefHashFilter::TrackedPreferenceMetadata> | 130 std::vector<prefs::mojom::TrackedPreferenceMetadataPtr> |
| 127 unprotected_configuration; | 131 unprotected_configuration; |
| 128 std::vector<PrefHashFilter::TrackedPreferenceMetadata> | 132 std::vector<prefs::mojom::TrackedPreferenceMetadataPtr> |
| 129 protected_configuration; | 133 protected_configuration; |
| 130 std::set<std::string> protected_pref_names; | 134 std::set<std::string> protected_pref_names; |
| 131 std::set<std::string> unprotected_pref_names; | 135 std::set<std::string> unprotected_pref_names; |
| 132 for (std::vector<PrefHashFilter::TrackedPreferenceMetadata>::const_iterator | 136 for (auto& metadata : tracking_configuration_) { |
|
gab
2017/03/29 16:27:56
const& (unless we can std::move(metadata) below)
Sam McNally
2017/03/30 02:23:22
Switched to std::move below instead.
| |
| 133 it = tracking_configuration_.begin(); | 137 if (metadata->enforcement_level > EnforcementLevel::NO_ENFORCEMENT) { |
| 134 it != tracking_configuration_.end(); | 138 protected_pref_names.insert(metadata->name); |
| 135 ++it) { | 139 protected_configuration.push_back(metadata.Clone()); |
|
gab
2017/03/29 16:27:56
Can we std::move(metadata) instead of cloning? (wi
Sam McNally
2017/03/30 02:23:22
Done.
| |
| 136 if (it->enforcement_level > | |
| 137 PrefHashFilter::EnforcementLevel::NO_ENFORCEMENT) { | |
| 138 protected_configuration.push_back(*it); | |
| 139 protected_pref_names.insert(it->name); | |
| 140 } else { | 140 } else { |
| 141 unprotected_configuration.push_back(*it); | 141 unprotected_pref_names.insert(metadata->name); |
| 142 unprotected_pref_names.insert(it->name); | 142 unprotected_configuration.push_back(metadata.Clone()); |
| 143 } | 143 } |
| 144 } | 144 } |
| 145 | 145 |
| 146 std::unique_ptr<PrefHashFilter> unprotected_pref_hash_filter( | 146 std::unique_ptr<PrefHashFilter> unprotected_pref_hash_filter( |
| 147 new PrefHashFilter(GetPrefHashStore(false), | 147 new PrefHashFilter(GetPrefHashStore(false), |
| 148 GetExternalVerificationPrefHashStorePair(), | 148 GetExternalVerificationPrefHashStorePair(), |
| 149 unprotected_configuration, base::Closure(), | 149 unprotected_configuration, base::Closure(), |
| 150 validation_delegate, reporting_ids_count_, false)); | 150 validation_delegate, reporting_ids_count_, false)); |
| 151 std::unique_ptr<PrefHashFilter> protected_pref_hash_filter(new PrefHashFilter( | 151 std::unique_ptr<PrefHashFilter> protected_pref_hash_filter(new PrefHashFilter( |
| 152 GetPrefHashStore(true), GetExternalVerificationPrefHashStorePair(), | 152 GetPrefHashStore(true), GetExternalVerificationPrefHashStorePair(), |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 243 const base::Closure& on_reset_on_load, | 243 const base::Closure& on_reset_on_load, |
| 244 service_manager::Connector* connector) { | 244 service_manager::Connector* connector) { |
| 245 auto config = prefs::mojom::PersistentPrefStoreConfiguration::New(); | 245 auto config = prefs::mojom::PersistentPrefStoreConfiguration::New(); |
| 246 config->set_simple_configuration( | 246 config->set_simple_configuration( |
| 247 prefs::mojom::SimplePersistentPrefStoreConfiguration::New( | 247 prefs::mojom::SimplePersistentPrefStoreConfiguration::New( |
| 248 profile_path_.Append(chrome::kPreferencesFilename))); | 248 profile_path_.Append(chrome::kPreferencesFilename))); |
| 249 prefs::mojom::PrefServiceControlPtr control; | 249 prefs::mojom::PrefServiceControlPtr control; |
| 250 connector->BindInterface(prefs::mojom::kPrefStoreServiceName, &control); | 250 connector->BindInterface(prefs::mojom::kPrefStoreServiceName, &control); |
| 251 control->Init(std::move(config)); | 251 control->Init(std::move(config)); |
| 252 } | 252 } |
| OLD | NEW |