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

Side by Side Diff: chrome/test/base/testing_profile.cc

Issue 2004043002: Supervised Users Initiated Installs v2 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@kid_initiated_install
Patch Set: Style fix Created 4 years, 7 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 (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 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 #include "components/keyed_service/core/refcounted_keyed_service.h" 68 #include "components/keyed_service/core/refcounted_keyed_service.h"
69 #include "components/omnibox/browser/autocomplete_classifier.h" 69 #include "components/omnibox/browser/autocomplete_classifier.h"
70 #include "components/omnibox/browser/history_index_restore_observer.h" 70 #include "components/omnibox/browser/history_index_restore_observer.h"
71 #include "components/omnibox/browser/in_memory_url_index.h" 71 #include "components/omnibox/browser/in_memory_url_index.h"
72 #include "components/policy/core/common/configuration_policy_provider.h" 72 #include "components/policy/core/common/configuration_policy_provider.h"
73 #include "components/policy/core/common/policy_service.h" 73 #include "components/policy/core/common/policy_service.h"
74 #include "components/policy/core/common/policy_service_impl.h" 74 #include "components/policy/core/common/policy_service_impl.h"
75 #include "components/policy/core/common/schema.h" 75 #include "components/policy/core/common/schema.h"
76 #include "components/prefs/testing_pref_store.h" 76 #include "components/prefs/testing_pref_store.h"
77 #include "components/proxy_config/pref_proxy_config_tracker.h" 77 #include "components/proxy_config/pref_proxy_config_tracker.h"
78 #include "components/syncable_prefs/pref_service_mock_factory.h"
78 #include "components/syncable_prefs/pref_service_syncable.h" 79 #include "components/syncable_prefs/pref_service_syncable.h"
79 #include "components/syncable_prefs/testing_pref_service_syncable.h" 80 #include "components/syncable_prefs/testing_pref_service_syncable.h"
80 #include "components/ui/zoom/zoom_event_manager.h" 81 #include "components/ui/zoom/zoom_event_manager.h"
81 #include "components/user_prefs/user_prefs.h" 82 #include "components/user_prefs/user_prefs.h"
82 #include "components/webdata_services/web_data_service_wrapper.h" 83 #include "components/webdata_services/web_data_service_wrapper.h"
83 #include "content/public/browser/browser_thread.h" 84 #include "content/public/browser/browser_thread.h"
84 #include "content/public/browser/cookie_store_factory.h" 85 #include "content/public/browser/cookie_store_factory.h"
85 #include "content/public/browser/notification_service.h" 86 #include "content/public/browser/notification_service.h"
86 #include "content/public/browser/render_process_host.h" 87 #include "content/public/browser/render_process_host.h"
87 #include "content/public/browser/storage_partition.h" 88 #include "content/public/browser/storage_partition.h"
(...skipping 21 matching lines...) Expand all
109 #include "extensions/browser/extension_prefs_observer.h" 110 #include "extensions/browser/extension_prefs_observer.h"
110 #include "extensions/browser/extension_system.h" 111 #include "extensions/browser/extension_system.h"
111 #endif 112 #endif
112 113
113 #if defined(OS_ANDROID) 114 #if defined(OS_ANDROID)
114 #include "chrome/browser/signin/oauth2_token_service_delegate_android.h" 115 #include "chrome/browser/signin/oauth2_token_service_delegate_android.h"
115 #endif 116 #endif
116 117
117 #if defined(ENABLE_SUPERVISED_USERS) 118 #if defined(ENABLE_SUPERVISED_USERS)
118 #include "chrome/browser/supervised_user/supervised_user_constants.h" 119 #include "chrome/browser/supervised_user/supervised_user_constants.h"
120 #include "chrome/browser/supervised_user/supervised_user_pref_store.h"
119 #include "chrome/browser/supervised_user/supervised_user_settings_service.h" 121 #include "chrome/browser/supervised_user/supervised_user_settings_service.h"
120 #include "chrome/browser/supervised_user/supervised_user_settings_service_factor y.h" 122 #include "chrome/browser/supervised_user/supervised_user_settings_service_factor y.h"
121 #endif 123 #endif
122 124
123 using base::Time; 125 using base::Time;
124 using bookmarks::BookmarkModel; 126 using bookmarks::BookmarkModel;
125 using content::BrowserThread; 127 using content::BrowserThread;
126 using content::DownloadManagerDelegate; 128 using content::DownloadManagerDelegate;
127 using testing::NiceMock; 129 using testing::NiceMock;
128 using testing::Return; 130 using testing::Return;
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after
348 if (profile_path_.empty()) { 350 if (profile_path_.empty()) {
349 CreateTempProfileDir(); 351 CreateTempProfileDir();
350 profile_path_ = temp_dir_.path(); 352 profile_path_ = temp_dir_.path();
351 } 353 }
352 354
353 // Set any testing factories prior to initializing the services. 355 // Set any testing factories prior to initializing the services.
354 for (TestingFactories::const_iterator it = factories.begin(); 356 for (TestingFactories::const_iterator it = factories.begin();
355 it != factories.end(); ++it) { 357 it != factories.end(); ++it) {
356 it->first->SetTestingFactory(this, it->second); 358 it->first->SetTestingFactory(this, it->second);
357 } 359 }
358 360 // Set supervised_user_id_ here, because Init() checks it.
361 supervised_user_id_ = supervised_user_id;
Marc Treib 2016/05/23 15:32:43 Set this in the initializer list above?
mamir 2016/05/23 19:35:14 Done.
359 Init(); 362 Init();
360 // If caller supplied a delegate, delay the FinishInit invocation until other 363 // If caller supplied a delegate, delay the FinishInit invocation until other
361 // tasks have run. 364 // tasks have run.
362 // TODO(atwilson): See if this is still required once we convert the current 365 // TODO(atwilson): See if this is still required once we convert the current
363 // users of the constructor that takes a Delegate* param. 366 // users of the constructor that takes a Delegate* param.
364 if (delegate_) { 367 if (delegate_) {
365 base::ThreadTaskRunnerHandle::Get()->PostTask( 368 base::ThreadTaskRunnerHandle::Get()->PostTask(
366 FROM_HERE, 369 FROM_HERE,
367 base::Bind(&TestingProfile::FinishInit, base::Unretained(this))); 370 base::Bind(&TestingProfile::FinishInit, base::Unretained(this)));
368 } else { 371 } else {
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
412 #if defined(OS_ANDROID) 415 #if defined(OS_ANDROID)
413 // Make sure token service knows its running in tests. 416 // Make sure token service knows its running in tests.
414 OAuth2TokenServiceDelegateAndroid::set_is_testing_profile(); 417 OAuth2TokenServiceDelegateAndroid::set_is_testing_profile();
415 #endif 418 #endif
416 419
417 // Normally this would happen during browser startup, but for tests 420 // Normally this would happen during browser startup, but for tests
418 // we need to trigger creation of Profile-related services. 421 // we need to trigger creation of Profile-related services.
419 ChromeBrowserMainExtraPartsProfiles:: 422 ChromeBrowserMainExtraPartsProfiles::
420 EnsureBrowserContextKeyedServiceFactoriesBuilt(); 423 EnsureBrowserContextKeyedServiceFactoriesBuilt();
421 424
425 #if defined(ENABLE_SUPERVISED_USERS)
426 if (!IsOffTheRecord()) {
427 SupervisedUserSettingsService* settings_service =
428 SupervisedUserSettingsServiceFactory::GetForProfile(this);
429 TestingPrefStore* store = new TestingPrefStore();
430 settings_service->Init(store);
431 store->SetInitializationCompleted();
432 }
433 #endif
434
422 if (prefs_.get()) 435 if (prefs_.get())
423 user_prefs::UserPrefs::Set(this, prefs_.get()); 436 user_prefs::UserPrefs::Set(this, prefs_.get());
424 else if (IsOffTheRecord()) 437 else if (IsOffTheRecord())
425 CreateIncognitoPrefService(); 438 CreateIncognitoPrefService();
439 else if (!supervised_user_id_.empty())
440 CreatePrefServiceForSupervisedUser();
426 else 441 else
427 CreateTestingPrefService(); 442 CreateTestingPrefService();
428 443
429 if (!base::PathExists(profile_path_)) 444 if (!base::PathExists(profile_path_))
430 base::CreateDirectory(profile_path_); 445 base::CreateDirectory(profile_path_);
431 446
432 // TODO(joaodasilva): remove this once this PKS isn't created in ProfileImpl 447 // TODO(joaodasilva): remove this once this PKS isn't created in ProfileImpl
433 // anymore, after converting the PrefService to a PKS. Until then it must 448 // anymore, after converting the PrefService to a PKS. Until then it must
434 // be associated with a TestingProfile too. 449 // be associated with a TestingProfile too.
435 if (!IsOffTheRecord()) 450 if (!IsOffTheRecord())
(...skipping 30 matching lines...) Expand all
466 DCHECK(!original_profile_); 481 DCHECK(!original_profile_);
467 user_prefs::PrefRegistrySyncable* pref_registry = 482 user_prefs::PrefRegistrySyncable* pref_registry =
468 static_cast<user_prefs::PrefRegistrySyncable*>( 483 static_cast<user_prefs::PrefRegistrySyncable*>(
469 prefs_->DeprecatedGetPrefRegistry()); 484 prefs_->DeprecatedGetPrefRegistry());
470 browser_context_dependency_manager_-> 485 browser_context_dependency_manager_->
471 RegisterProfilePrefsForServices(this, pref_registry); 486 RegisterProfilePrefsForServices(this, pref_registry);
472 } 487 }
473 488
474 browser_context_dependency_manager_->CreateBrowserContextServicesForTest( 489 browser_context_dependency_manager_->CreateBrowserContextServicesForTest(
475 this); 490 this);
476
477 #if defined(ENABLE_SUPERVISED_USERS)
478 if (!IsOffTheRecord()) {
479 SupervisedUserSettingsService* settings_service =
480 SupervisedUserSettingsServiceFactory::GetForProfile(this);
481 TestingPrefStore* store = new TestingPrefStore();
482 settings_service->Init(store);
483 store->SetInitializationCompleted();
484 }
485 #endif
486 } 491 }
487 492
488 void TestingProfile::FinishInit() { 493 void TestingProfile::FinishInit() {
489 DCHECK(content::NotificationService::current()); 494 DCHECK(content::NotificationService::current());
490 content::NotificationService::current()->Notify( 495 content::NotificationService::current()->Notify(
491 chrome::NOTIFICATION_PROFILE_CREATED, 496 chrome::NOTIFICATION_PROFILE_CREATED,
492 content::Source<Profile>(static_cast<Profile*>(this)), 497 content::Source<Profile>(static_cast<Profile*>(this)),
493 content::NotificationService::NoDetails()); 498 content::NotificationService::NoDetails());
494 499
495 ProfileManager* profile_manager = g_browser_process->profile_manager(); 500 ProfileManager* profile_manager = g_browser_process->profile_manager();
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after
741 } 746 }
742 747
743 void TestingProfile::CreateTestingPrefService() { 748 void TestingProfile::CreateTestingPrefService() {
744 DCHECK(!prefs_.get()); 749 DCHECK(!prefs_.get());
745 testing_prefs_ = new syncable_prefs::TestingPrefServiceSyncable(); 750 testing_prefs_ = new syncable_prefs::TestingPrefServiceSyncable();
746 prefs_.reset(testing_prefs_); 751 prefs_.reset(testing_prefs_);
747 user_prefs::UserPrefs::Set(this, prefs_.get()); 752 user_prefs::UserPrefs::Set(this, prefs_.get());
748 chrome::RegisterUserProfilePrefs(testing_prefs_->registry()); 753 chrome::RegisterUserProfilePrefs(testing_prefs_->registry());
749 } 754 }
750 755
756 void TestingProfile::CreatePrefServiceForSupervisedUser() {
757 DCHECK(!prefs_.get());
758 DCHECK(!supervised_user_id_.empty());
759 syncable_prefs::PrefServiceMockFactory factory;
760 SupervisedUserSettingsService* supervised_user_settings =
761 SupervisedUserSettingsServiceFactory::GetForProfile(this);
762 scoped_refptr<PrefStore> supervised_user_prefs =
763 make_scoped_refptr(new SupervisedUserPrefStore(supervised_user_settings));
764
765 factory.set_supervised_user_prefs(supervised_user_prefs);
766
767 scoped_refptr<user_prefs::PrefRegistrySyncable> registry(
768 new user_prefs::PrefRegistrySyncable);
769
770 std::unique_ptr<syncable_prefs::PrefServiceSyncable> prefs(
771 factory.CreateSyncable(registry.get()));
Marc Treib 2016/05/23 15:32:43 Can't you assign this directly to prefs_?
mamir 2016/05/23 19:35:14 Done.
772 chrome::RegisterUserProfilePrefs(registry.get());
773 prefs_ = std::move(prefs);
774 user_prefs::UserPrefs::Set(this, prefs_.get());
775 }
776
751 void TestingProfile::CreateIncognitoPrefService() { 777 void TestingProfile::CreateIncognitoPrefService() {
752 DCHECK(original_profile_); 778 DCHECK(original_profile_);
753 DCHECK(!testing_prefs_); 779 DCHECK(!testing_prefs_);
754 // Simplified version of ProfileImpl::GetOffTheRecordPrefs(). Note this 780 // Simplified version of ProfileImpl::GetOffTheRecordPrefs(). Note this
755 // leaves testing_prefs_ unset. 781 // leaves testing_prefs_ unset.
756 prefs_.reset(CreateIncognitoPrefServiceSyncable( 782 prefs_.reset(CreateIncognitoPrefServiceSyncable(
757 original_profile_->prefs_.get(), NULL)); 783 original_profile_->prefs_.get(), NULL));
758 user_prefs::UserPrefs::Set(this, prefs_.get()); 784 user_prefs::UserPrefs::Set(this, prefs_.get());
759 } 785 }
760 786
(...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after
1032 // Note: Owned by |original_profile|. 1058 // Note: Owned by |original_profile|.
1033 return new TestingProfile(path_, delegate_, 1059 return new TestingProfile(path_, delegate_,
1034 #if defined(ENABLE_EXTENSIONS) 1060 #if defined(ENABLE_EXTENSIONS)
1035 extension_policy_, 1061 extension_policy_,
1036 #endif 1062 #endif
1037 std::move(pref_service_), original_profile, 1063 std::move(pref_service_), original_profile,
1038 guest_session_, supervised_user_id_, 1064 guest_session_, supervised_user_id_,
1039 std::move(policy_service_), testing_factories_, 1065 std::move(policy_service_), testing_factories_,
1040 profile_name_); 1066 profile_name_);
1041 } 1067 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698