summaryrefslogtreecommitdiffstats
path: root/chrome/test/testing_profile.cc
diff options
context:
space:
mode:
authorsky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-10-27 15:22:54 +0000
committersky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-10-27 15:22:54 +0000
commit809cc4d808f30112929ef9c33183e6cc052d3f88 (patch)
tree54398a78a324c611c7413d386d62aad68c01b17b /chrome/test/testing_profile.cc
parent68d5a677812099c0d85b1c22f9234e8db9ddfc03 (diff)
downloadchromium_src-809cc4d808f30112929ef9c33183e6cc052d3f88.zip
chromium_src-809cc4d808f30112929ef9c33183e6cc052d3f88.tar.gz
chromium_src-809cc4d808f30112929ef9c33183e6cc052d3f88.tar.bz2
Attempt 2 at landing top sites refactor:
Refactors TopSites so that it's hopefully easier to maintain and doesn't suffer the plethora of threading issues that exist with the current version. Here's the breakdown of what was refactored: . TopSitesCache: Contains the most visited urls and thumbnails. . TopSitesBackend: All mutations to topsites data end up calling into the backend on the UI thread. TopSitesBackend processes the method on the DB thread calling through to the TopSitesDatabase. . TopSites: uses two TopSitesCache. One that contains the raw history data, the other contains the processed data (pinned/blacklisted). The processed cache can be accessed on any thread. TopSites waits until history loads to know if it should migrate or use it's own db. I could probably make these execute in parallel, but for now this is how it works. This patch also makes it so the dom ui accesses the thumbnails on the IO thread. BUG=56382 TEST=Make sure all your thumbnails are correctly updated and you don't see problems. Review URL: http://codereview.chromium.org/4051004 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@64072 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/test/testing_profile.cc')
-rw-r--r--chrome/test/testing_profile.cc55
1 files changed, 35 insertions, 20 deletions
diff --git a/chrome/test/testing_profile.cc b/chrome/test/testing_profile.cc
index 829fcc9..546e779 100644
--- a/chrome/test/testing_profile.cc
+++ b/chrome/test/testing_profile.cc
@@ -39,6 +39,7 @@
#include "chrome/common/notification_service.h"
#include "chrome/common/url_constants.h"
#include "chrome/test/testing_pref_service.h"
+#include "chrome/test/ui_test_utils.h"
#include "net/base/cookie_monster.h"
#include "net/url_request/url_request_context.h"
#include "net/url_request/url_request_unittest.h"
@@ -194,13 +195,11 @@ TestingProfile::~TestingProfile() {
NotificationType::PROFILE_DESTROYED,
Source<Profile>(this),
NotificationService::NoDetails());
+ DestroyTopSites();
DestroyHistoryService();
// FaviconService depends on HistoryServce so destroying it later.
DestroyFaviconService();
DestroyWebDataService();
- if (top_sites_.get())
- top_sites_->ClearProfile();
- history::TopSites::DeleteTopSites(top_sites_);
if (extensions_service_.get()) {
extensions_service_->DestroyingProfile();
extensions_service_ = NULL;
@@ -213,11 +212,7 @@ void TestingProfile::CreateFaviconService() {
}
void TestingProfile::CreateHistoryService(bool delete_file, bool no_db) {
- if (history_service_.get())
- history_service_->Cleanup();
-
- history_service_ = NULL;
-
+ DestroyHistoryService();
if (delete_file) {
FilePath path = GetPath();
path = path.Append(chrome::kHistoryFilename);
@@ -227,12 +222,6 @@ void TestingProfile::CreateHistoryService(bool delete_file, bool no_db) {
history_service_->Init(GetPath(), bookmark_bar_model_.get(), no_db);
}
-void TestingProfile::DestroyFaviconService() {
- if (!favicon_service_.get())
- return;
- favicon_service_ = NULL;
-}
-
void TestingProfile::DestroyHistoryService() {
if (!history_service_.get())
return;
@@ -254,6 +243,31 @@ void TestingProfile::DestroyHistoryService() {
MessageLoop::current()->Run();
}
+void TestingProfile::CreateTopSites() {
+ DestroyTopSites();
+ top_sites_ = new history::TopSites(this);
+ FilePath file_name = temp_dir_.path().Append(chrome::kTopSitesFilename);
+ top_sites_->Init(file_name);
+}
+
+void TestingProfile::DestroyTopSites() {
+ if (top_sites_.get()) {
+ top_sites_->Shutdown();
+ top_sites_ = NULL;
+ // TopSites::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 (MessageLoop::current())
+ MessageLoop::current()->RunAllPending();
+ }
+}
+
+void TestingProfile::DestroyFaviconService() {
+ if (!favicon_service_.get())
+ return;
+ favicon_service_ = NULL;
+}
+
void TestingProfile::CreateBookmarkModel(bool delete_file) {
// Nuke the model first, that way we're sure it's done writing to disk.
bookmark_bar_model_.reset(NULL);
@@ -303,6 +317,12 @@ void TestingProfile::BlockUntilBookmarkModelLoaded() {
DCHECK(bookmark_bar_model_->IsLoaded());
}
+void TestingProfile::BlockUntilTopSitesLoaded() {
+ if (!GetHistoryService(Profile::EXPLICIT_ACCESS))
+ GetTopSites()->HistoryLoaded();
+ ui_test_utils::WaitForNotification(NotificationType::TOP_SITES_LOADED);
+}
+
void TestingProfile::CreateTemplateURLFetcher() {
template_url_fetcher_.reset(new TemplateURLFetcher(this));
}
@@ -392,12 +412,7 @@ PrefService* TestingProfile::GetPrefs() {
}
history::TopSites* TestingProfile::GetTopSites() {
- if (!top_sites_.get()) {
- top_sites_ = new history::TopSites(this);
- FilePath file_name = temp_dir_.path().AppendASCII("TopSites.db");
- top_sites_->Init(file_name);
- }
- return top_sites_;
+ return top_sites_.get();
}
URLRequestContextGetter* TestingProfile::GetRequestContext() {