diff options
author | brettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-05-19 16:03:42 +0000 |
---|---|---|
committer | brettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-05-19 16:03:42 +0000 |
commit | 523623c62f291467769fbb3c0e7fd5c1709b4da1 (patch) | |
tree | f7ffe236605e0d56d89bd7c6c5e8785662be166d /chrome/browser/dom_ui | |
parent | d0cc0f3d2c1216d2c2168690f64dc448d3ac9ca8 (diff) | |
download | chromium_src-523623c62f291467769fbb3c0e7fd5c1709b4da1.zip chromium_src-523623c62f291467769fbb3c0e7fd5c1709b4da1.tar.gz chromium_src-523623c62f291467769fbb3c0e7fd5c1709b4da1.tar.bz2 |
Add command line flag --top-sites to replace the thumbnail store flag.
Use the flag for querying for thumbnails.
Add timer to update TopSites (every second for now).
BUG=None
TEST='chrome --top-sites'
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@47671 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/dom_ui')
-rw-r--r-- | chrome/browser/dom_ui/dom_ui_thumbnail_source.cc | 23 | ||||
-rw-r--r-- | chrome/browser/dom_ui/most_visited_handler.cc | 33 | ||||
-rw-r--r-- | chrome/browser/dom_ui/most_visited_handler.h | 4 |
3 files changed, 47 insertions, 13 deletions
diff --git a/chrome/browser/dom_ui/dom_ui_thumbnail_source.cc b/chrome/browser/dom_ui/dom_ui_thumbnail_source.cc index e907586..3d3308d 100644 --- a/chrome/browser/dom_ui/dom_ui_thumbnail_source.cc +++ b/chrome/browser/dom_ui/dom_ui_thumbnail_source.cc @@ -8,6 +8,7 @@ #include "base/callback.h" #include "base/command_line.h" #include "chrome/browser/profile.h" +#include "chrome/browser/history/top_sites.h" #include "chrome/browser/thumbnail_store.h" #include "chrome/common/chrome_switches.h" #include "chrome/common/notification_service.h" @@ -25,22 +26,17 @@ DOMUIThumbnailSource::DOMUIThumbnailSource(Profile* profile) void DOMUIThumbnailSource::StartDataRequest(const std::string& path, bool is_off_the_record, int request_id) { - if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kThumbnailStore)) { - scoped_refptr<ThumbnailStore> store_ = profile_->GetThumbnailStore(); - - if (!store_->IsReady()) { - // Register to be notified when the ThumbnailStore is ready. - if (registrar_.IsEmpty()) { - registrar_.Add(this, NotificationType::THUMBNAIL_STORE_READY, - Source<ThumbnailStore>(store_.get())); - } - // Insert into pending_requests. - pending_requests_.push_back(std::make_pair(path, request_id)); + if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kTopSites)) { + scoped_refptr<history::TopSites> top_sites = profile_->GetTopSites(); + RefCountedBytes* data = NULL; + if (top_sites->GetPageThumbnail(GURL(path), &data)) { + // We have the thumbnail. + SendResponse(request_id, data); } else { - DoDataRequest(path, request_id); + SendResponse(request_id, NULL); } return; - } // end --thumbnail-store switch + } // end --top-sites switch HistoryService* hs = profile_->GetHistoryService(Profile::EXPLICIT_ACCESS); if (hs) { @@ -56,6 +52,7 @@ void DOMUIThumbnailSource::StartDataRequest(const std::string& path, } } +// TODO(Nik): remove. ThumbnailStore is to be replaced with TopSites. void DOMUIThumbnailSource::DoDataRequest(const std::string& path, int request_id) { RefCountedBytes* data = NULL; diff --git a/chrome/browser/dom_ui/most_visited_handler.cc b/chrome/browser/dom_ui/most_visited_handler.cc index cc6ed7f..87fd109 100644 --- a/chrome/browser/dom_ui/most_visited_handler.cc +++ b/chrome/browser/dom_ui/most_visited_handler.cc @@ -8,6 +8,7 @@ #include "app/l10n_util.h" #include "base/callback.h" +#include "base/command_line.h" #include "base/md5.h" #include "base/singleton.h" #include "base/utf_string_conversions.h" @@ -20,9 +21,11 @@ #include "chrome/browser/dom_ui/new_tab_ui.h" #include "chrome/browser/history/page_usage_data.h" #include "chrome/browser/history/history.h" +#include "chrome/browser/history/top_sites.h" #include "chrome/browser/metrics/user_metrics.h" #include "chrome/browser/pref_service.h" #include "chrome/browser/profile.h" +#include "chrome/common/chrome_switches.h" #include "chrome/common/notification_type.h" #include "chrome/common/notification_source.h" #include "chrome/common/pref_names.h" @@ -126,7 +129,37 @@ void MostVisitedHandler::HandleGetMostVisited(const Value* value) { } } +// Set a DictionaryValue |dict| from a MostVisitedURL. +void SetDictionaryValue(const history::MostVisitedURL& url, + DictionaryValue& dict) { + NewTabUI::SetURLTitleAndDirection(&dict, url.title, url.url); + dict.SetString(L"url", url.url.spec()); + dict.SetString(L"faviconUrl", url.favicon_url.spec()); + // TODO(Nik): Need thumbnailUrl? + // TODO(Nik): Add pinned and blacklisted URLs. + dict.SetBoolean(L"pinned", false); +} + +void MostVisitedHandler::SetPagesValue(const + history::MostVisitedURLList& urls) { + pages_value_.reset(new ListValue); + for (size_t i = 0; i < urls.size(); i++) { + // Owned by pages_value_. + DictionaryValue* value = new DictionaryValue; + SetDictionaryValue(urls[i], *value); + pages_value_->Append(value); + } +} + void MostVisitedHandler::StartQueryForMostVisited() { + if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kTopSites)) { + // Use TopSites. + history::MostVisitedURLList top_urls = + dom_ui_->GetProfile()->GetTopSites()->GetMostVisitedURLs(); + SetPagesValue(top_urls); + return; + } + const int page_count = kMostVisitedPages; // Let's query for the number of items we want plus the blacklist size as // we'll be filtering-out the returned list with the blacklist URLs. diff --git a/chrome/browser/dom_ui/most_visited_handler.h b/chrome/browser/dom_ui/most_visited_handler.h index 9245cd9..a44b5a6 100644 --- a/chrome/browser/dom_ui/most_visited_handler.h +++ b/chrome/browser/dom_ui/most_visited_handler.h @@ -10,6 +10,7 @@ #include "chrome/browser/cancelable_request.h" #include "chrome/browser/dom_ui/dom_ui.h" +#include "chrome/browser/history/history_types.h" #include "chrome/common/notification_observer.h" #include "chrome/common/notification_registrar.h" #include "googleurl/src/gurl.h" @@ -91,6 +92,9 @@ class MostVisitedHandler : public DOMMessageHandler, void AddPinnedURL(const MostVisitedPage& page, int index); void RemovePinnedURL(const GURL& url); + // Sets pages_value_ from MostVisitedURLs. + void SetPagesValue(const history::MostVisitedURLList& urls); + // Returns true if we should treat this as the first run of the new tab page. bool IsFirstRun(); |