Index: chrome/test/base/testing_profile.cc |
=================================================================== |
--- chrome/test/base/testing_profile.cc (revision 110703) |
+++ chrome/test/base/testing_profile.cc (working copy) |
@@ -132,6 +132,7 @@ |
testing_prefs_(NULL), |
incognito_(false), |
last_session_exited_cleanly_(true), |
+ enable_lazy_service_initialization_(false), |
Paweł Hajdan Jr.
2011/11/21 12:19:37
This new variable is not checked consistently in T
rpetterson
2011/11/21 22:59:30
I added it to all Get*Service methods which:
- are
|
profile_dependency_manager_(ProfileDependencyManager::GetInstance()) { |
if (!temp_dir_.CreateUniqueTempDir()) { |
LOG(ERROR) << "Failed to create unique temporary directory."; |
@@ -167,11 +168,37 @@ |
testing_prefs_(NULL), |
incognito_(false), |
last_session_exited_cleanly_(true), |
+ enable_lazy_service_initialization_(false), |
profile_path_(path), |
profile_dependency_manager_(ProfileDependencyManager::GetInstance()) { |
Init(); |
} |
+TestingProfile::TestingProfile(const FilePath& path, |
+ Delegate* delegate) |
+ : start_time_(Time::Now()), |
+ testing_prefs_(NULL), |
+ incognito_(false), |
+ last_session_exited_cleanly_(true), |
+ enable_lazy_service_initialization_(false), |
+ profile_path_(path), |
+ profile_dependency_manager_(ProfileDependencyManager::GetInstance()), |
+ delegate_(delegate) { |
+ if (delegate_) { |
+ profile_dependency_manager_->CreateProfileServices(this, true); |
Paweł Hajdan Jr.
2011/11/21 12:19:37
Isn't this essentially identical to Init except th
rpetterson
2011/11/21 22:59:30
Done.
|
+ |
+ // Install profile keyed service factory hooks for dummy/test services |
+ DesktopNotificationServiceFactory::GetInstance()->SetTestingFactory( |
+ this, CreateTestDesktopNotificationService); |
+ |
+ MessageLoop::current()->PostTask(FROM_HERE, |
+ base::Bind(&TestingProfile::FinishInit, |
+ base::Unretained(this))); |
+ } else { |
+ Init(); |
+ } |
+} |
+ |
void TestingProfile::Init() { |
profile_dependency_manager_->CreateProfileServices(this, true); |
@@ -185,6 +212,16 @@ |
content::NotificationService::NoDetails()); |
} |
+void TestingProfile::FinishInit() { |
+ NotificationService::current()->Notify( |
+ chrome::NOTIFICATION_PROFILE_CREATED, |
+ content::Source<Profile>(static_cast<Profile*>(this)), |
+ NotificationService::NoDetails()); |
+ |
+ if (delegate_) |
+ delegate_->OnProfileCreated(this, true); |
+} |
+ |
TestingProfile::~TestingProfile() { |
content::NotificationService::current()->Notify( |
chrome::NOTIFICATION_PROFILE_DESTROYED, |
@@ -480,10 +517,14 @@ |
} |
FaviconService* TestingProfile::GetFaviconService(ServiceAccessType access) { |
+ if (enable_lazy_service_initialization_ && !favicon_service_.get()) |
+ CreateFaviconService(); |
return favicon_service_.get(); |
} |
HistoryService* TestingProfile::GetHistoryService(ServiceAccessType access) { |
+ if (enable_lazy_service_initialization_ && !history_service_.get()) |
+ CreateHistoryService(true, false); |
return history_service_.get(); |
} |
@@ -507,6 +548,8 @@ |
} |
WebDataService* TestingProfile::GetWebDataService(ServiceAccessType access) { |
+ if (enable_lazy_service_initialization_ && !web_data_service_.get()) |
+ CreateWebDataService(false); |
return web_data_service_.get(); |
} |
@@ -685,6 +728,8 @@ |
} |
BookmarkModel* TestingProfile::GetBookmarkModel() { |
+ if (enable_lazy_service_initialization_ && !bookmark_bar_model_.get()) |
+ CreateBookmarkModel(true); |
return bookmark_bar_model_.get(); |
} |