 Chromium Code Reviews
 Chromium Code Reviews Issue 2601873002:
  Add a mojo bridge for PersistentPrefStore.  (Closed)
    
  
    Issue 2601873002:
  Add a mojo bridge for PersistentPrefStore.  (Closed) 
  | 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 "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" | |
| 26 | 30 | 
| 27 #if defined(OS_WIN) | 31 #if defined(OS_WIN) | 
| 28 #include "chrome/installer/util/browser_distribution.h" | 32 #include "chrome/installer/util/browser_distribution.h" | 
| 29 #include "components/user_prefs/tracked/registry_hash_store_contents_win.h" | 33 #include "components/user_prefs/tracked/registry_hash_store_contents_win.h" | 
| 30 #endif | 34 #endif | 
| 31 | 35 | 
| 32 namespace { | 36 namespace { | 
| 33 | 37 | 
| 34 void RemoveValueSilently(const base::WeakPtr<JsonPrefStore> pref_store, | 38 void RemoveValueSilently(const base::WeakPtr<JsonPrefStore> pref_store, | 
| 35 const std::string& key) { | 39 const std::string& key) { | 
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 93 #if defined(OS_WIN) | 97 #if defined(OS_WIN) | 
| 94 // static | 98 // static | 
| 95 void ProfilePrefStoreManager::SetPreferenceValidationRegistryPathForTesting( | 99 void ProfilePrefStoreManager::SetPreferenceValidationRegistryPathForTesting( | 
| 96 const base::string16* path) { | 100 const base::string16* path) { | 
| 97 DCHECK(!path->empty()); | 101 DCHECK(!path->empty()); | 
| 98 g_preference_validation_registry_path_for_testing = path; | 102 g_preference_validation_registry_path_for_testing = path; | 
| 99 } | 103 } | 
| 100 #endif // OS_WIN | 104 #endif // OS_WIN | 
| 101 | 105 | 
| 102 PersistentPrefStore* ProfilePrefStoreManager::CreateProfilePrefStore( | 106 PersistentPrefStore* ProfilePrefStoreManager::CreateProfilePrefStore( | 
| 107 const scoped_refptr<base::SingleThreadTaskRunner>& pref_task_runner, | |
| 103 const scoped_refptr<base::SequencedTaskRunner>& io_task_runner, | 108 const scoped_refptr<base::SequencedTaskRunner>& io_task_runner, | 
| 104 const base::Closure& on_reset_on_load, | 109 const base::Closure& on_reset_on_load, | 
| 105 prefs::mojom::TrackedPreferenceValidationDelegate* validation_delegate) { | 110 std::unique_ptr<prefs::mojom::TrackedPreferenceValidationDelegate>* | 
| 106 std::unique_ptr<PrefFilter> pref_filter; | 111 validation_delegate) { | 
| 112 DCHECK(validation_delegate); | |
| 
tibell
2017/03/08 03:39:54
Split this whole block out into a CreateProfilePre
 | |
| 113 prefs::mojom::PersistentPrefStoreConnectorPtr connector; | |
| 114 if (base::FeatureList::IsEnabled(features::kPrefService)) { | |
| 115 if (!kPlatformSupportsPreferenceTracking) { | |
| 116 prefs::CreateUserPrefs(profile_path_.Append(chrome::kPreferencesFilename), | |
| 117 pref_task_runner, io_task_runner, | |
| 118 mojo::MakeRequest(&connector)); | |
| 119 } else { | |
| 120 prefs::mojom::TrackedPreferenceValidationDelegatePtr | |
| 121 validation_delegate_ptr; | |
| 122 if (*validation_delegate) { | |
| 123 mojo::MakeStrongBinding(std::move(*validation_delegate), | |
| 124 mojo::MakeRequest(&validation_delegate_ptr)); | |
| 125 } | |
| 126 prefs::CreateSegregatedUserPrefs( | |
| 127 profile_path_.Append(chrome::kPreferencesFilename), | |
| 128 profile_path_.Append(chrome::kSecurePreferencesFilename), | |
| 129 tracking_configuration_, reporting_ids_count_, seed_, | |
| 130 legacy_device_id_, | |
| 131 #if defined(OS_WIN) | |
| 132 g_preference_validation_registry_path_for_testing | |
| 133 ? *g_preference_validation_registry_path_for_testing | |
| 134 : BrowserDistribution::GetDistribution()->GetRegistryPath(), | |
| 135 #else | |
| 136 base::string16(), | |
| 137 #endif | |
| 138 std::move(validation_delegate_ptr), on_reset_on_load, | |
| 139 pref_task_runner, io_task_runner, mojo::MakeRequest(&connector)); | |
| 140 } | |
| 141 return new prefs::PersistentPrefStoreMojo(std::move(connector)); | |
| 142 } | |
| 107 if (!kPlatformSupportsPreferenceTracking) { | 143 if (!kPlatformSupportsPreferenceTracking) { | 
| 108 return new JsonPrefStore(profile_path_.Append(chrome::kPreferencesFilename), | 144 return new JsonPrefStore(profile_path_.Append(chrome::kPreferencesFilename), | 
| 109 io_task_runner.get(), | 145 io_task_runner.get(), | 
| 110 std::unique_ptr<PrefFilter>()); | 146 std::unique_ptr<PrefFilter>()); | 
| 111 } | 147 } | 
| 112 | 148 | 
| 113 std::vector<PrefHashFilter::TrackedPreferenceMetadata> | 149 std::vector<PrefHashFilter::TrackedPreferenceMetadata> | 
| 114 unprotected_configuration; | 150 unprotected_configuration; | 
| 115 std::vector<PrefHashFilter::TrackedPreferenceMetadata> | 151 std::vector<PrefHashFilter::TrackedPreferenceMetadata> | 
| 116 protected_configuration; | 152 protected_configuration; | 
| 117 std::set<std::string> protected_pref_names; | 153 std::set<std::string> protected_pref_names; | 
| 118 std::set<std::string> unprotected_pref_names; | 154 std::set<std::string> unprotected_pref_names; | 
| 119 for (std::vector<PrefHashFilter::TrackedPreferenceMetadata>::const_iterator | 155 for (std::vector<PrefHashFilter::TrackedPreferenceMetadata>::const_iterator | 
| 120 it = tracking_configuration_.begin(); | 156 it = tracking_configuration_.begin(); | 
| 121 it != tracking_configuration_.end(); | 157 it != tracking_configuration_.end(); | 
| 122 ++it) { | 158 ++it) { | 
| 123 if (it->enforcement_level > PrefHashFilter::NO_ENFORCEMENT) { | 159 if (it->enforcement_level > PrefHashFilter::NO_ENFORCEMENT) { | 
| 124 protected_configuration.push_back(*it); | 160 protected_configuration.push_back(*it); | 
| 125 protected_pref_names.insert(it->name); | 161 protected_pref_names.insert(it->name); | 
| 126 } else { | 162 } else { | 
| 127 unprotected_configuration.push_back(*it); | 163 unprotected_configuration.push_back(*it); | 
| 128 unprotected_pref_names.insert(it->name); | 164 unprotected_pref_names.insert(it->name); | 
| 129 } | 165 } | 
| 130 } | 166 } | 
| 131 | 167 | 
| 132 std::unique_ptr<PrefHashFilter> unprotected_pref_hash_filter( | 168 std::unique_ptr<PrefHashFilter> unprotected_pref_hash_filter( | 
| 133 new PrefHashFilter(GetPrefHashStore(false), | 169 new PrefHashFilter( | 
| 134 GetExternalVerificationPrefHashStorePair(), | 170 GetPrefHashStore(false), GetExternalVerificationPrefHashStorePair(), | 
| 135 unprotected_configuration, base::Closure(), | 171 unprotected_configuration, base::Closure(), | 
| 136 validation_delegate, reporting_ids_count_, false)); | 172 validation_delegate->get(), reporting_ids_count_, false)); | 
| 137 std::unique_ptr<PrefHashFilter> protected_pref_hash_filter(new PrefHashFilter( | 173 std::unique_ptr<PrefHashFilter> protected_pref_hash_filter(new PrefHashFilter( | 
| 138 GetPrefHashStore(true), GetExternalVerificationPrefHashStorePair(), | 174 GetPrefHashStore(true), GetExternalVerificationPrefHashStorePair(), | 
| 139 protected_configuration, on_reset_on_load, validation_delegate, | 175 protected_configuration, on_reset_on_load, validation_delegate->get(), | 
| 140 reporting_ids_count_, true)); | 176 reporting_ids_count_, true)); | 
| 141 | 177 | 
| 142 PrefHashFilter* raw_unprotected_pref_hash_filter = | 178 PrefHashFilter* raw_unprotected_pref_hash_filter = | 
| 143 unprotected_pref_hash_filter.get(); | 179 unprotected_pref_hash_filter.get(); | 
| 144 PrefHashFilter* raw_protected_pref_hash_filter = | 180 PrefHashFilter* raw_protected_pref_hash_filter = | 
| 145 protected_pref_hash_filter.get(); | 181 protected_pref_hash_filter.get(); | 
| 146 | 182 | 
| 147 scoped_refptr<JsonPrefStore> unprotected_pref_store(new JsonPrefStore( | 183 scoped_refptr<JsonPrefStore> unprotected_pref_store(new JsonPrefStore( | 
| 148 profile_path_.Append(chrome::kPreferencesFilename), io_task_runner.get(), | 184 profile_path_.Append(chrome::kPreferencesFilename), io_task_runner.get(), | 
| 149 std::move(unprotected_pref_hash_filter))); | 185 std::move(unprotected_pref_hash_filter))); | 
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 220 ? base::MakeUnique<RegistryHashStoreContentsWin>( | 256 ? base::MakeUnique<RegistryHashStoreContentsWin>( | 
| 221 *g_preference_validation_registry_path_for_testing, | 257 *g_preference_validation_registry_path_for_testing, | 
| 222 profile_path_.BaseName().LossyDisplayName()) | 258 profile_path_.BaseName().LossyDisplayName()) | 
| 223 : base::MakeUnique<RegistryHashStoreContentsWin>( | 259 : base::MakeUnique<RegistryHashStoreContentsWin>( | 
| 224 BrowserDistribution::GetDistribution()->GetRegistryPath(), | 260 BrowserDistribution::GetDistribution()->GetRegistryPath(), | 
| 225 profile_path_.BaseName().LossyDisplayName())); | 261 profile_path_.BaseName().LossyDisplayName())); | 
| 226 #else | 262 #else | 
| 227 return std::make_pair(nullptr, nullptr); | 263 return std::make_pair(nullptr, nullptr); | 
| 228 #endif | 264 #endif | 
| 229 } | 265 } | 
| OLD | NEW |