| 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) {
|
| + 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();
|
| }
|
|
|
| // 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(
|
| + &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
|
|
|