| 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 "base/base_paths.h" | 7 #include "base/base_paths.h" |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/files/file_util.h" | 9 #include "base/files/file_util.h" |
| 10 #include "base/message_loop/message_loop_proxy.h" | 10 #include "base/message_loop/message_loop_proxy.h" |
| (...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 177 // Must be kept in sync with | 177 // Must be kept in sync with |
| 178 // ChromeBrowserMainPartsChromeos::PreEarlyInitialization. | 178 // ChromeBrowserMainPartsChromeos::PreEarlyInitialization. |
| 179 const char TestingProfile::kTestUserProfileDir[] = "test-user"; | 179 const char TestingProfile::kTestUserProfileDir[] = "test-user"; |
| 180 #else | 180 #else |
| 181 const char TestingProfile::kTestUserProfileDir[] = "Default"; | 181 const char TestingProfile::kTestUserProfileDir[] = "Default"; |
| 182 #endif | 182 #endif |
| 183 | 183 |
| 184 TestingProfile::TestingProfile() | 184 TestingProfile::TestingProfile() |
| 185 : start_time_(Time::Now()), | 185 : start_time_(Time::Now()), |
| 186 testing_prefs_(NULL), | 186 testing_prefs_(NULL), |
| 187 incognito_(false), | |
| 188 force_incognito_(false), | 187 force_incognito_(false), |
| 189 original_profile_(NULL), | 188 original_profile_(NULL), |
| 190 guest_session_(false), | 189 guest_session_(false), |
| 191 last_session_exited_cleanly_(true), | 190 last_session_exited_cleanly_(true), |
| 192 browser_context_dependency_manager_( | 191 browser_context_dependency_manager_( |
| 193 BrowserContextDependencyManager::GetInstance()), | 192 BrowserContextDependencyManager::GetInstance()), |
| 194 resource_context_(NULL), | 193 resource_context_(NULL), |
| 195 delegate_(NULL) { | 194 delegate_(NULL) { |
| 196 CreateTempProfileDir(); | 195 CreateTempProfileDir(); |
| 197 profile_path_ = temp_dir_.path(); | 196 profile_path_ = temp_dir_.path(); |
| 198 | 197 |
| 199 Init(); | 198 Init(); |
| 200 FinishInit(); | 199 FinishInit(); |
| 201 } | 200 } |
| 202 | 201 |
| 203 TestingProfile::TestingProfile(const base::FilePath& path) | 202 TestingProfile::TestingProfile(const base::FilePath& path) |
| 204 : start_time_(Time::Now()), | 203 : start_time_(Time::Now()), |
| 205 testing_prefs_(NULL), | 204 testing_prefs_(NULL), |
| 206 incognito_(false), | |
| 207 force_incognito_(false), | 205 force_incognito_(false), |
| 208 original_profile_(NULL), | 206 original_profile_(NULL), |
| 209 guest_session_(false), | 207 guest_session_(false), |
| 210 last_session_exited_cleanly_(true), | 208 last_session_exited_cleanly_(true), |
| 211 profile_path_(path), | 209 profile_path_(path), |
| 212 browser_context_dependency_manager_( | 210 browser_context_dependency_manager_( |
| 213 BrowserContextDependencyManager::GetInstance()), | 211 BrowserContextDependencyManager::GetInstance()), |
| 214 resource_context_(NULL), | 212 resource_context_(NULL), |
| 215 delegate_(NULL) { | 213 delegate_(NULL) { |
| 216 Init(); | 214 Init(); |
| 217 FinishInit(); | 215 FinishInit(); |
| 218 } | 216 } |
| 219 | 217 |
| 220 TestingProfile::TestingProfile(const base::FilePath& path, | 218 TestingProfile::TestingProfile(const base::FilePath& path, |
| 221 Delegate* delegate) | 219 Delegate* delegate) |
| 222 : start_time_(Time::Now()), | 220 : start_time_(Time::Now()), |
| 223 testing_prefs_(NULL), | 221 testing_prefs_(NULL), |
| 224 incognito_(false), | |
| 225 force_incognito_(false), | 222 force_incognito_(false), |
| 226 original_profile_(NULL), | 223 original_profile_(NULL), |
| 227 guest_session_(false), | 224 guest_session_(false), |
| 228 last_session_exited_cleanly_(true), | 225 last_session_exited_cleanly_(true), |
| 229 profile_path_(path), | 226 profile_path_(path), |
| 230 browser_context_dependency_manager_( | 227 browser_context_dependency_manager_( |
| 231 BrowserContextDependencyManager::GetInstance()), | 228 BrowserContextDependencyManager::GetInstance()), |
| 232 resource_context_(NULL), | 229 resource_context_(NULL), |
| 233 delegate_(delegate) { | 230 delegate_(delegate) { |
| 234 Init(); | 231 Init(); |
| 235 if (delegate_) { | 232 if (delegate_) { |
| 236 base::MessageLoop::current()->PostTask( | 233 base::MessageLoop::current()->PostTask( |
| 237 FROM_HERE, | 234 FROM_HERE, |
| 238 base::Bind(&TestingProfile::FinishInit, base::Unretained(this))); | 235 base::Bind(&TestingProfile::FinishInit, base::Unretained(this))); |
| 239 } else { | 236 } else { |
| 240 FinishInit(); | 237 FinishInit(); |
| 241 } | 238 } |
| 242 } | 239 } |
| 243 | 240 |
| 244 TestingProfile::TestingProfile( | 241 TestingProfile::TestingProfile( |
| 245 const base::FilePath& path, | 242 const base::FilePath& path, |
| 246 Delegate* delegate, | 243 Delegate* delegate, |
| 247 #if defined(ENABLE_EXTENSIONS) | 244 #if defined(ENABLE_EXTENSIONS) |
| 248 scoped_refptr<ExtensionSpecialStoragePolicy> extension_policy, | 245 scoped_refptr<ExtensionSpecialStoragePolicy> extension_policy, |
| 249 #endif | 246 #endif |
| 250 scoped_ptr<PrefServiceSyncable> prefs, | 247 scoped_ptr<PrefServiceSyncable> prefs, |
| 251 bool incognito, | 248 TestingProfile* parent, |
| 252 bool guest_session, | 249 bool guest_session, |
| 253 const std::string& supervised_user_id, | 250 const std::string& supervised_user_id, |
| 254 scoped_ptr<policy::PolicyService> policy_service, | 251 scoped_ptr<policy::PolicyService> policy_service, |
| 255 const TestingFactories& factories) | 252 const TestingFactories& factories) |
| 256 : start_time_(Time::Now()), | 253 : start_time_(Time::Now()), |
| 257 prefs_(prefs.release()), | 254 prefs_(prefs.release()), |
| 258 testing_prefs_(NULL), | 255 testing_prefs_(NULL), |
| 259 incognito_(incognito), | |
| 260 force_incognito_(false), | 256 force_incognito_(false), |
| 261 original_profile_(NULL), | 257 original_profile_(parent), |
| 262 guest_session_(guest_session), | 258 guest_session_(guest_session), |
| 263 supervised_user_id_(supervised_user_id), | 259 supervised_user_id_(supervised_user_id), |
| 264 last_session_exited_cleanly_(true), | 260 last_session_exited_cleanly_(true), |
| 265 #if defined(ENABLE_EXTENSIONS) | 261 #if defined(ENABLE_EXTENSIONS) |
| 266 extension_special_storage_policy_(extension_policy), | 262 extension_special_storage_policy_(extension_policy), |
| 267 #endif | 263 #endif |
| 268 profile_path_(path), | 264 profile_path_(path), |
| 269 browser_context_dependency_manager_( | 265 browser_context_dependency_manager_( |
| 270 BrowserContextDependencyManager::GetInstance()), | 266 BrowserContextDependencyManager::GetInstance()), |
| 271 resource_context_(NULL), | 267 resource_context_(NULL), |
| 272 delegate_(delegate), | 268 delegate_(delegate), |
| 273 policy_service_(policy_service.release()) { | 269 policy_service_(policy_service.release()) { |
| 270 if (parent) |
| 271 parent->SetOffTheRecordProfile(scoped_ptr<Profile>(this)); |
| 272 |
| 274 // If no profile path was supplied, create one. | 273 // If no profile path was supplied, create one. |
| 275 if (profile_path_.empty()) { | 274 if (profile_path_.empty()) { |
| 276 CreateTempProfileDir(); | 275 CreateTempProfileDir(); |
| 277 profile_path_ = temp_dir_.path(); | 276 profile_path_ = temp_dir_.path(); |
| 278 } | 277 } |
| 279 | 278 |
| 280 // Set any testing factories prior to initializing the services. | 279 // Set any testing factories prior to initializing the services. |
| 281 for (TestingFactories::const_iterator it = factories.begin(); | 280 for (TestingFactories::const_iterator it = factories.begin(); |
| 282 it != factories.end(); ++it) { | 281 it != factories.end(); ++it) { |
| 283 it->first->SetTestingFactory(this, it->second); | 282 it->first->SetTestingFactory(this, it->second); |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 335 AndroidProfileOAuth2TokenService::set_is_testing_profile(); | 334 AndroidProfileOAuth2TokenService::set_is_testing_profile(); |
| 336 #endif | 335 #endif |
| 337 | 336 |
| 338 // Normally this would happen during browser startup, but for tests | 337 // Normally this would happen during browser startup, but for tests |
| 339 // we need to trigger creation of Profile-related services. | 338 // we need to trigger creation of Profile-related services. |
| 340 ChromeBrowserMainExtraPartsProfiles:: | 339 ChromeBrowserMainExtraPartsProfiles:: |
| 341 EnsureBrowserContextKeyedServiceFactoriesBuilt(); | 340 EnsureBrowserContextKeyedServiceFactoriesBuilt(); |
| 342 | 341 |
| 343 if (prefs_.get()) | 342 if (prefs_.get()) |
| 344 user_prefs::UserPrefs::Set(this, prefs_.get()); | 343 user_prefs::UserPrefs::Set(this, prefs_.get()); |
| 344 else if (IsOffTheRecord()) |
| 345 CreateIncognitoPrefService(); |
| 345 else | 346 else |
| 346 CreateTestingPrefService(); | 347 CreateTestingPrefService(); |
| 347 | 348 |
| 348 if (!base::PathExists(profile_path_)) | 349 if (!base::PathExists(profile_path_)) |
| 349 base::CreateDirectory(profile_path_); | 350 base::CreateDirectory(profile_path_); |
| 350 | 351 |
| 351 // TODO(joaodasilva): remove this once this PKS isn't created in ProfileImpl | 352 // TODO(joaodasilva): remove this once this PKS isn't created in ProfileImpl |
| 352 // anymore, after converting the PrefService to a PKS. Until then it must | 353 // anymore, after converting the PrefService to a PKS. Until then it must |
| 353 // be associated with a TestingProfile too. | 354 // be associated with a TestingProfile too. |
| 354 if (!IsOffTheRecord()) | 355 if (!IsOffTheRecord()) |
| 355 CreateProfilePolicyConnector(); | 356 CreateProfilePolicyConnector(); |
| 356 | 357 |
| 357 #if defined(ENABLE_EXTENSIONS) | 358 #if defined(ENABLE_EXTENSIONS) |
| 358 extensions::ExtensionSystemFactory::GetInstance()->SetTestingFactory( | 359 extensions::ExtensionSystemFactory::GetInstance()->SetTestingFactory( |
| 359 this, extensions::TestExtensionSystem::Build); | 360 this, extensions::TestExtensionSystem::Build); |
| 360 #endif | 361 #endif |
| 361 | 362 |
| 362 // If no original profile was specified for this profile: register preferences | 363 // Prefs for incognito profiles are set in CreateIncognitoPrefService() by |
| 363 // even if this is an incognito profile - this allows tests to create a | 364 // simulating ProfileImpl::GetOffTheRecordPrefs(). |
| 364 // standalone incognito profile while still having prefs registered. | 365 if (!IsOffTheRecord()) { |
| 365 if (!IsOffTheRecord() || !original_profile_) { | 366 DCHECK(!original_profile_); |
| 366 user_prefs::PrefRegistrySyncable* pref_registry = | 367 user_prefs::PrefRegistrySyncable* pref_registry = |
| 367 static_cast<user_prefs::PrefRegistrySyncable*>( | 368 static_cast<user_prefs::PrefRegistrySyncable*>( |
| 368 prefs_->DeprecatedGetPrefRegistry()); | 369 prefs_->DeprecatedGetPrefRegistry()); |
| 369 browser_context_dependency_manager_-> | 370 browser_context_dependency_manager_-> |
| 370 RegisterProfilePrefsForServices(this, pref_registry); | 371 RegisterProfilePrefsForServices(this, pref_registry); |
| 371 } | 372 } |
| 372 | 373 |
| 373 browser_context_dependency_manager_->CreateBrowserContextServicesForTest( | 374 browser_context_dependency_manager_->CreateBrowserContextServicesForTest( |
| 374 this); | 375 this); |
| 375 | 376 |
| 376 #if defined(ENABLE_NOTIFICATIONS) | 377 #if defined(ENABLE_NOTIFICATIONS) |
| 377 // Install profile keyed service factory hooks for dummy/test services | 378 // Install profile keyed service factory hooks for dummy/test services |
| 378 DesktopNotificationServiceFactory::GetInstance()->SetTestingFactory( | 379 DesktopNotificationServiceFactory::GetInstance()->SetTestingFactory( |
| 379 this, CreateTestDesktopNotificationService); | 380 this, CreateTestDesktopNotificationService); |
| 380 #endif | 381 #endif |
| 381 | 382 |
| 382 #if defined(ENABLE_MANAGED_USERS) | 383 #if defined(ENABLE_MANAGED_USERS) |
| 383 SupervisedUserSettingsService* settings_service = | 384 if (!IsOffTheRecord()) { |
| 384 SupervisedUserSettingsServiceFactory::GetForProfile(this); | 385 SupervisedUserSettingsService* settings_service = |
| 385 TestingPrefStore* store = new TestingPrefStore(); | 386 SupervisedUserSettingsServiceFactory::GetForProfile(this); |
| 386 settings_service->Init(store); | 387 TestingPrefStore* store = new TestingPrefStore(); |
| 387 store->SetInitializationCompleted(); | 388 settings_service->Init(store); |
| 389 store->SetInitializationCompleted(); |
| 390 } |
| 388 #endif | 391 #endif |
| 389 | 392 |
| 390 profile_name_ = "testing_profile"; | 393 profile_name_ = "testing_profile"; |
| 391 } | 394 } |
| 392 | 395 |
| 393 void TestingProfile::FinishInit() { | 396 void TestingProfile::FinishInit() { |
| 394 DCHECK(content::NotificationService::current()); | 397 DCHECK(content::NotificationService::current()); |
| 395 content::NotificationService::current()->Notify( | 398 content::NotificationService::current()->Notify( |
| 396 chrome::NOTIFICATION_PROFILE_CREATED, | 399 chrome::NOTIFICATION_PROFILE_CREATED, |
| 397 content::Source<Profile>(static_cast<Profile*>(this)), | 400 content::Source<Profile>(static_cast<Profile*>(this)), |
| 398 content::NotificationService::NoDetails()); | 401 content::NotificationService::NoDetails()); |
| 399 | 402 |
| 400 ProfileManager* profile_manager = g_browser_process->profile_manager(); | 403 ProfileManager* profile_manager = g_browser_process->profile_manager(); |
| 401 if (profile_manager) | 404 if (profile_manager) |
| 402 profile_manager->InitProfileUserPrefs(this); | 405 profile_manager->InitProfileUserPrefs(this); |
| 403 | 406 |
| 404 if (delegate_) | 407 if (delegate_) |
| 405 delegate_->OnProfileCreated(this, true, false); | 408 delegate_->OnProfileCreated(this, true, false); |
| 406 } | 409 } |
| 407 | 410 |
| 408 TestingProfile::~TestingProfile() { | 411 TestingProfile::~TestingProfile() { |
| 409 // Revert to non-incognito mode before shutdown. | 412 // Revert to non-incognito mode before shutdown. |
| 410 force_incognito_ = false; | 413 force_incognito_ = false; |
| 411 | 414 |
| 415 // If this profile owns an incognito profile, tear it down first. |
| 416 incognito_profile_.reset(); |
| 417 |
| 412 // Any objects holding live URLFetchers should be deleted before teardown. | 418 // Any objects holding live URLFetchers should be deleted before teardown. |
| 413 TemplateURLFetcherFactory::ShutdownForProfile(this); | 419 TemplateURLFetcherFactory::ShutdownForProfile(this); |
| 414 | 420 |
| 415 MaybeSendDestroyedNotification(); | 421 MaybeSendDestroyedNotification(); |
| 416 | 422 |
| 417 browser_context_dependency_manager_->DestroyBrowserContextServices(this); | 423 browser_context_dependency_manager_->DestroyBrowserContextServices(this); |
| 418 | 424 |
| 419 if (host_content_settings_map_.get()) | 425 if (host_content_settings_map_.get()) |
| 420 host_content_settings_map_->ShutdownOnUIThread(); | 426 host_content_settings_map_->ShutdownOnUIThread(); |
| 421 | 427 |
| (...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 594 | 600 |
| 595 base::FilePath TestingProfile::GetPath() const { | 601 base::FilePath TestingProfile::GetPath() const { |
| 596 return profile_path_; | 602 return profile_path_; |
| 597 } | 603 } |
| 598 | 604 |
| 599 scoped_refptr<base::SequencedTaskRunner> TestingProfile::GetIOTaskRunner() { | 605 scoped_refptr<base::SequencedTaskRunner> TestingProfile::GetIOTaskRunner() { |
| 600 return base::MessageLoop::current()->message_loop_proxy(); | 606 return base::MessageLoop::current()->message_loop_proxy(); |
| 601 } | 607 } |
| 602 | 608 |
| 603 TestingPrefServiceSyncable* TestingProfile::GetTestingPrefService() { | 609 TestingPrefServiceSyncable* TestingProfile::GetTestingPrefService() { |
| 604 if (!prefs_.get()) | 610 DCHECK(prefs_); |
| 605 CreateTestingPrefService(); | |
| 606 DCHECK(testing_prefs_); | 611 DCHECK(testing_prefs_); |
| 607 return testing_prefs_; | 612 return testing_prefs_; |
| 608 } | 613 } |
| 609 | 614 |
| 610 TestingProfile* TestingProfile::AsTestingProfile() { | 615 TestingProfile* TestingProfile::AsTestingProfile() { |
| 611 return this; | 616 return this; |
| 612 } | 617 } |
| 613 | 618 |
| 614 std::string TestingProfile::GetProfileName() { | 619 std::string TestingProfile::GetProfileName() { |
| 615 return profile_name_; | 620 return profile_name_; |
| 616 } | 621 } |
| 617 | 622 |
| 618 Profile::ProfileType TestingProfile::GetProfileType() const { | 623 Profile::ProfileType TestingProfile::GetProfileType() const { |
| 619 if (guest_session_) | 624 if (guest_session_) |
| 620 return GUEST_PROFILE; | 625 return GUEST_PROFILE; |
| 621 if (force_incognito_ || incognito_) | 626 if (force_incognito_ || original_profile_) |
| 622 return INCOGNITO_PROFILE; | 627 return INCOGNITO_PROFILE; |
| 623 return REGULAR_PROFILE; | 628 return REGULAR_PROFILE; |
| 624 } | 629 } |
| 625 | 630 |
| 626 bool TestingProfile::IsOffTheRecord() const { | 631 bool TestingProfile::IsOffTheRecord() const { |
| 627 return force_incognito_ || incognito_; | 632 return force_incognito_ || original_profile_; |
| 628 } | 633 } |
| 629 | 634 |
| 630 void TestingProfile::SetOffTheRecordProfile(scoped_ptr<Profile> profile) { | 635 void TestingProfile::SetOffTheRecordProfile(scoped_ptr<Profile> profile) { |
| 631 DCHECK(!IsOffTheRecord()); | 636 DCHECK(!IsOffTheRecord()); |
| 637 DCHECK_EQ(this, profile->GetOriginalProfile()); |
| 632 incognito_profile_ = profile.Pass(); | 638 incognito_profile_ = profile.Pass(); |
| 633 } | 639 } |
| 634 | 640 |
| 635 void TestingProfile::SetOriginalProfile(Profile* profile) { | |
| 636 DCHECK(IsOffTheRecord()); | |
| 637 original_profile_ = profile; | |
| 638 } | |
| 639 | |
| 640 Profile* TestingProfile::GetOffTheRecordProfile() { | 641 Profile* TestingProfile::GetOffTheRecordProfile() { |
| 641 if (IsOffTheRecord()) | 642 if (IsOffTheRecord()) |
| 642 return this; | 643 return this; |
| 643 if (!incognito_profile_) { | 644 if (!incognito_profile_) |
| 644 TestingProfile::Builder builder; | 645 TestingProfile::Builder().BuildIncognito(this); |
| 645 builder.SetIncognito(); | |
| 646 scoped_ptr<TestingProfile> incognito_test_profile(builder.Build()); | |
| 647 incognito_test_profile->SetOriginalProfile(this); | |
| 648 SetOffTheRecordProfile(incognito_test_profile.PassAs<Profile>()); | |
| 649 } | |
| 650 return incognito_profile_.get(); | 646 return incognito_profile_.get(); |
| 651 } | 647 } |
| 652 | 648 |
| 653 bool TestingProfile::HasOffTheRecordProfile() { | 649 bool TestingProfile::HasOffTheRecordProfile() { |
| 654 return incognito_profile_.get() != NULL; | 650 return incognito_profile_.get() != NULL; |
| 655 } | 651 } |
| 656 | 652 |
| 657 Profile* TestingProfile::GetOriginalProfile() { | 653 Profile* TestingProfile::GetOriginalProfile() { |
| 658 if (original_profile_) | 654 if (original_profile_) |
| 659 return original_profile_; | 655 return original_profile_; |
| (...skipping 30 matching lines...) Expand all Loading... |
| 690 } | 686 } |
| 691 | 687 |
| 692 void TestingProfile::CreateTestingPrefService() { | 688 void TestingProfile::CreateTestingPrefService() { |
| 693 DCHECK(!prefs_.get()); | 689 DCHECK(!prefs_.get()); |
| 694 testing_prefs_ = new TestingPrefServiceSyncable(); | 690 testing_prefs_ = new TestingPrefServiceSyncable(); |
| 695 prefs_.reset(testing_prefs_); | 691 prefs_.reset(testing_prefs_); |
| 696 user_prefs::UserPrefs::Set(this, prefs_.get()); | 692 user_prefs::UserPrefs::Set(this, prefs_.get()); |
| 697 chrome::RegisterUserProfilePrefs(testing_prefs_->registry()); | 693 chrome::RegisterUserProfilePrefs(testing_prefs_->registry()); |
| 698 } | 694 } |
| 699 | 695 |
| 696 void TestingProfile::CreateIncognitoPrefService() { |
| 697 DCHECK(original_profile_); |
| 698 DCHECK(!testing_prefs_); |
| 699 // Simplified version of ProfileImpl::GetOffTheRecordPrefs(). Note this |
| 700 // leaves testing_prefs_ unset. |
| 701 prefs_.reset(original_profile_->prefs_->CreateIncognitoPrefService(NULL)); |
| 702 user_prefs::UserPrefs::Set(this, prefs_.get()); |
| 703 } |
| 704 |
| 700 void TestingProfile::CreateProfilePolicyConnector() { | 705 void TestingProfile::CreateProfilePolicyConnector() { |
| 701 #if defined(ENABLE_CONFIGURATION_POLICY) | 706 #if defined(ENABLE_CONFIGURATION_POLICY) |
| 702 schema_registry_service_ = | 707 schema_registry_service_ = |
| 703 policy::SchemaRegistryServiceFactory::CreateForContext( | 708 policy::SchemaRegistryServiceFactory::CreateForContext( |
| 704 this, policy::Schema(), NULL); | 709 this, policy::Schema(), NULL); |
| 705 CHECK_EQ(schema_registry_service_.get(), | 710 CHECK_EQ(schema_registry_service_.get(), |
| 706 policy::SchemaRegistryServiceFactory::GetForContext(this)); | 711 policy::SchemaRegistryServiceFactory::GetForContext(this)); |
| 707 #endif // defined(ENABLE_CONFIGURATION_POLICY) | 712 #endif // defined(ENABLE_CONFIGURATION_POLICY) |
| 708 | 713 |
| 709 if (!policy_service_) { | 714 if (!policy_service_) { |
| 710 #if defined(ENABLE_CONFIGURATION_POLICY) | 715 #if defined(ENABLE_CONFIGURATION_POLICY) |
| 711 std::vector<policy::ConfigurationPolicyProvider*> providers; | 716 std::vector<policy::ConfigurationPolicyProvider*> providers; |
| 712 policy_service_.reset(new policy::PolicyServiceImpl(providers)); | 717 policy_service_.reset(new policy::PolicyServiceImpl(providers)); |
| 713 #else | 718 #else |
| 714 policy_service_.reset(new policy::PolicyServiceStub()); | 719 policy_service_.reset(new policy::PolicyServiceStub()); |
| 715 #endif | 720 #endif |
| 716 } | 721 } |
| 717 profile_policy_connector_.reset(new policy::ProfilePolicyConnector()); | 722 profile_policy_connector_.reset(new policy::ProfilePolicyConnector()); |
| 718 profile_policy_connector_->InitForTesting(policy_service_.Pass()); | 723 profile_policy_connector_->InitForTesting(policy_service_.Pass()); |
| 719 policy::ProfilePolicyConnectorFactory::GetInstance()->SetServiceForTesting( | 724 policy::ProfilePolicyConnectorFactory::GetInstance()->SetServiceForTesting( |
| 720 this, profile_policy_connector_.get()); | 725 this, profile_policy_connector_.get()); |
| 721 CHECK_EQ(profile_policy_connector_.get(), | 726 CHECK_EQ(profile_policy_connector_.get(), |
| 722 policy::ProfilePolicyConnectorFactory::GetForProfile(this)); | 727 policy::ProfilePolicyConnectorFactory::GetForProfile(this)); |
| 723 } | 728 } |
| 724 | 729 |
| 725 PrefService* TestingProfile::GetPrefs() { | 730 PrefService* TestingProfile::GetPrefs() { |
| 726 if (!prefs_.get()) { | 731 DCHECK(prefs_); |
| 727 CreateTestingPrefService(); | |
| 728 } | |
| 729 return prefs_.get(); | 732 return prefs_.get(); |
| 730 } | 733 } |
| 731 | 734 |
| 732 history::TopSites* TestingProfile::GetTopSites() { | 735 history::TopSites* TestingProfile::GetTopSites() { |
| 733 return top_sites_.get(); | 736 return top_sites_.get(); |
| 734 } | 737 } |
| 735 | 738 |
| 736 history::TopSites* TestingProfile::GetTopSitesWithoutCreating() { | 739 history::TopSites* TestingProfile::GetTopSitesWithoutCreating() { |
| 737 return top_sites_.get(); | 740 return top_sites_.get(); |
| 738 } | 741 } |
| (...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 914 return guest_session_; | 917 return guest_session_; |
| 915 } | 918 } |
| 916 | 919 |
| 917 Profile::ExitType TestingProfile::GetLastSessionExitType() { | 920 Profile::ExitType TestingProfile::GetLastSessionExitType() { |
| 918 return last_session_exited_cleanly_ ? EXIT_NORMAL : EXIT_CRASHED; | 921 return last_session_exited_cleanly_ ? EXIT_NORMAL : EXIT_CRASHED; |
| 919 } | 922 } |
| 920 | 923 |
| 921 TestingProfile::Builder::Builder() | 924 TestingProfile::Builder::Builder() |
| 922 : build_called_(false), | 925 : build_called_(false), |
| 923 delegate_(NULL), | 926 delegate_(NULL), |
| 924 incognito_(false), | |
| 925 guest_session_(false) { | 927 guest_session_(false) { |
| 926 } | 928 } |
| 927 | 929 |
| 928 TestingProfile::Builder::~Builder() { | 930 TestingProfile::Builder::~Builder() { |
| 929 } | 931 } |
| 930 | 932 |
| 931 void TestingProfile::Builder::SetPath(const base::FilePath& path) { | 933 void TestingProfile::Builder::SetPath(const base::FilePath& path) { |
| 932 path_ = path; | 934 path_ = path; |
| 933 } | 935 } |
| 934 | 936 |
| 935 void TestingProfile::Builder::SetDelegate(Delegate* delegate) { | 937 void TestingProfile::Builder::SetDelegate(Delegate* delegate) { |
| 936 delegate_ = delegate; | 938 delegate_ = delegate; |
| 937 } | 939 } |
| 938 | 940 |
| 939 #if defined(ENABLE_EXTENSIONS) | 941 #if defined(ENABLE_EXTENSIONS) |
| 940 void TestingProfile::Builder::SetExtensionSpecialStoragePolicy( | 942 void TestingProfile::Builder::SetExtensionSpecialStoragePolicy( |
| 941 scoped_refptr<ExtensionSpecialStoragePolicy> policy) { | 943 scoped_refptr<ExtensionSpecialStoragePolicy> policy) { |
| 942 extension_policy_ = policy; | 944 extension_policy_ = policy; |
| 943 } | 945 } |
| 944 #endif | 946 #endif |
| 945 | 947 |
| 946 void TestingProfile::Builder::SetPrefService( | 948 void TestingProfile::Builder::SetPrefService( |
| 947 scoped_ptr<PrefServiceSyncable> prefs) { | 949 scoped_ptr<PrefServiceSyncable> prefs) { |
| 948 pref_service_ = prefs.Pass(); | 950 pref_service_ = prefs.Pass(); |
| 949 } | 951 } |
| 950 | 952 |
| 951 void TestingProfile::Builder::SetIncognito() { | |
| 952 incognito_ = true; | |
| 953 } | |
| 954 | |
| 955 void TestingProfile::Builder::SetGuestSession() { | 953 void TestingProfile::Builder::SetGuestSession() { |
| 956 guest_session_ = true; | 954 guest_session_ = true; |
| 957 } | 955 } |
| 958 | 956 |
| 959 void TestingProfile::Builder::SetSupervisedUserId( | 957 void TestingProfile::Builder::SetSupervisedUserId( |
| 960 const std::string& supervised_user_id) { | 958 const std::string& supervised_user_id) { |
| 961 supervised_user_id_ = supervised_user_id; | 959 supervised_user_id_ = supervised_user_id; |
| 962 } | 960 } |
| 963 | 961 |
| 964 void TestingProfile::Builder::SetPolicyService( | 962 void TestingProfile::Builder::SetPolicyService( |
| 965 scoped_ptr<policy::PolicyService> policy_service) { | 963 scoped_ptr<policy::PolicyService> policy_service) { |
| 966 policy_service_ = policy_service.Pass(); | 964 policy_service_ = policy_service.Pass(); |
| 967 } | 965 } |
| 968 | 966 |
| 969 void TestingProfile::Builder::AddTestingFactory( | 967 void TestingProfile::Builder::AddTestingFactory( |
| 970 BrowserContextKeyedServiceFactory* service_factory, | 968 BrowserContextKeyedServiceFactory* service_factory, |
| 971 BrowserContextKeyedServiceFactory::TestingFactoryFunction callback) { | 969 BrowserContextKeyedServiceFactory::TestingFactoryFunction callback) { |
| 972 testing_factories_.push_back(std::make_pair(service_factory, callback)); | 970 testing_factories_.push_back(std::make_pair(service_factory, callback)); |
| 973 } | 971 } |
| 974 | 972 |
| 975 scoped_ptr<TestingProfile> TestingProfile::Builder::Build() { | 973 scoped_ptr<TestingProfile> TestingProfile::Builder::Build() { |
| 976 DCHECK(!build_called_); | 974 DCHECK(!build_called_); |
| 977 build_called_ = true; | 975 build_called_ = true; |
| 978 | 976 |
| 979 return scoped_ptr<TestingProfile>(new TestingProfile( | 977 return scoped_ptr<TestingProfile>(new TestingProfile(path_, |
| 980 path_, | 978 delegate_, |
| 981 delegate_, | |
| 982 #if defined(ENABLE_EXTENSIONS) | 979 #if defined(ENABLE_EXTENSIONS) |
| 983 extension_policy_, | 980 extension_policy_, |
| 984 #endif | 981 #endif |
| 985 pref_service_.Pass(), | 982 pref_service_.Pass(), |
| 986 incognito_, | 983 NULL, |
| 987 guest_session_, | 984 guest_session_, |
| 988 supervised_user_id_, | 985 supervised_user_id_, |
| 989 policy_service_.Pass(), | 986 policy_service_.Pass(), |
| 990 testing_factories_)); | 987 testing_factories_)); |
| 991 } | 988 } |
| 989 |
| 990 TestingProfile* TestingProfile::Builder::BuildIncognito( |
| 991 TestingProfile* original_profile) { |
| 992 DCHECK(!build_called_); |
| 993 DCHECK(original_profile); |
| 994 build_called_ = true; |
| 995 |
| 996 // Note: Owned by |original_profile|. |
| 997 return new TestingProfile(path_, |
| 998 delegate_, |
| 999 #if defined(ENABLE_EXTENSIONS) |
| 1000 extension_policy_, |
| 1001 #endif |
| 1002 pref_service_.Pass(), |
| 1003 original_profile, |
| 1004 guest_session_, |
| 1005 supervised_user_id_, |
| 1006 policy_service_.Pass(), |
| 1007 testing_factories_); |
| 1008 } |
| OLD | NEW |