| 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 "build/build_config.h" | 7 #include "build/build_config.h" |
| 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 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 223 FinishInit(); | 223 FinishInit(); |
| 224 } | 224 } |
| 225 } | 225 } |
| 226 | 226 |
| 227 TestingProfile::TestingProfile( | 227 TestingProfile::TestingProfile( |
| 228 const base::FilePath& path, | 228 const base::FilePath& path, |
| 229 Delegate* delegate, | 229 Delegate* delegate, |
| 230 scoped_refptr<ExtensionSpecialStoragePolicy> extension_policy, | 230 scoped_refptr<ExtensionSpecialStoragePolicy> extension_policy, |
| 231 scoped_ptr<PrefServiceSyncable> prefs, | 231 scoped_ptr<PrefServiceSyncable> prefs, |
| 232 bool incognito, | 232 bool incognito, |
| 233 const std::string& managed_user_id, |
| 233 const TestingFactories& factories) | 234 const TestingFactories& factories) |
| 234 : start_time_(Time::Now()), | 235 : start_time_(Time::Now()), |
| 235 prefs_(prefs.release()), | 236 prefs_(prefs.release()), |
| 236 testing_prefs_(NULL), | 237 testing_prefs_(NULL), |
| 237 incognito_(incognito), | 238 incognito_(incognito), |
| 238 force_incognito_(false), | 239 force_incognito_(false), |
| 239 original_profile_(NULL), | 240 original_profile_(NULL), |
| 241 managed_user_id_(managed_user_id), |
| 240 last_session_exited_cleanly_(true), | 242 last_session_exited_cleanly_(true), |
| 241 extension_special_storage_policy_(extension_policy), | 243 extension_special_storage_policy_(extension_policy), |
| 242 profile_path_(path), | 244 profile_path_(path), |
| 243 browser_context_dependency_manager_( | 245 browser_context_dependency_manager_( |
| 244 BrowserContextDependencyManager::GetInstance()), | 246 BrowserContextDependencyManager::GetInstance()), |
| 245 resource_context_(NULL), | 247 resource_context_(NULL), |
| 246 delegate_(delegate) { | 248 delegate_(delegate) { |
| 247 | 249 |
| 248 // If no profile path was supplied, create one. | 250 // If no profile path was supplied, create one. |
| 249 if (profile_path_.empty()) { | 251 if (profile_path_.empty()) { |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 346 #endif | 348 #endif |
| 347 } | 349 } |
| 348 | 350 |
| 349 void TestingProfile::FinishInit() { | 351 void TestingProfile::FinishInit() { |
| 350 DCHECK(content::NotificationService::current()); | 352 DCHECK(content::NotificationService::current()); |
| 351 content::NotificationService::current()->Notify( | 353 content::NotificationService::current()->Notify( |
| 352 chrome::NOTIFICATION_PROFILE_CREATED, | 354 chrome::NOTIFICATION_PROFILE_CREATED, |
| 353 content::Source<Profile>(static_cast<Profile*>(this)), | 355 content::Source<Profile>(static_cast<Profile*>(this)), |
| 354 content::NotificationService::NoDetails()); | 356 content::NotificationService::NoDetails()); |
| 355 | 357 |
| 356 if (delegate_) | 358 if (delegate_) { |
| 359 delegate_->OnPrefsLoaded(this); |
| 357 delegate_->OnProfileCreated(this, true, false); | 360 delegate_->OnProfileCreated(this, true, false); |
| 361 } |
| 358 } | 362 } |
| 359 | 363 |
| 360 TestingProfile::~TestingProfile() { | 364 TestingProfile::~TestingProfile() { |
| 361 // Revert to non-incognito mode before shutdown. | 365 // Revert to non-incognito mode before shutdown. |
| 362 force_incognito_ = false; | 366 force_incognito_ = false; |
| 363 | 367 |
| 364 // Any objects holding live URLFetchers should be deleted before teardown. | 368 // Any objects holding live URLFetchers should be deleted before teardown. |
| 365 TemplateURLFetcherFactory::ShutdownForProfile(this); | 369 TemplateURLFetcherFactory::ShutdownForProfile(this); |
| 366 | 370 |
| 367 MaybeSendDestroyedNotification(); | 371 MaybeSendDestroyedNotification(); |
| (...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 577 return incognito_profile_.get() != NULL; | 581 return incognito_profile_.get() != NULL; |
| 578 } | 582 } |
| 579 | 583 |
| 580 Profile* TestingProfile::GetOriginalProfile() { | 584 Profile* TestingProfile::GetOriginalProfile() { |
| 581 if (original_profile_) | 585 if (original_profile_) |
| 582 return original_profile_; | 586 return original_profile_; |
| 583 return this; | 587 return this; |
| 584 } | 588 } |
| 585 | 589 |
| 586 bool TestingProfile::IsManaged() { | 590 bool TestingProfile::IsManaged() { |
| 587 return !GetPrefs()->GetString(prefs::kManagedUserId).empty(); | 591 return !managed_user_id_.empty(); |
| 588 } | 592 } |
| 589 | 593 |
| 590 ExtensionService* TestingProfile::GetExtensionService() { | 594 ExtensionService* TestingProfile::GetExtensionService() { |
| 591 return extensions::ExtensionSystem::Get(this)->extension_service(); | 595 return extensions::ExtensionSystem::Get(this)->extension_service(); |
| 592 } | 596 } |
| 593 | 597 |
| 594 void TestingProfile::SetExtensionSpecialStoragePolicy( | 598 void TestingProfile::SetExtensionSpecialStoragePolicy( |
| 595 ExtensionSpecialStoragePolicy* extension_special_storage_policy) { | 599 ExtensionSpecialStoragePolicy* extension_special_storage_policy) { |
| 596 extension_special_storage_policy_ = extension_special_storage_policy; | 600 extension_special_storage_policy_ = extension_special_storage_policy; |
| 597 } | 601 } |
| (...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 850 | 854 |
| 851 void TestingProfile::Builder::SetPrefService( | 855 void TestingProfile::Builder::SetPrefService( |
| 852 scoped_ptr<PrefServiceSyncable> prefs) { | 856 scoped_ptr<PrefServiceSyncable> prefs) { |
| 853 pref_service_ = prefs.Pass(); | 857 pref_service_ = prefs.Pass(); |
| 854 } | 858 } |
| 855 | 859 |
| 856 void TestingProfile::Builder::SetIncognito() { | 860 void TestingProfile::Builder::SetIncognito() { |
| 857 incognito_ = true; | 861 incognito_ = true; |
| 858 } | 862 } |
| 859 | 863 |
| 864 void TestingProfile::Builder::SetManagedUserId( |
| 865 const std::string& managed_user_id) { |
| 866 managed_user_id_ = managed_user_id_; |
| 867 } |
| 868 |
| 860 void TestingProfile::Builder::AddTestingFactory( | 869 void TestingProfile::Builder::AddTestingFactory( |
| 861 BrowserContextKeyedServiceFactory* service_factory, | 870 BrowserContextKeyedServiceFactory* service_factory, |
| 862 BrowserContextKeyedServiceFactory::FactoryFunction callback) { | 871 BrowserContextKeyedServiceFactory::FactoryFunction callback) { |
| 863 testing_factories_.push_back(std::make_pair(service_factory, callback)); | 872 testing_factories_.push_back(std::make_pair(service_factory, callback)); |
| 864 } | 873 } |
| 865 | 874 |
| 866 scoped_ptr<TestingProfile> TestingProfile::Builder::Build() { | 875 scoped_ptr<TestingProfile> TestingProfile::Builder::Build() { |
| 867 DCHECK(!build_called_); | 876 DCHECK(!build_called_); |
| 868 build_called_ = true; | 877 build_called_ = true; |
| 878 |
| 869 return scoped_ptr<TestingProfile>(new TestingProfile( | 879 return scoped_ptr<TestingProfile>(new TestingProfile( |
| 870 path_, | 880 path_, |
| 871 delegate_, | 881 delegate_, |
| 872 extension_policy_, | 882 extension_policy_, |
| 873 pref_service_.Pass(), | 883 pref_service_.Pass(), |
| 874 incognito_, | 884 incognito_, |
| 885 managed_user_id_, |
| 875 testing_factories_)); | 886 testing_factories_)); |
| 876 } | 887 } |
| OLD | NEW |