| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/test/base/testing_profile.h" | 5 #include "chrome/test/base/testing_profile.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/base_paths.h" | 9 #include "base/base_paths.h" |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| (...skipping 449 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 460 syncer::SUPERVISED_USER_SETTINGS, syncer::SyncDataList(), | 460 syncer::SUPERVISED_USER_SETTINGS, syncer::SyncDataList(), |
| 461 std::unique_ptr<syncer::SyncChangeProcessor>( | 461 std::unique_ptr<syncer::SyncChangeProcessor>( |
| 462 new syncer::FakeSyncChangeProcessor), | 462 new syncer::FakeSyncChangeProcessor), |
| 463 std::unique_ptr<syncer::SyncErrorFactory>( | 463 std::unique_ptr<syncer::SyncErrorFactory>( |
| 464 new syncer::SyncErrorFactoryMock)); | 464 new syncer::SyncErrorFactoryMock)); |
| 465 | 465 |
| 466 store->SetInitializationCompleted(); | 466 store->SetInitializationCompleted(); |
| 467 } | 467 } |
| 468 #endif | 468 #endif |
| 469 | 469 |
| 470 if (prefs_.get()) | 470 if (prefs_.get()) { |
| 471 user_prefs::UserPrefs::Set(this, prefs_.get()); | 471 user_prefs::UserPrefs::Set(this, prefs_.get()); |
| 472 else if (IsOffTheRecord()) | 472 } else if (IsOffTheRecord()) { |
| 473 CreateIncognitoPrefService(); | 473 CreateIncognitoPrefService(); |
| 474 else if (!supervised_user_id_.empty()) | 474 } else if (!supervised_user_id_.empty()) { |
| 475 #if BUILDFLAG(ENABLE_SUPERVISED_USERS) |
| 475 CreatePrefServiceForSupervisedUser(); | 476 CreatePrefServiceForSupervisedUser(); |
| 476 else | 477 #endif |
| 478 } else { |
| 477 CreateTestingPrefService(); | 479 CreateTestingPrefService(); |
| 480 } |
| 478 | 481 |
| 479 if (!base::PathExists(profile_path_)) | 482 if (!base::PathExists(profile_path_)) |
| 480 base::CreateDirectory(profile_path_); | 483 base::CreateDirectory(profile_path_); |
| 481 | 484 |
| 482 // TODO(joaodasilva): remove this once this PKS isn't created in ProfileImpl | 485 // TODO(joaodasilva): remove this once this PKS isn't created in ProfileImpl |
| 483 // anymore, after converting the PrefService to a PKS. Until then it must | 486 // anymore, after converting the PrefService to a PKS. Until then it must |
| 484 // be associated with a TestingProfile too. | 487 // be associated with a TestingProfile too. |
| 485 if (!IsOffTheRecord()) | 488 if (!IsOffTheRecord()) |
| 486 CreateProfilePolicyConnector(); | 489 CreateProfilePolicyConnector(); |
| 487 | 490 |
| (...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 796 } | 799 } |
| 797 | 800 |
| 798 void TestingProfile::CreateTestingPrefService() { | 801 void TestingProfile::CreateTestingPrefService() { |
| 799 DCHECK(!prefs_.get()); | 802 DCHECK(!prefs_.get()); |
| 800 testing_prefs_ = new sync_preferences::TestingPrefServiceSyncable(); | 803 testing_prefs_ = new sync_preferences::TestingPrefServiceSyncable(); |
| 801 prefs_.reset(testing_prefs_); | 804 prefs_.reset(testing_prefs_); |
| 802 user_prefs::UserPrefs::Set(this, prefs_.get()); | 805 user_prefs::UserPrefs::Set(this, prefs_.get()); |
| 803 chrome::RegisterUserProfilePrefs(testing_prefs_->registry()); | 806 chrome::RegisterUserProfilePrefs(testing_prefs_->registry()); |
| 804 } | 807 } |
| 805 | 808 |
| 809 #if BUILDFLAG(ENABLE_SUPERVISED_USERS) |
| 806 void TestingProfile::CreatePrefServiceForSupervisedUser() { | 810 void TestingProfile::CreatePrefServiceForSupervisedUser() { |
| 807 DCHECK(!prefs_.get()); | 811 DCHECK(!prefs_.get()); |
| 808 DCHECK(!supervised_user_id_.empty()); | 812 DCHECK(!supervised_user_id_.empty()); |
| 809 sync_preferences::PrefServiceMockFactory factory; | 813 sync_preferences::PrefServiceMockFactory factory; |
| 810 SupervisedUserSettingsService* supervised_user_settings = | 814 SupervisedUserSettingsService* supervised_user_settings = |
| 811 SupervisedUserSettingsServiceFactory::GetForProfile(this); | 815 SupervisedUserSettingsServiceFactory::GetForProfile(this); |
| 812 scoped_refptr<PrefStore> supervised_user_prefs = | 816 scoped_refptr<PrefStore> supervised_user_prefs = |
| 813 make_scoped_refptr(new SupervisedUserPrefStore(supervised_user_settings)); | 817 make_scoped_refptr(new SupervisedUserPrefStore(supervised_user_settings)); |
| 814 | 818 |
| 815 factory.set_supervised_user_prefs(supervised_user_prefs); | 819 factory.set_supervised_user_prefs(supervised_user_prefs); |
| 816 | 820 |
| 817 scoped_refptr<user_prefs::PrefRegistrySyncable> registry( | 821 scoped_refptr<user_prefs::PrefRegistrySyncable> registry( |
| 818 new user_prefs::PrefRegistrySyncable); | 822 new user_prefs::PrefRegistrySyncable); |
| 819 | 823 |
| 820 prefs_ = factory.CreateSyncable(registry.get()); | 824 prefs_ = factory.CreateSyncable(registry.get()); |
| 821 chrome::RegisterUserProfilePrefs(registry.get()); | 825 chrome::RegisterUserProfilePrefs(registry.get()); |
| 822 user_prefs::UserPrefs::Set(this, prefs_.get()); | 826 user_prefs::UserPrefs::Set(this, prefs_.get()); |
| 823 } | 827 } |
| 828 #endif |
| 824 | 829 |
| 825 void TestingProfile::CreateIncognitoPrefService() { | 830 void TestingProfile::CreateIncognitoPrefService() { |
| 826 DCHECK(original_profile_); | 831 DCHECK(original_profile_); |
| 827 DCHECK(!testing_prefs_); | 832 DCHECK(!testing_prefs_); |
| 828 // Simplified version of ProfileImpl::GetOffTheRecordPrefs(). Note this | 833 // Simplified version of ProfileImpl::GetOffTheRecordPrefs(). Note this |
| 829 // leaves testing_prefs_ unset. | 834 // leaves testing_prefs_ unset. |
| 830 prefs_.reset(CreateIncognitoPrefServiceSyncable( | 835 prefs_.reset(CreateIncognitoPrefServiceSyncable( |
| 831 original_profile_->prefs_.get(), NULL)); | 836 original_profile_->prefs_.get(), NULL)); |
| 832 user_prefs::UserPrefs::Set(this, prefs_.get()); | 837 user_prefs::UserPrefs::Set(this, prefs_.get()); |
| 833 } | 838 } |
| (...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1124 // Note: Owned by |original_profile|. | 1129 // Note: Owned by |original_profile|. |
| 1125 return new TestingProfile(path_, delegate_, | 1130 return new TestingProfile(path_, delegate_, |
| 1126 #if BUILDFLAG(ENABLE_EXTENSIONS) | 1131 #if BUILDFLAG(ENABLE_EXTENSIONS) |
| 1127 extension_policy_, | 1132 extension_policy_, |
| 1128 #endif | 1133 #endif |
| 1129 std::move(pref_service_), original_profile, | 1134 std::move(pref_service_), original_profile, |
| 1130 guest_session_, supervised_user_id_, | 1135 guest_session_, supervised_user_id_, |
| 1131 std::move(policy_service_), testing_factories_, | 1136 std::move(policy_service_), testing_factories_, |
| 1132 profile_name_); | 1137 profile_name_); |
| 1133 } | 1138 } |
| OLD | NEW |