| 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 "components/pref_registry/pref_registry_syncable.h" | 20 #include "components/pref_registry/pref_registry_syncable.h" |
| 20 #include "components/prefs/json_pref_store.h" | 21 #include "components/prefs/json_pref_store.h" |
| 21 #include "components/prefs/persistent_pref_store.h" | 22 #include "components/prefs/persistent_pref_store.h" |
| 22 #include "components/prefs/pref_registry_simple.h" | 23 #include "components/prefs/pref_registry_simple.h" |
| 23 #include "components/user_prefs/tracked/pref_hash_store_impl.h" | 24 #include "components/user_prefs/tracked/pref_hash_store_impl.h" |
| 24 #include "components/user_prefs/tracked/segregated_pref_store.h" | 25 #include "components/user_prefs/tracked/segregated_pref_store.h" |
| 25 #include "components/user_prefs/tracked/tracked_preferences_migration.h" | 26 #include "components/user_prefs/tracked/tracked_preferences_migration.h" |
| 27 #include "services/preferences/public/cpp/persistent_pref_store_mojo.h" |
| 28 #include "services/preferences/public/cpp/user_prefs_impl.h" |
| 26 | 29 |
| 27 #if defined(OS_WIN) | 30 #if defined(OS_WIN) |
| 28 #include "chrome/installer/util/browser_distribution.h" | 31 #include "chrome/installer/util/browser_distribution.h" |
| 29 #include "components/user_prefs/tracked/registry_hash_store_contents_win.h" | 32 #include "components/user_prefs/tracked/registry_hash_store_contents_win.h" |
| 30 #endif | 33 #endif |
| 31 | 34 |
| 32 namespace { | 35 namespace { |
| 33 | 36 |
| 34 void RemoveValueSilently(const base::WeakPtr<JsonPrefStore> pref_store, | 37 void RemoveValueSilently(const base::WeakPtr<JsonPrefStore> pref_store, |
| 35 const std::string& key) { | 38 const std::string& key) { |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 93 #if defined(OS_WIN) | 96 #if defined(OS_WIN) |
| 94 // static | 97 // static |
| 95 void ProfilePrefStoreManager::SetPreferenceValidationRegistryPathForTesting( | 98 void ProfilePrefStoreManager::SetPreferenceValidationRegistryPathForTesting( |
| 96 const base::string16* path) { | 99 const base::string16* path) { |
| 97 DCHECK(!path->empty()); | 100 DCHECK(!path->empty()); |
| 98 g_preference_validation_registry_path_for_testing = path; | 101 g_preference_validation_registry_path_for_testing = path; |
| 99 } | 102 } |
| 100 #endif // OS_WIN | 103 #endif // OS_WIN |
| 101 | 104 |
| 102 PersistentPrefStore* ProfilePrefStoreManager::CreateProfilePrefStore( | 105 PersistentPrefStore* ProfilePrefStoreManager::CreateProfilePrefStore( |
| 106 const scoped_refptr<base::SingleThreadTaskRunner>& pref_task_runner, |
| 103 const scoped_refptr<base::SequencedTaskRunner>& io_task_runner, | 107 const scoped_refptr<base::SequencedTaskRunner>& io_task_runner, |
| 104 const base::Closure& on_reset_on_load, | 108 const base::Closure& on_reset_on_load, |
| 105 TrackedPreferenceValidationDelegate* validation_delegate) { | 109 base::WeakPtr<TrackedPreferenceValidationDelegate> validation_delegate) { |
| 106 std::unique_ptr<PrefFilter> pref_filter; | 110 prefs::mojom::PersistentPrefStoreConnectorPtr connector; |
| 111 if (base::FeatureList::IsEnabled(features::kPrefService)) { |
| 112 if (!kPlatformSupportsPreferenceTracking) { |
| 113 prefs::CreateUserPrefs(profile_path_.Append(chrome::kPreferencesFilename), |
| 114 pref_task_runner, io_task_runner, |
| 115 mojo::MakeRequest(&connector)); |
| 116 } else { |
| 117 prefs::CreateSegregatedUserPrefs( |
| 118 profile_path_.Append(chrome::kPreferencesFilename), |
| 119 profile_path_.Append(chrome::kSecurePreferencesFilename), |
| 120 tracking_configuration_, reporting_ids_count_, seed_, |
| 121 legacy_device_id_, |
| 122 #if defined(OS_WIN) |
| 123 g_preference_validation_registry_path_for_testing |
| 124 ? *g_preference_validation_registry_path_for_testing |
| 125 : BrowserDistribution::GetDistribution()->GetRegistryPath(), |
| 126 #else |
| 127 base::string16(), |
| 128 #endif |
| 129 validation_delegate, on_reset_on_load, pref_task_runner, |
| 130 io_task_runner, mojo::MakeRequest(&connector)); |
| 131 } |
| 132 return new prefs::PersistentPrefStoreMojo(std::move(connector)); |
| 133 } |
| 107 if (!kPlatformSupportsPreferenceTracking) { | 134 if (!kPlatformSupportsPreferenceTracking) { |
| 108 return new JsonPrefStore(profile_path_.Append(chrome::kPreferencesFilename), | 135 return new JsonPrefStore(profile_path_.Append(chrome::kPreferencesFilename), |
| 109 io_task_runner.get(), | 136 io_task_runner.get(), |
| 110 std::unique_ptr<PrefFilter>()); | 137 std::unique_ptr<PrefFilter>()); |
| 111 } | 138 } |
| 112 | 139 |
| 113 std::vector<PrefHashFilter::TrackedPreferenceMetadata> | 140 std::vector<PrefHashFilter::TrackedPreferenceMetadata> |
| 114 unprotected_configuration; | 141 unprotected_configuration; |
| 115 std::vector<PrefHashFilter::TrackedPreferenceMetadata> | 142 std::vector<PrefHashFilter::TrackedPreferenceMetadata> |
| 116 protected_configuration; | 143 protected_configuration; |
| 117 std::set<std::string> protected_pref_names; | 144 std::set<std::string> protected_pref_names; |
| 118 std::set<std::string> unprotected_pref_names; | 145 std::set<std::string> unprotected_pref_names; |
| 119 for (std::vector<PrefHashFilter::TrackedPreferenceMetadata>::const_iterator | 146 for (std::vector<PrefHashFilter::TrackedPreferenceMetadata>::const_iterator |
| 120 it = tracking_configuration_.begin(); | 147 it = tracking_configuration_.begin(); |
| 121 it != tracking_configuration_.end(); | 148 it != tracking_configuration_.end(); |
| 122 ++it) { | 149 ++it) { |
| 123 if (it->enforcement_level > PrefHashFilter::NO_ENFORCEMENT) { | 150 if (it->enforcement_level > PrefHashFilter::NO_ENFORCEMENT) { |
| 124 protected_configuration.push_back(*it); | 151 protected_configuration.push_back(*it); |
| 125 protected_pref_names.insert(it->name); | 152 protected_pref_names.insert(it->name); |
| 126 } else { | 153 } else { |
| 127 unprotected_configuration.push_back(*it); | 154 unprotected_configuration.push_back(*it); |
| 128 unprotected_pref_names.insert(it->name); | 155 unprotected_pref_names.insert(it->name); |
| 129 } | 156 } |
| 130 } | 157 } |
| 131 | 158 |
| 132 std::unique_ptr<PrefHashFilter> unprotected_pref_hash_filter( | 159 std::unique_ptr<PrefHashFilter> unprotected_pref_hash_filter( |
| 133 new PrefHashFilter(GetPrefHashStore(false), | 160 new PrefHashFilter( |
| 134 GetExternalVerificationPrefHashStorePair(), | 161 GetPrefHashStore(false), GetExternalVerificationPrefHashStorePair(), |
| 135 unprotected_configuration, base::Closure(), | 162 unprotected_configuration, base::Closure(), validation_delegate.get(), |
| 136 validation_delegate, reporting_ids_count_, false)); | 163 reporting_ids_count_, false)); |
| 137 std::unique_ptr<PrefHashFilter> protected_pref_hash_filter(new PrefHashFilter( | 164 std::unique_ptr<PrefHashFilter> protected_pref_hash_filter(new PrefHashFilter( |
| 138 GetPrefHashStore(true), GetExternalVerificationPrefHashStorePair(), | 165 GetPrefHashStore(true), GetExternalVerificationPrefHashStorePair(), |
| 139 protected_configuration, on_reset_on_load, validation_delegate, | 166 protected_configuration, on_reset_on_load, validation_delegate.get(), |
| 140 reporting_ids_count_, true)); | 167 reporting_ids_count_, true)); |
| 141 | 168 |
| 142 PrefHashFilter* raw_unprotected_pref_hash_filter = | 169 PrefHashFilter* raw_unprotected_pref_hash_filter = |
| 143 unprotected_pref_hash_filter.get(); | 170 unprotected_pref_hash_filter.get(); |
| 144 PrefHashFilter* raw_protected_pref_hash_filter = | 171 PrefHashFilter* raw_protected_pref_hash_filter = |
| 145 protected_pref_hash_filter.get(); | 172 protected_pref_hash_filter.get(); |
| 146 | 173 |
| 147 scoped_refptr<JsonPrefStore> unprotected_pref_store(new JsonPrefStore( | 174 scoped_refptr<JsonPrefStore> unprotected_pref_store(new JsonPrefStore( |
| 148 profile_path_.Append(chrome::kPreferencesFilename), io_task_runner.get(), | 175 profile_path_.Append(chrome::kPreferencesFilename), io_task_runner.get(), |
| 149 std::move(unprotected_pref_hash_filter))); | 176 std::move(unprotected_pref_hash_filter))); |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 225 ? base::MakeUnique<RegistryHashStoreContentsWin>( | 252 ? base::MakeUnique<RegistryHashStoreContentsWin>( |
| 226 *g_preference_validation_registry_path_for_testing, | 253 *g_preference_validation_registry_path_for_testing, |
| 227 profile_path_.BaseName().LossyDisplayName()) | 254 profile_path_.BaseName().LossyDisplayName()) |
| 228 : base::MakeUnique<RegistryHashStoreContentsWin>( | 255 : base::MakeUnique<RegistryHashStoreContentsWin>( |
| 229 BrowserDistribution::GetDistribution()->GetRegistryPath(), | 256 BrowserDistribution::GetDistribution()->GetRegistryPath(), |
| 230 profile_path_.BaseName().LossyDisplayName())); | 257 profile_path_.BaseName().LossyDisplayName())); |
| 231 #else | 258 #else |
| 232 return std::make_pair(nullptr, nullptr); | 259 return std::make_pair(nullptr, nullptr); |
| 233 #endif | 260 #endif |
| 234 } | 261 } |
| OLD | NEW |