Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 125 return new DesktopNotificationService(profile, NULL); | 125 return new DesktopNotificationService(profile, NULL); |
| 126 } | 126 } |
| 127 | 127 |
| 128 } // namespace | 128 } // namespace |
| 129 | 129 |
| 130 TestingProfile::TestingProfile() | 130 TestingProfile::TestingProfile() |
| 131 : start_time_(Time::Now()), | 131 : start_time_(Time::Now()), |
| 132 testing_prefs_(NULL), | 132 testing_prefs_(NULL), |
| 133 incognito_(false), | 133 incognito_(false), |
| 134 last_session_exited_cleanly_(true), | 134 last_session_exited_cleanly_(true), |
| 135 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
| |
| 135 profile_dependency_manager_(ProfileDependencyManager::GetInstance()) { | 136 profile_dependency_manager_(ProfileDependencyManager::GetInstance()) { |
| 136 if (!temp_dir_.CreateUniqueTempDir()) { | 137 if (!temp_dir_.CreateUniqueTempDir()) { |
| 137 LOG(ERROR) << "Failed to create unique temporary directory."; | 138 LOG(ERROR) << "Failed to create unique temporary directory."; |
| 138 | 139 |
| 139 // Fallback logic in case we fail to create unique temporary directory. | 140 // Fallback logic in case we fail to create unique temporary directory. |
| 140 FilePath system_tmp_dir; | 141 FilePath system_tmp_dir; |
| 141 bool success = PathService::Get(base::DIR_TEMP, &system_tmp_dir); | 142 bool success = PathService::Get(base::DIR_TEMP, &system_tmp_dir); |
| 142 | 143 |
| 143 // We're severly screwed if we can't get the system temporary | 144 // We're severly screwed if we can't get the system temporary |
| 144 // directory. Die now to avoid writing to the filesystem root | 145 // directory. Die now to avoid writing to the filesystem root |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 160 profile_path_ = temp_dir_.path(); | 161 profile_path_ = temp_dir_.path(); |
| 161 | 162 |
| 162 Init(); | 163 Init(); |
| 163 } | 164 } |
| 164 | 165 |
| 165 TestingProfile::TestingProfile(const FilePath& path) | 166 TestingProfile::TestingProfile(const FilePath& path) |
| 166 : start_time_(Time::Now()), | 167 : start_time_(Time::Now()), |
| 167 testing_prefs_(NULL), | 168 testing_prefs_(NULL), |
| 168 incognito_(false), | 169 incognito_(false), |
| 169 last_session_exited_cleanly_(true), | 170 last_session_exited_cleanly_(true), |
| 171 enable_lazy_service_initialization_(false), | |
| 170 profile_path_(path), | 172 profile_path_(path), |
| 171 profile_dependency_manager_(ProfileDependencyManager::GetInstance()) { | 173 profile_dependency_manager_(ProfileDependencyManager::GetInstance()) { |
| 172 Init(); | 174 Init(); |
| 173 } | 175 } |
| 174 | 176 |
| 177 TestingProfile::TestingProfile(const FilePath& path, | |
| 178 Delegate* delegate) | |
| 179 : start_time_(Time::Now()), | |
| 180 testing_prefs_(NULL), | |
| 181 incognito_(false), | |
| 182 last_session_exited_cleanly_(true), | |
| 183 enable_lazy_service_initialization_(false), | |
| 184 profile_path_(path), | |
| 185 profile_dependency_manager_(ProfileDependencyManager::GetInstance()), | |
| 186 delegate_(delegate) { | |
| 187 if (delegate_) { | |
| 188 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.
| |
| 189 | |
| 190 // Install profile keyed service factory hooks for dummy/test services | |
| 191 DesktopNotificationServiceFactory::GetInstance()->SetTestingFactory( | |
| 192 this, CreateTestDesktopNotificationService); | |
| 193 | |
| 194 MessageLoop::current()->PostTask(FROM_HERE, | |
| 195 base::Bind(&TestingProfile::FinishInit, | |
| 196 base::Unretained(this))); | |
| 197 } else { | |
| 198 Init(); | |
| 199 } | |
| 200 } | |
| 201 | |
| 175 void TestingProfile::Init() { | 202 void TestingProfile::Init() { |
| 176 profile_dependency_manager_->CreateProfileServices(this, true); | 203 profile_dependency_manager_->CreateProfileServices(this, true); |
| 177 | 204 |
| 178 // Install profile keyed service factory hooks for dummy/test services | 205 // Install profile keyed service factory hooks for dummy/test services |
| 179 DesktopNotificationServiceFactory::GetInstance()->SetTestingFactory( | 206 DesktopNotificationServiceFactory::GetInstance()->SetTestingFactory( |
| 180 this, CreateTestDesktopNotificationService); | 207 this, CreateTestDesktopNotificationService); |
| 181 | 208 |
| 182 content::NotificationService::current()->Notify( | 209 content::NotificationService::current()->Notify( |
| 183 chrome::NOTIFICATION_PROFILE_CREATED, | 210 chrome::NOTIFICATION_PROFILE_CREATED, |
| 184 content::Source<Profile>(static_cast<Profile*>(this)), | 211 content::Source<Profile>(static_cast<Profile*>(this)), |
| 185 content::NotificationService::NoDetails()); | 212 content::NotificationService::NoDetails()); |
| 186 } | 213 } |
| 187 | 214 |
| 215 void TestingProfile::FinishInit() { | |
| 216 NotificationService::current()->Notify( | |
| 217 chrome::NOTIFICATION_PROFILE_CREATED, | |
| 218 content::Source<Profile>(static_cast<Profile*>(this)), | |
| 219 NotificationService::NoDetails()); | |
| 220 | |
| 221 if (delegate_) | |
| 222 delegate_->OnProfileCreated(this, true); | |
| 223 } | |
| 224 | |
| 188 TestingProfile::~TestingProfile() { | 225 TestingProfile::~TestingProfile() { |
| 189 content::NotificationService::current()->Notify( | 226 content::NotificationService::current()->Notify( |
| 190 chrome::NOTIFICATION_PROFILE_DESTROYED, | 227 chrome::NOTIFICATION_PROFILE_DESTROYED, |
| 191 content::Source<Profile>(static_cast<Profile*>(this)), | 228 content::Source<Profile>(static_cast<Profile*>(this)), |
| 192 content::NotificationService::NoDetails()); | 229 content::NotificationService::NoDetails()); |
| 193 | 230 |
| 194 profile_dependency_manager_->DestroyProfileServices(this); | 231 profile_dependency_manager_->DestroyProfileServices(this); |
| 195 | 232 |
| 196 if (host_content_settings_map_) | 233 if (host_content_settings_map_) |
| 197 host_content_settings_map_->ShutdownOnUIThread(); | 234 host_content_settings_map_->ShutdownOnUIThread(); |
| (...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 473 if (!extension_special_storage_policy_.get()) | 510 if (!extension_special_storage_policy_.get()) |
| 474 extension_special_storage_policy_ = new ExtensionSpecialStoragePolicy(NULL); | 511 extension_special_storage_policy_ = new ExtensionSpecialStoragePolicy(NULL); |
| 475 return extension_special_storage_policy_.get(); | 512 return extension_special_storage_policy_.get(); |
| 476 } | 513 } |
| 477 | 514 |
| 478 SSLHostState* TestingProfile::GetSSLHostState() { | 515 SSLHostState* TestingProfile::GetSSLHostState() { |
| 479 return NULL; | 516 return NULL; |
| 480 } | 517 } |
| 481 | 518 |
| 482 FaviconService* TestingProfile::GetFaviconService(ServiceAccessType access) { | 519 FaviconService* TestingProfile::GetFaviconService(ServiceAccessType access) { |
| 520 if (enable_lazy_service_initialization_ && !favicon_service_.get()) | |
| 521 CreateFaviconService(); | |
| 483 return favicon_service_.get(); | 522 return favicon_service_.get(); |
| 484 } | 523 } |
| 485 | 524 |
| 486 HistoryService* TestingProfile::GetHistoryService(ServiceAccessType access) { | 525 HistoryService* TestingProfile::GetHistoryService(ServiceAccessType access) { |
| 526 if (enable_lazy_service_initialization_ && !history_service_.get()) | |
| 527 CreateHistoryService(true, false); | |
| 487 return history_service_.get(); | 528 return history_service_.get(); |
| 488 } | 529 } |
| 489 | 530 |
| 490 HistoryService* TestingProfile::GetHistoryServiceWithoutCreating() { | 531 HistoryService* TestingProfile::GetHistoryServiceWithoutCreating() { |
| 491 return history_service_.get(); | 532 return history_service_.get(); |
| 492 } | 533 } |
| 493 | 534 |
| 494 net::CookieMonster* TestingProfile::GetCookieMonster() { | 535 net::CookieMonster* TestingProfile::GetCookieMonster() { |
| 495 if (!GetRequestContext()) | 536 if (!GetRequestContext()) |
| 496 return NULL; | 537 return NULL; |
| 497 return GetRequestContext()->GetURLRequestContext()->cookie_store()-> | 538 return GetRequestContext()->GetURLRequestContext()->cookie_store()-> |
| 498 GetCookieMonster(); | 539 GetCookieMonster(); |
| 499 } | 540 } |
| 500 | 541 |
| 501 AutocompleteClassifier* TestingProfile::GetAutocompleteClassifier() { | 542 AutocompleteClassifier* TestingProfile::GetAutocompleteClassifier() { |
| 502 return autocomplete_classifier_.get(); | 543 return autocomplete_classifier_.get(); |
| 503 } | 544 } |
| 504 | 545 |
| 505 history::ShortcutsBackend* TestingProfile::GetShortcutsBackend() { | 546 history::ShortcutsBackend* TestingProfile::GetShortcutsBackend() { |
| 506 return NULL; | 547 return NULL; |
| 507 } | 548 } |
| 508 | 549 |
| 509 WebDataService* TestingProfile::GetWebDataService(ServiceAccessType access) { | 550 WebDataService* TestingProfile::GetWebDataService(ServiceAccessType access) { |
| 551 if (enable_lazy_service_initialization_ && !web_data_service_.get()) | |
| 552 CreateWebDataService(false); | |
| 510 return web_data_service_.get(); | 553 return web_data_service_.get(); |
| 511 } | 554 } |
| 512 | 555 |
| 513 WebDataService* TestingProfile::GetWebDataServiceWithoutCreating() { | 556 WebDataService* TestingProfile::GetWebDataServiceWithoutCreating() { |
| 514 return web_data_service_.get(); | 557 return web_data_service_.get(); |
| 515 } | 558 } |
| 516 | 559 |
| 517 PasswordStore* TestingProfile::GetPasswordStore(ServiceAccessType access) { | 560 PasswordStore* TestingProfile::GetPasswordStore(ServiceAccessType access) { |
| 518 return NULL; | 561 return NULL; |
| 519 } | 562 } |
| (...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 678 | 721 |
| 679 void TestingProfile::SetID(const std::wstring& id) { | 722 void TestingProfile::SetID(const std::wstring& id) { |
| 680 id_ = id; | 723 id_ = id; |
| 681 } | 724 } |
| 682 | 725 |
| 683 bool TestingProfile::DidLastSessionExitCleanly() { | 726 bool TestingProfile::DidLastSessionExitCleanly() { |
| 684 return last_session_exited_cleanly_; | 727 return last_session_exited_cleanly_; |
| 685 } | 728 } |
| 686 | 729 |
| 687 BookmarkModel* TestingProfile::GetBookmarkModel() { | 730 BookmarkModel* TestingProfile::GetBookmarkModel() { |
| 731 if (enable_lazy_service_initialization_ && !bookmark_bar_model_.get()) | |
| 732 CreateBookmarkModel(true); | |
| 688 return bookmark_bar_model_.get(); | 733 return bookmark_bar_model_.get(); |
| 689 } | 734 } |
| 690 | 735 |
| 691 bool TestingProfile::IsSameProfile(Profile *p) { | 736 bool TestingProfile::IsSameProfile(Profile *p) { |
| 692 return this == p; | 737 return this == p; |
| 693 } | 738 } |
| 694 | 739 |
| 695 base::Time TestingProfile::GetStartTime() const { | 740 base::Time TestingProfile::GetStartTime() const { |
| 696 return start_time_; | 741 return start_time_; |
| 697 } | 742 } |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 809 quota::SpecialStoragePolicy* TestingProfile::GetSpecialStoragePolicy() { | 854 quota::SpecialStoragePolicy* TestingProfile::GetSpecialStoragePolicy() { |
| 810 return GetExtensionSpecialStoragePolicy(); | 855 return GetExtensionSpecialStoragePolicy(); |
| 811 } | 856 } |
| 812 | 857 |
| 813 void TestingProfile::DestroyWebDataService() { | 858 void TestingProfile::DestroyWebDataService() { |
| 814 if (!web_data_service_.get()) | 859 if (!web_data_service_.get()) |
| 815 return; | 860 return; |
| 816 | 861 |
| 817 web_data_service_->Shutdown(); | 862 web_data_service_->Shutdown(); |
| 818 } | 863 } |
| OLD | NEW |