summaryrefslogtreecommitdiffstats
path: root/chrome/browser
diff options
context:
space:
mode:
authorbrettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-05-19 16:03:42 +0000
committerbrettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-05-19 16:03:42 +0000
commit523623c62f291467769fbb3c0e7fd5c1709b4da1 (patch)
treef7ffe236605e0d56d89bd7c6c5e8785662be166d /chrome/browser
parentd0cc0f3d2c1216d2c2168690f64dc448d3ac9ca8 (diff)
downloadchromium_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')
-rw-r--r--chrome/browser/dom_ui/dom_ui_thumbnail_source.cc23
-rw-r--r--chrome/browser/dom_ui/most_visited_handler.cc33
-rw-r--r--chrome/browser/dom_ui/most_visited_handler.h4
-rw-r--r--chrome/browser/history/top_sites.cc19
-rw-r--r--chrome/browser/history/top_sites.h14
-rw-r--r--chrome/browser/profile.cc13
-rw-r--r--chrome/browser/profile.h11
-rw-r--r--chrome/browser/tab_contents/tab_contents.cc6
8 files changed, 101 insertions, 22 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();
diff --git a/chrome/browser/history/top_sites.cc b/chrome/browser/history/top_sites.cc
index 90399b1..fd23865 100644
--- a/chrome/browser/history/top_sites.cc
+++ b/chrome/browser/history/top_sites.cc
@@ -15,6 +15,8 @@ namespace history {
// How many top sites to store in the cache.
static const int kTopSitesNumber = 20;
static const int kDaysOfHistory = 90;
+static const int64 kUpdateIntervalSecs = 15; // TODO(Nik): come up
+ // with an algorithm for timing.
TopSites::TopSites(Profile* profile) : profile_(profile),
mock_history_service_(NULL) {
@@ -23,9 +25,12 @@ TopSites::TopSites(Profile* profile) : profile_(profile),
TopSites::~TopSites() {
}
-bool TopSites::Init() {
+void TopSites::Init() {
// TODO(brettw) read the database here.
- return true;
+
+ // Start the one-shot timer.
+ timer_.Start(base::TimeDelta::FromSeconds(kUpdateIntervalSecs), this,
+ &TopSites::StartQueryForMostVisited);
}
bool TopSites::SetPageThumbnail(const GURL& url,
@@ -70,6 +75,16 @@ MostVisitedURLList TopSites::GetMostVisitedURLs() {
return top_sites_;
}
+bool TopSites::GetPageThumbnail(const GURL& url, RefCountedBytes** data) const {
+ std::map<GURL, Images>::const_iterator found = top_images_.find(url);
+ if (found == top_images_.end())
+ return false; // No thumbnail for this URL.
+
+ Images image = found->second;
+ *data = image.thumbnail.get();
+ return true;
+}
+
void TopSites::StoreMostVisited(MostVisitedURLList* most_visited) {
lock_.AssertAcquired();
// TODO(brettw) filter for blacklist!
diff --git a/chrome/browser/history/top_sites.h b/chrome/browser/history/top_sites.h
index 6a85ef6..ff98b7a 100644
--- a/chrome/browser/history/top_sites.h
+++ b/chrome/browser/history/top_sites.h
@@ -12,6 +12,7 @@
#include "base/basictypes.h"
#include "base/lock.h"
+#include "base/timer.h"
#include "base/ref_counted.h"
#include "base/ref_counted_memory.h"
#include "chrome/browser/cancelable_request.h"
@@ -55,8 +56,8 @@ class TopSites : public base::RefCountedThreadSafe<TopSites> {
virtual ~MockHistoryService() {}
};
- // Initializes this component, returning true on success.
- bool Init();
+ // Initializes TopSites.
+ void Init();
// Sets the given thumbnail for the given URL. Returns true if the thumbnail
// was updated. False means either the URL wasn't known to us, or we felt
@@ -65,10 +66,12 @@ class TopSites : public base::RefCountedThreadSafe<TopSites> {
const SkBitmap& thumbnail,
const ThumbnailScore& score);
+ // Returns a list of most visited URLs or an empty list if it's not
+ // cached yet.
MostVisitedURLList GetMostVisitedURLs();
- // TODO(brettw): write this.
- // bool GetPageThumbnail(const GURL& url, RefCountedBytes** data) const;
+ // Get a thumbnail for a given page. Returns true iff we have the thumbnail.
+ bool GetPageThumbnail(const GURL& url, RefCountedBytes** data) const;
private:
friend class base::RefCountedThreadSafe<TopSites>;
@@ -152,6 +155,9 @@ class TopSites : public base::RefCountedThreadSafe<TopSites> {
// maps the redirects to the index into top_sites_ that contains it.
std::map<GURL, size_t> canonical_urls_;
+ // Timer for updating TopSites data.
+ base::OneShotTimer<TopSites> timer_;
+
// TODO(brettw): use the blacklist.
// std::set<GURL> blacklist_;
diff --git a/chrome/browser/profile.cc b/chrome/browser/profile.cc
index 652cc02..c8a1559 100644
--- a/chrome/browser/profile.cc
+++ b/chrome/browser/profile.cc
@@ -37,6 +37,7 @@
#include "chrome/browser/spellcheck_host.h"
#include "chrome/browser/transport_security_persister.h"
#include "chrome/browser/history/history.h"
+#include "chrome/browser/history/top_sites.h"
#include "chrome/browser/host_content_settings_map.h"
#include "chrome/browser/host_zoom_map.h"
#include "chrome/browser/in_process_webkit/webkit_context.h"
@@ -548,6 +549,10 @@ class OffTheRecordProfileImpl : public Profile,
return NULL;
}
+ virtual history::TopSites* GetTopSites() {
+ return NULL;
+ }
+
virtual void MarkAsCleanShutdown() {
}
@@ -1384,6 +1389,14 @@ ThumbnailStore* ProfileImpl::GetThumbnailStore() {
return thumbnail_store_.get();
}
+history::TopSites* ProfileImpl::GetTopSites() {
+ if (!top_sites_.get()) {
+ top_sites_ = new history::TopSites(this);
+ top_sites_->Init();
+ }
+ return top_sites_;
+}
+
void ProfileImpl::ResetTabRestoreService() {
tab_restore_service_ = NULL;
}
diff --git a/chrome/browser/profile.h b/chrome/browser/profile.h
index 9871d77..118608c 100644
--- a/chrome/browser/profile.h
+++ b/chrome/browser/profile.h
@@ -25,6 +25,10 @@ namespace chrome_common_net {
class NetworkChangeNotifierThread;
}
+namespace history {
+class TopSites;
+}
+
namespace net {
class TransportSecurityState;
class SSLConfigService;
@@ -155,6 +159,10 @@ class Profile {
// Returns a pointer to the DatabaseTracker instance for this profile.
virtual webkit_database::DatabaseTracker* GetDatabaseTracker() = 0;
+ // Returns a pointer to the TopSites (thumbnail manager) instance
+ // for this profile.
+ virtual history::TopSites* GetTopSites() = 0;
+
// Retrieves a pointer to the VisitedLinkMaster associated with this
// profile. The VisitedLinkMaster is lazily created the first time
// that this method is called.
@@ -469,6 +477,7 @@ class ProfileImpl : public Profile,
virtual void DestroyOffTheRecordProfile();
virtual Profile* GetOriginalProfile();
virtual webkit_database::DatabaseTracker* GetDatabaseTracker();
+ virtual history::TopSites* GetTopSites();
virtual VisitedLinkMaster* GetVisitedLinkMaster();
virtual UserScriptMaster* GetUserScriptMaster();
virtual SSLHostState* GetSSLHostState();
@@ -652,6 +661,8 @@ class ProfileImpl : public Profile,
// Should be used only on the file thread.
scoped_refptr<webkit_database::DatabaseTracker> db_tracker_;
+ scoped_refptr<history::TopSites> top_sites_; // For history and thumbnails.
+
#if defined(OS_CHROMEOS)
chromeos::Preferences chromeos_preferences_;
#endif
diff --git a/chrome/browser/tab_contents/tab_contents.cc b/chrome/browser/tab_contents/tab_contents.cc
index 1f7dd3d..9d1a558 100644
--- a/chrome/browser/tab_contents/tab_contents.cc
+++ b/chrome/browser/tab_contents/tab_contents.cc
@@ -36,6 +36,7 @@
#include "chrome/browser/download/download_request_manager.h"
#include "chrome/browser/external_protocol_handler.h"
#include "chrome/browser/extensions/extensions_service.h"
+#include "chrome/browser/history/top_sites.h"
#include "chrome/browser/favicon_service.h"
#include "chrome/browser/find_bar_state.h"
#include "chrome/browser/google_util.h"
@@ -2407,10 +2408,9 @@ void TabContents::UpdateThumbnail(const GURL& url,
const SkBitmap& bitmap,
const ThumbnailScore& score) {
// Tell History about this thumbnail
- if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kThumbnailStore)) {
+ if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kTopSites)) {
if (!profile()->IsOffTheRecord())
- profile()->GetThumbnailStore()->SetPageThumbnail(url, bitmap,
- score, true);
+ profile()->GetTopSites()->SetPageThumbnail(url, bitmap, score);
} else {
HistoryService* hs;
if (!profile()->IsOffTheRecord() &&