| 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" | 24 #include "components/user_prefs/tracked/pref_hash_store_impl.h" |
| 25 #include "components/user_prefs/tracked/segregated_pref_store.h" | 25 #include "components/user_prefs/tracked/segregated_pref_store.h" |
| 26 #include "components/user_prefs/tracked/tracked_preferences_migration.h" | 26 #include "components/user_prefs/tracked/tracked_preferences_migration.h" |
| 27 #include "mojo/public/cpp/bindings/strong_binding.h" | 27 #include "mojo/public/cpp/bindings/strong_binding.h" |
| 28 #include "services/preferences/public/cpp/persistent_pref_store_mojo.h" | |
| 29 #include "services/preferences/public/cpp/user_prefs_impl.h" | 28 #include "services/preferences/public/cpp/user_prefs_impl.h" |
| 30 | 29 |
| 31 #if defined(OS_WIN) | 30 #if defined(OS_WIN) |
| 32 #include "chrome/installer/util/browser_distribution.h" | 31 #include "chrome/installer/util/browser_distribution.h" |
| 33 #include "components/user_prefs/tracked/registry_hash_store_contents_win.h" | 32 #include "components/user_prefs/tracked/registry_hash_store_contents_win.h" |
| 34 #endif | 33 #endif |
| 35 | 34 |
| 36 namespace { | 35 namespace { |
| 37 | 36 |
| 38 void RemoveValueSilently(const base::WeakPtr<JsonPrefStore> pref_store, | 37 void RemoveValueSilently(const base::WeakPtr<JsonPrefStore> pref_store, |
| 39 const std::string& key) { | 38 const std::string& key) { |
| 40 if (pref_store) { | 39 if (pref_store) { |
| 41 pref_store->RemoveValueSilently( | 40 pref_store->RemoveValueSilently( |
| 42 key, WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS); | 41 key, WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS); |
| 43 } | 42 } |
| 44 } | 43 } |
| 45 | 44 |
| 46 #if defined(OS_WIN) | 45 #if defined(OS_WIN) |
| 47 // Forces a different registry key to be used for storing preference validation | 46 // Forces a different registry key to be used for storing preference validation |
| 48 // MACs. See |SetPreferenceValidationRegistryPathForTesting|. | 47 // MACs. See |SetPreferenceValidationRegistryPathForTesting|. |
| 49 const base::string16* g_preference_validation_registry_path_for_testing = | 48 const base::string16* g_preference_validation_registry_path_for_testing = |
| 50 nullptr; | 49 nullptr; |
| 51 #endif // OS_WIN | 50 #endif // OS_WIN |
| 52 | 51 |
| 52 class ResetOnLoadObserverImpl : public prefs::mojom::ResetOnLoadObserver { |
| 53 public: |
| 54 explicit ResetOnLoadObserverImpl(const base::Closure& on_reset_on_load) |
| 55 : on_reset_on_load_(on_reset_on_load) { |
| 56 DCHECK(on_reset_on_load_); |
| 57 } |
| 58 |
| 59 void OnResetOnLoad() override { on_reset_on_load_.Run(); } |
| 60 |
| 61 private: |
| 62 base::Closure on_reset_on_load_; |
| 63 }; |
| 64 |
| 53 } // namespace | 65 } // namespace |
| 54 | 66 |
| 55 // Preference tracking and protection is not required on platforms where other | 67 // Preference tracking and protection is not required on platforms where other |
| 56 // apps do not have access to chrome's persistent storage. | 68 // apps do not have access to chrome's persistent storage. |
| 57 const bool ProfilePrefStoreManager::kPlatformSupportsPreferenceTracking = | 69 const bool ProfilePrefStoreManager::kPlatformSupportsPreferenceTracking = |
| 58 #if defined(OS_ANDROID) || defined(OS_CHROMEOS) | 70 #if defined(OS_ANDROID) || defined(OS_CHROMEOS) |
| 59 false; | 71 false; |
| 60 #else | 72 #else |
| 61 true; | 73 true; |
| 62 #endif | 74 #endif |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 101 DCHECK(!path->empty()); | 113 DCHECK(!path->empty()); |
| 102 g_preference_validation_registry_path_for_testing = path; | 114 g_preference_validation_registry_path_for_testing = path; |
| 103 } | 115 } |
| 104 #endif // OS_WIN | 116 #endif // OS_WIN |
| 105 | 117 |
| 106 PersistentPrefStore* ProfilePrefStoreManager::CreateProfilePrefStore( | 118 PersistentPrefStore* ProfilePrefStoreManager::CreateProfilePrefStore( |
| 107 const scoped_refptr<base::SingleThreadTaskRunner>& pref_task_runner, | 119 const scoped_refptr<base::SingleThreadTaskRunner>& pref_task_runner, |
| 108 const scoped_refptr<base::SequencedTaskRunner>& io_task_runner, | 120 const scoped_refptr<base::SequencedTaskRunner>& io_task_runner, |
| 109 const base::Closure& on_reset_on_load, | 121 const base::Closure& on_reset_on_load, |
| 110 std::unique_ptr<prefs::mojom::TrackedPreferenceValidationDelegate>* | 122 std::unique_ptr<prefs::mojom::TrackedPreferenceValidationDelegate>* |
| 111 validation_delegate) { | 123 validation_delegate, |
| 124 prefs::mojom::PersistentPrefStoreConnectorPtr* connector) { |
| 112 DCHECK(validation_delegate); | 125 DCHECK(validation_delegate); |
| 113 prefs::mojom::PersistentPrefStoreConnectorPtr connector; | |
| 114 if (base::FeatureList::IsEnabled(features::kPrefService)) { | 126 if (base::FeatureList::IsEnabled(features::kPrefService)) { |
| 115 if (!kPlatformSupportsPreferenceTracking) { | 127 if (!kPlatformSupportsPreferenceTracking) { |
| 116 prefs::CreateUserPrefs(profile_path_.Append(chrome::kPreferencesFilename), | 128 prefs::CreateUserPrefs(profile_path_.Append(chrome::kPreferencesFilename), |
| 117 pref_task_runner, io_task_runner, | 129 pref_task_runner, io_task_runner, |
| 118 mojo::MakeRequest(&connector)); | 130 mojo::MakeRequest(connector)); |
| 119 } else { | 131 } else { |
| 120 prefs::mojom::TrackedPreferenceValidationDelegatePtr | 132 prefs::mojom::TrackedPreferenceValidationDelegatePtr |
| 121 validation_delegate_ptr; | 133 validation_delegate_ptr; |
| 122 if (*validation_delegate) { | 134 if (*validation_delegate) { |
| 123 mojo::MakeStrongBinding(std::move(*validation_delegate), | 135 mojo::MakeStrongBinding(std::move(*validation_delegate), |
| 124 mojo::MakeRequest(&validation_delegate_ptr)); | 136 mojo::MakeRequest(&validation_delegate_ptr)); |
| 125 } | 137 } |
| 138 prefs::mojom::ResetOnLoadObserverPtr reset_on_load_observer; |
| 139 if (on_reset_on_load) { |
| 140 mojo::MakeStrongBinding( |
| 141 base::MakeUnique<ResetOnLoadObserverImpl>(on_reset_on_load), |
| 142 mojo::MakeRequest(&reset_on_load_observer)); |
| 143 } |
| 144 |
| 126 prefs::CreateSegregatedUserPrefs( | 145 prefs::CreateSegregatedUserPrefs( |
| 127 profile_path_.Append(chrome::kPreferencesFilename), | 146 profile_path_.Append(chrome::kPreferencesFilename), |
| 128 profile_path_.Append(chrome::kSecurePreferencesFilename), | 147 profile_path_.Append(chrome::kSecurePreferencesFilename), |
| 129 tracking_configuration_, reporting_ids_count_, seed_, | 148 tracking_configuration_, reporting_ids_count_, seed_, |
| 130 legacy_device_id_, | 149 legacy_device_id_, |
| 131 #if defined(OS_WIN) | 150 #if defined(OS_WIN) |
| 132 g_preference_validation_registry_path_for_testing | 151 g_preference_validation_registry_path_for_testing |
| 133 ? *g_preference_validation_registry_path_for_testing | 152 ? *g_preference_validation_registry_path_for_testing |
| 134 : BrowserDistribution::GetDistribution()->GetRegistryPath(), | 153 : BrowserDistribution::GetDistribution()->GetRegistryPath(), |
| 135 #else | 154 #else |
| 136 base::string16(), | 155 base::string16(), |
| 137 #endif | 156 #endif |
| 138 std::move(validation_delegate_ptr), on_reset_on_load, | 157 std::move(validation_delegate_ptr), std::move(reset_on_load_observer), |
| 139 pref_task_runner, io_task_runner, mojo::MakeRequest(&connector)); | 158 pref_task_runner, io_task_runner, mojo::MakeRequest(connector)); |
| 140 } | 159 } |
| 141 return new prefs::PersistentPrefStoreMojo(std::move(connector)); | 160 return nullptr; |
| 142 } | 161 } |
| 143 if (!kPlatformSupportsPreferenceTracking) { | 162 if (!kPlatformSupportsPreferenceTracking) { |
| 144 return new JsonPrefStore(profile_path_.Append(chrome::kPreferencesFilename), | 163 return new JsonPrefStore(profile_path_.Append(chrome::kPreferencesFilename), |
| 145 io_task_runner.get(), | 164 io_task_runner.get(), |
| 146 std::unique_ptr<PrefFilter>()); | 165 std::unique_ptr<PrefFilter>()); |
| 147 } | 166 } |
| 148 | 167 |
| 149 std::vector<PrefHashFilter::TrackedPreferenceMetadata> | 168 std::vector<PrefHashFilter::TrackedPreferenceMetadata> |
| 150 unprotected_configuration; | 169 unprotected_configuration; |
| 151 std::vector<PrefHashFilter::TrackedPreferenceMetadata> | 170 std::vector<PrefHashFilter::TrackedPreferenceMetadata> |
| 152 protected_configuration; | 171 protected_configuration; |
| 153 std::set<std::string> protected_pref_names; | 172 std::set<std::string> protected_pref_names; |
| 154 std::set<std::string> unprotected_pref_names; | 173 std::set<std::string> unprotected_pref_names; |
| 155 for (std::vector<PrefHashFilter::TrackedPreferenceMetadata>::const_iterator | 174 for (std::vector<PrefHashFilter::TrackedPreferenceMetadata>::const_iterator |
| 156 it = tracking_configuration_.begin(); | 175 it = tracking_configuration_.begin(); |
| 157 it != tracking_configuration_.end(); | 176 it != tracking_configuration_.end(); |
| 158 ++it) { | 177 ++it) { |
| 159 if (it->enforcement_level > PrefHashFilter::NO_ENFORCEMENT) { | 178 if (it->enforcement_level > |
| 179 PrefHashFilter::EnforcementLevel::NO_ENFORCEMENT) { |
| 160 protected_configuration.push_back(*it); | 180 protected_configuration.push_back(*it); |
| 161 protected_pref_names.insert(it->name); | 181 protected_pref_names.insert(it->name); |
| 162 } else { | 182 } else { |
| 163 unprotected_configuration.push_back(*it); | 183 unprotected_configuration.push_back(*it); |
| 164 unprotected_pref_names.insert(it->name); | 184 unprotected_pref_names.insert(it->name); |
| 165 } | 185 } |
| 166 } | 186 } |
| 167 | 187 |
| 168 std::unique_ptr<PrefHashFilter> unprotected_pref_hash_filter( | 188 std::unique_ptr<PrefHashFilter> unprotected_pref_hash_filter( |
| 169 new PrefHashFilter( | 189 new PrefHashFilter( |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 256 ? base::MakeUnique<RegistryHashStoreContentsWin>( | 276 ? base::MakeUnique<RegistryHashStoreContentsWin>( |
| 257 *g_preference_validation_registry_path_for_testing, | 277 *g_preference_validation_registry_path_for_testing, |
| 258 profile_path_.BaseName().LossyDisplayName()) | 278 profile_path_.BaseName().LossyDisplayName()) |
| 259 : base::MakeUnique<RegistryHashStoreContentsWin>( | 279 : base::MakeUnique<RegistryHashStoreContentsWin>( |
| 260 BrowserDistribution::GetDistribution()->GetRegistryPath(), | 280 BrowserDistribution::GetDistribution()->GetRegistryPath(), |
| 261 profile_path_.BaseName().LossyDisplayName())); | 281 profile_path_.BaseName().LossyDisplayName())); |
| 262 #else | 282 #else |
| 263 return std::make_pair(nullptr, nullptr); | 283 return std::make_pair(nullptr, nullptr); |
| 264 #endif | 284 #endif |
| 265 } | 285 } |
| OLD | NEW |