Index: chrome/test/base/testing_profile.cc |
diff --git a/chrome/test/base/testing_profile.cc b/chrome/test/base/testing_profile.cc |
index e3de282a58aaacee7e01e4e97bd84cf1c71171f3..ed4c556130c3fbd37f02d877a633aaf4a2fc55dc 100644 |
--- a/chrome/test/base/testing_profile.cc |
+++ b/chrome/test/base/testing_profile.cc |
@@ -28,6 +28,8 @@ |
#include "chrome/browser/history/history_service.h" |
#include "chrome/browser/history/history_service_factory.h" |
#include "chrome/browser/history/top_sites.h" |
+#include "chrome/browser/history/top_sites_impl.h" |
+#include "chrome/browser/history/top_sites_service_factory.h" |
#include "chrome/browser/history/web_history_service_factory.h" |
#include "chrome/browser/net/pref_proxy_config_tracker.h" |
#include "chrome/browser/net/proxy_service_factory.h" |
@@ -223,9 +225,10 @@ KeyedService* BuildChromeBookmarkClient( |
KeyedService* BuildChromeHistoryClient( |
content::BrowserContext* context) { |
Profile* profile = static_cast<Profile*>(context); |
+ scoped_refptr<history::TopSites> top_sites = |
+ TopSitesServiceFactory::GetForProfile(profile); |
return new ChromeHistoryClient(BookmarkModelFactory::GetForProfile(profile), |
- profile, |
- profile->GetTopSites()); |
+ profile, top_sites.get()); |
} |
void TestProfileErrorCallback(WebDataServiceWrapper::ErrorType error_type, |
@@ -453,6 +456,8 @@ void TestingProfile::Init() { |
this, CreateTestDesktopNotificationService); |
#endif |
+ CreateTopSitesService(); |
+ |
#if defined(ENABLE_SUPERVISED_USERS) |
if (!IsOffTheRecord()) { |
SupervisedUserSettingsService* settings_service = |
@@ -498,8 +503,6 @@ TestingProfile::~TestingProfile() { |
if (host_content_settings_map_.get()) |
host_content_settings_map_->ShutdownOnUIThread(); |
- DestroyTopSites(); |
- |
if (pref_proxy_config_tracker_.get()) |
pref_proxy_config_tracker_->DetachFromPrefService(); |
// Failing a post == leaks == heapcheck failure. Make that an immediate test |
@@ -569,29 +572,6 @@ void TestingProfile::DestroyHistoryService() { |
base::MessageLoop::current()->Run(); |
} |
-void TestingProfile::CreateTopSites() { |
- DestroyTopSites(); |
- top_sites_ = history::TopSites::Create( |
- this, GetPath().Append(chrome::kTopSitesFilename)); |
-} |
- |
-void TestingProfile::SetTopSites(history::TopSites* top_sites) { |
- DestroyTopSites(); |
- top_sites_ = top_sites; |
-} |
- |
-void TestingProfile::DestroyTopSites() { |
- if (top_sites_.get()) { |
- top_sites_->Shutdown(); |
- top_sites_ = NULL; |
- // TopSitesImpl::Shutdown schedules some tasks (from TopSitesBackend) that |
- // need to be run to properly shutdown. Run all pending tasks now. This is |
- // normally handled by browser_process shutdown. |
- if (base::MessageLoop::current()) |
- base::MessageLoop::current()->RunUntilIdle(); |
- } |
-} |
- |
void TestingProfile::CreateBookmarkModel(bool delete_file) { |
if (delete_file) { |
base::FilePath path = GetPath().Append(bookmarks::kBookmarksFileName); |
@@ -606,6 +586,17 @@ void TestingProfile::CreateBookmarkModel(bool delete_file) { |
this, BuildBookmarkModel)); |
} |
+void TestingProfile::CreateTopSitesService(history::TopSites* top_sites) { |
+ TopSitesServiceFactory::GetInstance()->SetTestingFactory( |
+ this, |
+ &TopSitesServiceFactory::CreateCustomTopSitesServiceFactory(&top_sites)); |
sdefresne
2014/12/29 09:48:14
Please move this testing factory function (TopSite
Jitu( very slow this week)
2014/12/30 10:09:03
Done.
|
+} |
+ |
+void TestingProfile::CreateTopSitesService() { |
+ TopSitesServiceFactory::GetInstance()->SetTestingFactory( |
+ this, &TopSitesServiceFactory::BuildProfileForTesting(this)); |
sdefresne
2014/12/29 09:48:14
Please move this testing factory function (TopSite
Jitu( very slow this week)
2014/12/30 10:09:03
Done.
|
+} |
+ |
void TestingProfile::CreateWebDataService() { |
WebDataServiceFactory::GetInstance()->SetTestingFactory( |
this, BuildWebDataService); |
@@ -634,9 +625,11 @@ void TestingProfile::BlockUntilTopSitesLoaded() { |
scoped_refptr<content::MessageLoopRunner> runner = |
new content::MessageLoopRunner; |
WaitTopSitesLoadedObserver observer(runner.get()); |
- top_sites_->AddObserver(&observer); |
+ scoped_refptr<history::TopSites> top_site = |
+ TopSitesServiceFactory::GetForProfile(this); |
+ top_site->AddObserver(&observer); |
runner->Run(); |
- top_sites_->RemoveObserver(&observer); |
+ top_site->RemoveObserver(&observer); |
} |
void TestingProfile::SetGuestSession(bool guest) { |
@@ -794,14 +787,6 @@ PrefService* TestingProfile::GetPrefs() { |
return prefs_.get(); |
} |
-history::TopSites* TestingProfile::GetTopSites() { |
- return top_sites_.get(); |
-} |
- |
-history::TopSites* TestingProfile::GetTopSitesWithoutCreating() { |
- return top_sites_.get(); |
-} |
- |
DownloadManagerDelegate* TestingProfile::GetDownloadManagerDelegate() { |
return NULL; |
} |