Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3912)

Unified Diff: chrome/browser/history/top_sites.cc

Issue 5088001: Add pyauto hook for getting and manipulating the data underneath the NTP. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/chrome/test/functional
Patch Set: add forgotten py files Created 10 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/history/top_sites.cc
diff --git a/chrome/browser/history/top_sites.cc b/chrome/browser/history/top_sites.cc
index 8bdfe340f55137be2f2306364313fcb213dc564e..ebc13aee624378bc53887338d027ef16d4fb298d 100644
--- a/chrome/browser/history/top_sites.cc
+++ b/chrome/browser/history/top_sites.cc
@@ -136,7 +136,8 @@ TopSites::TopSites(Profile* profile)
pinned_urls_(NULL),
history_state_(HISTORY_LOADING),
top_sites_state_(TOP_SITES_LOADING),
- loaded_(false) {
+ loaded_(false),
+ handle_to_wait_for_(NULL) {
if (!profile_)
return;
@@ -440,6 +441,15 @@ void TopSites::DiffMostVisited(const MostVisitedURLList& old_list,
}
}
+void TopSites::RefreshAndCallback(Callback0::Type* callback) {
sky 2010/11/16 21:43:08 Instead of exposing this method, maintaining handl
kkania 2010/11/17 01:11:34 Done.
+ if (refresh_callback_.get()) {
+ DLOG(ERROR) << "Waiting for refresh before previous refresh finished";
+ return;
+ }
+ refresh_callback_.reset(callback);
+ handle_to_wait_for_ = StartQueryForMostVisited();
+}
+
TopSites::~TopSites() {
}
@@ -533,19 +543,25 @@ void TopSites::AddTemporaryThumbnail(const GURL& url,
temp_images_.push_back(image);
}
-void TopSites::StartQueryForMostVisited() {
+CancelableRequestProvider::Handle TopSites::StartQueryForMostVisited() {
if (!profile_)
- return;
+ return NULL;
+ CancelableRequestProvider::Handle request_handle = NULL;
HistoryService* hs = profile_->GetHistoryService(Profile::EXPLICIT_ACCESS);
// |hs| may be null during unit tests.
if (hs) {
- hs->QueryMostVisitedURLs(
+ request_handle = hs->QueryMostVisitedURLs(
num_results_to_request_from_history(),
kDaysOfHistory,
&cancelable_consumer_,
NewCallback(this, &TopSites::OnTopSitesAvailableFromHistory));
}
+ return request_handle;
+}
+
+void TopSites::TimerFired() {
+ StartQueryForMostVisited();
sky 2010/11/16 21:43:08 Why do we need TimerFired?
kkania 2010/11/17 01:11:34 OneShotTimer expects a void method.
}
// static
@@ -844,7 +860,7 @@ void TopSites::RestartQueryForTopSitesTimer(base::TimeDelta delta) {
timer_start_time_ = base::TimeTicks::Now();
timer_.Stop();
- timer_.Start(delta, this, &TopSites::StartQueryForMostVisited);
+ timer_.Start(delta, this, &TopSites::TimerFired);
}
void TopSites::OnHistoryMigrationWrittenToDisk(TopSitesBackend::Handle handle) {
@@ -902,6 +918,26 @@ void TopSites::OnTopSitesAvailableFromHistory(
CancelableRequestProvider::Handle handle,
MostVisitedURLList pages) {
SetTopSites(pages);
+
+ // For testing only. Invoke the testing callback if this is the handle to the
+ // request that is being waited upon.
+ if (handle == handle_to_wait_for_) {
+ handle_to_wait_for_ = NULL;
+ // Invoke the callback after this empty request goes through the backend, to
+ // ensure that the database is updated.
+ backend_->DoEmptyRequest(
sky 2010/11/16 21:43:08 Why does this need to wait until the backend has b
kkania 2010/11/17 01:11:34 After thinking about it again, I think this is not
+ &cancelable_consumer_,
+ NewCallback(this, &TopSites::InvokeRefreshCallback));
+ }
+}
+
+void TopSites::InvokeRefreshCallback(CancelableRequestProvider::Handle handle) {
+ if (refresh_callback_.get()) {
+ refresh_callback_->Run();
+ refresh_callback_.reset();
+ } else {
+ LOG(DFATAL) << "refresh callback was not set";
+ }
}
} // namespace history

Powered by Google App Engine
This is Rietveld 408576698