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

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

Issue 2767743003: Pref service: Merge connectors and send a PrefRegistry in Connect(). (Closed)
Patch Set: Created 3 years, 9 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 <stddef.h> 7 #include <stddef.h>
8 8
9 #include <memory> 9 #include <memory>
10 #include <utility> 10 #include <utility>
(...skipping 18 matching lines...) Expand all
29 #include "components/prefs/json_pref_store.h" 29 #include "components/prefs/json_pref_store.h"
30 #include "components/prefs/persistent_pref_store.h" 30 #include "components/prefs/persistent_pref_store.h"
31 #include "components/prefs/pref_service.h" 31 #include "components/prefs/pref_service.h"
32 #include "components/prefs/pref_service_factory.h" 32 #include "components/prefs/pref_service_factory.h"
33 #include "components/prefs/pref_store.h" 33 #include "components/prefs/pref_store.h"
34 #include "components/prefs/testing_pref_service.h" 34 #include "components/prefs/testing_pref_service.h"
35 #include "components/user_prefs/tracked/mock_validation_delegate.h" 35 #include "components/user_prefs/tracked/mock_validation_delegate.h"
36 #include "components/user_prefs/tracked/pref_hash_filter.h" 36 #include "components/user_prefs/tracked/pref_hash_filter.h"
37 #include "components/user_prefs/tracked/pref_names.h" 37 #include "components/user_prefs/tracked/pref_names.h"
38 #include "content/public/common/service_names.mojom.h" 38 #include "content/public/common/service_names.mojom.h"
39 #include "services/preferences/public/cpp/persistent_pref_store_client.h"
39 #include "services/preferences/public/cpp/pref_service_main.h" 40 #include "services/preferences/public/cpp/pref_service_main.h"
41 #include "services/preferences/public/interfaces/preferences.mojom.h"
40 #include "services/service_manager/public/cpp/connector.h" 42 #include "services/service_manager/public/cpp/connector.h"
41 #include "services/service_manager/public/cpp/service_context.h" 43 #include "services/service_manager/public/cpp/service_context.h"
42 #include "testing/gtest/include/gtest/gtest.h" 44 #include "testing/gtest/include/gtest/gtest.h"
43 45
44 namespace { 46 namespace {
45 47
46 class FirstEqualsPredicate { 48 class FirstEqualsPredicate {
47 public: 49 public:
48 explicit FirstEqualsPredicate(const std::string& expected) 50 explicit FirstEqualsPredicate(const std::string& expected)
49 : expected_(expected) {} 51 : expected_(expected) {}
(...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after
299 // According to the implementation of ProfilePrefStoreManager, this is 301 // According to the implementation of ProfilePrefStoreManager, this is
300 // actually a SegregatedPrefStore backed by two underlying pref stores. 302 // actually a SegregatedPrefStore backed by two underlying pref stores.
301 mock_validation_delegate_ = base::MakeUnique<MockValidationDelegate>( 303 mock_validation_delegate_ = base::MakeUnique<MockValidationDelegate>(
302 mock_validation_delegate_record_); 304 mock_validation_delegate_record_);
303 scoped_refptr<PersistentPrefStore> pref_store = 305 scoped_refptr<PersistentPrefStore> pref_store =
304 manager_->CreateProfilePrefStore( 306 manager_->CreateProfilePrefStore(
305 main_message_loop_.task_runner(), 307 main_message_loop_.task_runner(),
306 base::Bind(&ProfilePrefStoreManagerTest::RecordReset, 308 base::Bind(&ProfilePrefStoreManagerTest::RecordReset,
307 base::Unretained(this)), 309 base::Unretained(this)),
308 mock_validation_delegate_.get(), connector_.get()); 310 mock_validation_delegate_.get(), connector_.get());
311 if (!pref_store) {
312 prefs::mojom::PrefStoreConnectorPtr pref_connector;
313 connector_->BindInterface(prefs::mojom::kPrefStoreServiceName,
314 &pref_connector);
315 pref_store = new prefs::PersistentPrefStoreClient(
316 std::move(pref_connector), profile_pref_registry_);
317 }
309 InitializePrefStore(pref_store.get()); 318 InitializePrefStore(pref_store.get());
310 pref_store = NULL; 319 pref_store = NULL;
311 base::RunLoop().RunUntilIdle(); 320 base::RunLoop().RunUntilIdle();
312 } 321 }
313 322
314 void DestroyPrefStore() { 323 void DestroyPrefStore() {
315 if (pref_store_.get()) { 324 if (pref_store_.get()) {
316 ClearResetRecorded(); 325 ClearResetRecorded();
317 // Force everything to be written to disk, triggering the PrefHashFilter 326 // Force everything to be written to disk, triggering the PrefHashFilter
318 // while our RegistryVerifier is watching. 327 // while our RegistryVerifier is watching.
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
361 void LoadExistingPrefs() { 370 void LoadExistingPrefs() {
362 DestroyPrefStore(); 371 DestroyPrefStore();
363 mock_validation_delegate_ = base::MakeUnique<MockValidationDelegate>( 372 mock_validation_delegate_ = base::MakeUnique<MockValidationDelegate>(
364 mock_validation_delegate_record_); 373 mock_validation_delegate_record_);
365 pref_store_ = manager_->CreateProfilePrefStore( 374 pref_store_ = manager_->CreateProfilePrefStore(
366 JsonPrefStore::GetTaskRunnerForFile(profile_dir_.GetPath(), 375 JsonPrefStore::GetTaskRunnerForFile(profile_dir_.GetPath(),
367 worker_pool_->pool().get()), 376 worker_pool_->pool().get()),
368 base::Bind(&ProfilePrefStoreManagerTest::RecordReset, 377 base::Bind(&ProfilePrefStoreManagerTest::RecordReset,
369 base::Unretained(this)), 378 base::Unretained(this)),
370 mock_validation_delegate_.get(), connector_.get()); 379 mock_validation_delegate_.get(), connector_.get());
380 if (!pref_store_) {
381 prefs::mojom::PrefStoreConnectorPtr pref_connector;
382 connector_->BindInterface(prefs::mojom::kPrefStoreServiceName,
383 &pref_connector);
384 pref_store_ = new prefs::PersistentPrefStoreClient(
385 std::move(pref_connector), profile_pref_registry_);
386 }
371 pref_store_->AddObserver(&registry_verifier_); 387 pref_store_->AddObserver(&registry_verifier_);
372 PrefStoreReadObserver read_observer(pref_store_); 388 PrefStoreReadObserver read_observer(pref_store_);
373 read_observer.Read(); 389 read_observer.Read();
374 } 390 }
375 391
376 void ReplaceStringInPrefs(const std::string& find, 392 void ReplaceStringInPrefs(const std::string& find,
377 const std::string& replace) { 393 const std::string& replace) {
378 base::FileEnumerator file_enum(profile_dir_.GetPath(), true, 394 base::FileEnumerator file_enum(profile_dir_.GetPath(), true,
379 base::FileEnumerator::FILES); 395 base::FileEnumerator::FILES);
380 396
(...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after
642 base::WrapUnique(new base::Value(kGoodbyeWorld)), 658 base::WrapUnique(new base::Value(kGoodbyeWorld)),
643 WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS); 659 WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS);
644 LoadExistingPrefs(); 660 LoadExistingPrefs();
645 ExpectStringValueEquals(kProtectedAtomic, kGoodbyeWorld); 661 ExpectStringValueEquals(kProtectedAtomic, kGoodbyeWorld);
646 VerifyResetRecorded(false); 662 VerifyResetRecorded(false);
647 } 663 }
648 664
649 INSTANTIATE_TEST_CASE_P(ProfilePrefStoreManagerTest, 665 INSTANTIATE_TEST_CASE_P(ProfilePrefStoreManagerTest,
650 ProfilePrefStoreManagerTest, 666 ProfilePrefStoreManagerTest,
651 testing::Bool()); 667 testing::Bool());
OLDNEW
« no previous file with comments | « chrome/browser/prefs/profile_pref_store_manager.cc ('k') | components/sync_preferences/pref_service_syncable_factory.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698