summaryrefslogtreecommitdiffstats
path: root/chrome/browser/dom_ui
diff options
context:
space:
mode:
authornshkrob@chromium.org <nshkrob@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-06-28 18:12:05 +0000
committernshkrob@chromium.org <nshkrob@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-06-28 18:12:05 +0000
commite7e5cfb5f44adb69cb4bd55eb1436d0ce353b474 (patch)
tree678dad8d57a84c9c6462aeb848f135fea0c8f42e /chrome/browser/dom_ui
parentaef042746af7a3a9a9967195c24cb7a9c755a0e8 (diff)
downloadchromium_src-e7e5cfb5f44adb69cb4bd55eb1436d0ce353b474.zip
chromium_src-e7e5cfb5f44adb69cb4bd55eb1436d0ce353b474.tar.gz
chromium_src-e7e5cfb5f44adb69cb4bd55eb1436d0ce353b474.tar.bz2
Fix the race condition on TopSites initialization.
Change TopSites::GetMostVisitedURLs to take a callback. This allows TopSites to wait for the results list from the TopSitesDatabase. BUG=none TEST=TopSitesTest Review URL: http://codereview.chromium.org/2811028 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@51002 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/dom_ui')
-rw-r--r--chrome/browser/dom_ui/most_visited_handler.cc36
-rw-r--r--chrome/browser/dom_ui/most_visited_handler.h7
2 files changed, 30 insertions, 13 deletions
diff --git a/chrome/browser/dom_ui/most_visited_handler.cc b/chrome/browser/dom_ui/most_visited_handler.cc
index 87fd109..c7d38cf 100644
--- a/chrome/browser/dom_ui/most_visited_handler.cc
+++ b/chrome/browser/dom_ui/most_visited_handler.cc
@@ -117,12 +117,7 @@ void MostVisitedHandler::RegisterMessages() {
void MostVisitedHandler::HandleGetMostVisited(const Value* value) {
if (!got_first_most_visited_request_) {
// If our intial data is already here, return it.
- if (pages_value_.get()) {
- FundamentalValue first_run(IsFirstRun());
- dom_ui_->CallJavascriptFunction(L"mostVisitedPages",
- *(pages_value_.get()), first_run);
- pages_value_.reset();
- }
+ SendPagesValue();
got_first_most_visited_request_ = true;
} else {
StartQueryForMostVisited();
@@ -151,12 +146,22 @@ void MostVisitedHandler::SetPagesValue(const
}
}
+void MostVisitedHandler::SendPagesValue() {
+ if (pages_value_.get()) {
+ FundamentalValue first_run(IsFirstRun());
+ dom_ui_->CallJavascriptFunction(L"mostVisitedPages",
+ *(pages_value_.get()), first_run);
+ pages_value_.reset();
+ }
+}
+
void MostVisitedHandler::StartQueryForMostVisited() {
if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kTopSites)) {
// Use TopSites.
- history::MostVisitedURLList top_urls =
- dom_ui_->GetProfile()->GetTopSites()->GetMostVisitedURLs();
- SetPagesValue(top_urls);
+ history::TopSites* ts = dom_ui_->GetProfile()->GetTopSites();
+ ts->GetMostVisitedURLs(
+ &topsites_consumer_,
+ NewCallback(this, &MostVisitedHandler::OnMostVisitedURLsAvailable));
return;
}
@@ -416,10 +421,15 @@ void MostVisitedHandler::OnSegmentUsageAvailable(
}
if (got_first_most_visited_request_) {
- FundamentalValue first_run(IsFirstRun());
- dom_ui_->CallJavascriptFunction(L"mostVisitedPages", *(pages_value_.get()),
- first_run);
- pages_value_.reset();
+ SendPagesValue();
+ }
+}
+
+void MostVisitedHandler::OnMostVisitedURLsAvailable(
+ const history::MostVisitedURLList& data) {
+ SetPagesValue(data);
+ if (got_first_most_visited_request_) {
+ SendPagesValue();
}
}
diff --git a/chrome/browser/dom_ui/most_visited_handler.h b/chrome/browser/dom_ui/most_visited_handler.h
index a44b5a6..1ace9fc 100644
--- a/chrome/browser/dom_ui/most_visited_handler.h
+++ b/chrome/browser/dom_ui/most_visited_handler.h
@@ -78,6 +78,9 @@ class MostVisitedHandler : public DOMMessageHandler,
void OnSegmentUsageAvailable(CancelableRequestProvider::Handle handle,
std::vector<PageUsageData*>* data);
+ // Callback for TopSites.
+ void OnMostVisitedURLsAvailable(const history::MostVisitedURLList& data);
+
// Puts the passed URL in the blacklist (so it does not show as a thumbnail).
void BlacklistURL(const GURL& url);
@@ -95,6 +98,9 @@ class MostVisitedHandler : public DOMMessageHandler,
// Sets pages_value_ from MostVisitedURLs.
void SetPagesValue(const history::MostVisitedURLList& urls);
+ // Sends pages_value_ to the javascript side to and resets page_value_.
+ void SendPagesValue();
+
// Returns true if we should treat this as the first run of the new tab page.
bool IsFirstRun();
@@ -104,6 +110,7 @@ class MostVisitedHandler : public DOMMessageHandler,
// Our consumer for the history service.
CancelableRequestConsumerTSimple<PageUsageData*> cancelable_consumer_;
+ CancelableRequestConsumer topsites_consumer_;
// The most visited URLs, in priority order.
// Only used for matching up clicks on the page to which most visited entry