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

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: Fixing the build again! Created 4 years, 5 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
« no previous file with comments | « chrome/test/base/testing_profile.h ('k') | extensions/common/extension.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/user_prefs/user_prefs.h" 81 #include "components/user_prefs/user_prefs.h"
81 #include "components/webdata_services/web_data_service_wrapper.h" 82 #include "components/webdata_services/web_data_service_wrapper.h"
82 #include "components/zoom/zoom_event_manager.h" 83 #include "components/zoom/zoom_event_manager.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"
88 #include "content/public/browser/zoom_level_delegate.h" 89 #include "content/public/browser/zoom_level_delegate.h"
89 #include "content/public/test/mock_resource_context.h" 90 #include "content/public/test/mock_resource_context.h"
90 #include "content/public/test/test_utils.h" 91 #include "content/public/test/test_utils.h"
91 #include "extensions/common/constants.h" 92 #include "extensions/common/constants.h"
92 #include "net/cookies/cookie_store.h" 93 #include "net/cookies/cookie_store.h"
93 #include "net/url_request/url_request_context.h" 94 #include "net/url_request/url_request_context.h"
94 #include "net/url_request/url_request_context_getter.h" 95 #include "net/url_request/url_request_context_getter.h"
95 #include "net/url_request/url_request_test_util.h" 96 #include "net/url_request/url_request_test_util.h"
97 #include "sync/api/fake_sync_change_processor.h"
98 #include "sync/api/sync_error_factory_mock.h"
96 #include "testing/gmock/include/gmock/gmock.h" 99 #include "testing/gmock/include/gmock/gmock.h"
97 100
98 #if defined(ENABLE_EXTENSIONS) 101 #if defined(ENABLE_EXTENSIONS)
99 #include "chrome/browser/extensions/extension_service.h" 102 #include "chrome/browser/extensions/extension_service.h"
100 #include "chrome/browser/extensions/extension_special_storage_policy.h" 103 #include "chrome/browser/extensions/extension_special_storage_policy.h"
101 #include "chrome/browser/extensions/extension_system_factory.h" 104 #include "chrome/browser/extensions/extension_system_factory.h"
102 #include "chrome/browser/extensions/test_extension_system.h" 105 #include "chrome/browser/extensions/test_extension_system.h"
103 #include "components/guest_view/browser/guest_view_manager.h" 106 #include "components/guest_view/browser/guest_view_manager.h"
104 #include "extensions/browser/event_router_factory.h" 107 #include "extensions/browser/event_router_factory.h"
105 #include "extensions/browser/extension_pref_value_map.h" 108 #include "extensions/browser/extension_pref_value_map.h"
106 #include "extensions/browser/extension_pref_value_map_factory.h" 109 #include "extensions/browser/extension_pref_value_map_factory.h"
107 #include "extensions/browser/extension_prefs.h" 110 #include "extensions/browser/extension_prefs.h"
108 #include "extensions/browser/extension_prefs_factory.h" 111 #include "extensions/browser/extension_prefs_factory.h"
109 #include "extensions/browser/extension_prefs_observer.h" 112 #include "extensions/browser/extension_prefs_observer.h"
110 #include "extensions/browser/extension_system.h" 113 #include "extensions/browser/extension_system.h"
111 #endif 114 #endif
112 115
113 #if defined(OS_ANDROID) 116 #if defined(OS_ANDROID)
114 #include "chrome/browser/signin/oauth2_token_service_delegate_android.h" 117 #include "chrome/browser/signin/oauth2_token_service_delegate_android.h"
115 #endif 118 #endif
116 119
117 #if defined(ENABLE_SUPERVISED_USERS) 120 #if defined(ENABLE_SUPERVISED_USERS)
118 #include "chrome/browser/supervised_user/supervised_user_constants.h" 121 #include "chrome/browser/supervised_user/supervised_user_constants.h"
122 #include "chrome/browser/supervised_user/supervised_user_pref_store.h"
119 #include "chrome/browser/supervised_user/supervised_user_settings_service.h" 123 #include "chrome/browser/supervised_user/supervised_user_settings_service.h"
120 #include "chrome/browser/supervised_user/supervised_user_settings_service_factor y.h" 124 #include "chrome/browser/supervised_user/supervised_user_settings_service_factor y.h"
121 #endif 125 #endif
122 126
123 using base::Time; 127 using base::Time;
124 using bookmarks::BookmarkModel; 128 using bookmarks::BookmarkModel;
125 using content::BrowserThread; 129 using content::BrowserThread;
126 using content::DownloadManagerDelegate; 130 using content::DownloadManagerDelegate;
127 using testing::NiceMock; 131 using testing::NiceMock;
128 using testing::Return; 132 using testing::Return;
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after
323 const std::string& supervised_user_id, 327 const std::string& supervised_user_id,
324 std::unique_ptr<policy::PolicyService> policy_service, 328 std::unique_ptr<policy::PolicyService> policy_service,
325 const TestingFactories& factories, 329 const TestingFactories& factories,
326 const std::string& profile_name) 330 const std::string& profile_name)
327 : start_time_(Time::Now()), 331 : start_time_(Time::Now()),
328 prefs_(prefs.release()), 332 prefs_(prefs.release()),
329 testing_prefs_(NULL), 333 testing_prefs_(NULL),
330 force_incognito_(false), 334 force_incognito_(false),
331 original_profile_(parent), 335 original_profile_(parent),
332 guest_session_(guest_session), 336 guest_session_(guest_session),
337 supervised_user_id_(supervised_user_id),
333 last_session_exited_cleanly_(true), 338 last_session_exited_cleanly_(true),
334 #if defined(ENABLE_EXTENSIONS) 339 #if defined(ENABLE_EXTENSIONS)
335 extension_special_storage_policy_(extension_policy), 340 extension_special_storage_policy_(extension_policy),
336 #endif 341 #endif
337 profile_path_(path), 342 profile_path_(path),
338 browser_context_dependency_manager_( 343 browser_context_dependency_manager_(
339 BrowserContextDependencyManager::GetInstance()), 344 BrowserContextDependencyManager::GetInstance()),
340 resource_context_(NULL), 345 resource_context_(NULL),
341 delegate_(delegate), 346 delegate_(delegate),
342 profile_name_(profile_name), 347 profile_name_(profile_name),
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
412 #if defined(OS_ANDROID) 417 #if defined(OS_ANDROID)
413 // Make sure token service knows its running in tests. 418 // Make sure token service knows its running in tests.
414 OAuth2TokenServiceDelegateAndroid::set_is_testing_profile(); 419 OAuth2TokenServiceDelegateAndroid::set_is_testing_profile();
415 #endif 420 #endif
416 421
417 // Normally this would happen during browser startup, but for tests 422 // Normally this would happen during browser startup, but for tests
418 // we need to trigger creation of Profile-related services. 423 // we need to trigger creation of Profile-related services.
419 ChromeBrowserMainExtraPartsProfiles:: 424 ChromeBrowserMainExtraPartsProfiles::
420 EnsureBrowserContextKeyedServiceFactoriesBuilt(); 425 EnsureBrowserContextKeyedServiceFactoriesBuilt();
421 426
427 #if defined(ENABLE_SUPERVISED_USERS)
428 if (!IsOffTheRecord()) {
429 SupervisedUserSettingsService* settings_service =
430 SupervisedUserSettingsServiceFactory::GetForProfile(this);
431 TestingPrefStore* store = new TestingPrefStore();
432 settings_service->Init(store);
433 settings_service->MergeDataAndStartSyncing(
434 syncer::SUPERVISED_USER_SETTINGS, syncer::SyncDataList(),
435 std::unique_ptr<syncer::SyncChangeProcessor>(
436 new syncer::FakeSyncChangeProcessor),
437 std::unique_ptr<syncer::SyncErrorFactory>(
438 new syncer::SyncErrorFactoryMock));
439
440 store->SetInitializationCompleted();
441 }
442 #endif
443
422 if (prefs_.get()) 444 if (prefs_.get())
423 user_prefs::UserPrefs::Set(this, prefs_.get()); 445 user_prefs::UserPrefs::Set(this, prefs_.get());
424 else if (IsOffTheRecord()) 446 else if (IsOffTheRecord())
425 CreateIncognitoPrefService(); 447 CreateIncognitoPrefService();
448 else if (!supervised_user_id_.empty())
449 CreatePrefServiceForSupervisedUser();
426 else 450 else
427 CreateTestingPrefService(); 451 CreateTestingPrefService();
428 452
429 if (!base::PathExists(profile_path_)) 453 if (!base::PathExists(profile_path_))
430 base::CreateDirectory(profile_path_); 454 base::CreateDirectory(profile_path_);
431 455
432 // TODO(joaodasilva): remove this once this PKS isn't created in ProfileImpl 456 // 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 457 // anymore, after converting the PrefService to a PKS. Until then it must
434 // be associated with a TestingProfile too. 458 // be associated with a TestingProfile too.
435 if (!IsOffTheRecord()) 459 if (!IsOffTheRecord())
(...skipping 30 matching lines...) Expand all
466 DCHECK(!original_profile_); 490 DCHECK(!original_profile_);
467 user_prefs::PrefRegistrySyncable* pref_registry = 491 user_prefs::PrefRegistrySyncable* pref_registry =
468 static_cast<user_prefs::PrefRegistrySyncable*>( 492 static_cast<user_prefs::PrefRegistrySyncable*>(
469 prefs_->DeprecatedGetPrefRegistry()); 493 prefs_->DeprecatedGetPrefRegistry());
470 browser_context_dependency_manager_-> 494 browser_context_dependency_manager_->
471 RegisterProfilePrefsForServices(this, pref_registry); 495 RegisterProfilePrefsForServices(this, pref_registry);
472 } 496 }
473 497
474 browser_context_dependency_manager_->CreateBrowserContextServicesForTest( 498 browser_context_dependency_manager_->CreateBrowserContextServicesForTest(
475 this); 499 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 } 500 }
487 501
488 void TestingProfile::FinishInit() { 502 void TestingProfile::FinishInit() {
489 DCHECK(content::NotificationService::current()); 503 DCHECK(content::NotificationService::current());
490 content::NotificationService::current()->Notify( 504 content::NotificationService::current()->Notify(
491 chrome::NOTIFICATION_PROFILE_CREATED, 505 chrome::NOTIFICATION_PROFILE_CREATED,
492 content::Source<Profile>(static_cast<Profile*>(this)), 506 content::Source<Profile>(static_cast<Profile*>(this)),
493 content::NotificationService::NoDetails()); 507 content::NotificationService::NoDetails());
494 508
495 ProfileManager* profile_manager = g_browser_process->profile_manager(); 509 ProfileManager* profile_manager = g_browser_process->profile_manager();
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after
741 } 755 }
742 756
743 void TestingProfile::CreateTestingPrefService() { 757 void TestingProfile::CreateTestingPrefService() {
744 DCHECK(!prefs_.get()); 758 DCHECK(!prefs_.get());
745 testing_prefs_ = new syncable_prefs::TestingPrefServiceSyncable(); 759 testing_prefs_ = new syncable_prefs::TestingPrefServiceSyncable();
746 prefs_.reset(testing_prefs_); 760 prefs_.reset(testing_prefs_);
747 user_prefs::UserPrefs::Set(this, prefs_.get()); 761 user_prefs::UserPrefs::Set(this, prefs_.get());
748 chrome::RegisterUserProfilePrefs(testing_prefs_->registry()); 762 chrome::RegisterUserProfilePrefs(testing_prefs_->registry());
749 } 763 }
750 764
765 void TestingProfile::CreatePrefServiceForSupervisedUser() {
766 DCHECK(!prefs_.get());
767 DCHECK(!supervised_user_id_.empty());
768 syncable_prefs::PrefServiceMockFactory factory;
769 SupervisedUserSettingsService* supervised_user_settings =
770 SupervisedUserSettingsServiceFactory::GetForProfile(this);
771 scoped_refptr<PrefStore> supervised_user_prefs =
772 make_scoped_refptr(new SupervisedUserPrefStore(supervised_user_settings));
773
774 factory.set_supervised_user_prefs(supervised_user_prefs);
775
776 scoped_refptr<user_prefs::PrefRegistrySyncable> registry(
777 new user_prefs::PrefRegistrySyncable);
778
779 prefs_ = factory.CreateSyncable(registry.get());
780 chrome::RegisterUserProfilePrefs(registry.get());
781 user_prefs::UserPrefs::Set(this, prefs_.get());
782 }
783
751 void TestingProfile::CreateIncognitoPrefService() { 784 void TestingProfile::CreateIncognitoPrefService() {
752 DCHECK(original_profile_); 785 DCHECK(original_profile_);
753 DCHECK(!testing_prefs_); 786 DCHECK(!testing_prefs_);
754 // Simplified version of ProfileImpl::GetOffTheRecordPrefs(). Note this 787 // Simplified version of ProfileImpl::GetOffTheRecordPrefs(). Note this
755 // leaves testing_prefs_ unset. 788 // leaves testing_prefs_ unset.
756 prefs_.reset(CreateIncognitoPrefServiceSyncable( 789 prefs_.reset(CreateIncognitoPrefServiceSyncable(
757 original_profile_->prefs_.get(), NULL)); 790 original_profile_->prefs_.get(), NULL));
758 user_prefs::UserPrefs::Set(this, prefs_.get()); 791 user_prefs::UserPrefs::Set(this, prefs_.get());
759 } 792 }
760 793
(...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after
1032 // Note: Owned by |original_profile|. 1065 // Note: Owned by |original_profile|.
1033 return new TestingProfile(path_, delegate_, 1066 return new TestingProfile(path_, delegate_,
1034 #if defined(ENABLE_EXTENSIONS) 1067 #if defined(ENABLE_EXTENSIONS)
1035 extension_policy_, 1068 extension_policy_,
1036 #endif 1069 #endif
1037 std::move(pref_service_), original_profile, 1070 std::move(pref_service_), original_profile,
1038 guest_session_, supervised_user_id_, 1071 guest_session_, supervised_user_id_,
1039 std::move(policy_service_), testing_factories_, 1072 std::move(policy_service_), testing_factories_,
1040 profile_name_); 1073 profile_name_);
1041 } 1074 }
OLDNEW
« no previous file with comments | « chrome/test/base/testing_profile.h ('k') | extensions/common/extension.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698