summaryrefslogtreecommitdiffstats
path: root/chrome/browser/history/top_sites.h
diff options
context:
space:
mode:
authorbrettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-05-13 22:17:17 +0000
committerbrettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-05-13 22:17:17 +0000
commitcd436b6d700e08e4801f8f5f8396b4e3d068e8e3 (patch)
tree1ac2688c40ed14529751f7b3daf6c78c6cfbacb0 /chrome/browser/history/top_sites.h
parentb88ab037fc20ab5dfe0f35d71e78acc8499979a5 (diff)
downloadchromium_src-cd436b6d700e08e4801f8f5f8396b4e3d068e8e3.zip
chromium_src-cd436b6d700e08e4801f8f5f8396b4e3d068e8e3.tar.gz
chromium_src-cd436b6d700e08e4801f8f5f8396b4e3d068e8e3.tar.bz2
Add TopSites::GetMostVisitedURLs and unittest for it using MockHistoryService.
BUG=none TEST=TopSitesTest Original review=http://codereview.chromium.org/2057008 Patch by Nik Shkrob git-svn-id: svn://svn.chromium.org/chrome/trunk/src@47206 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/history/top_sites.h')
-rw-r--r--chrome/browser/history/top_sites.h55
1 files changed, 47 insertions, 8 deletions
diff --git a/chrome/browser/history/top_sites.h b/chrome/browser/history/top_sites.h
index cce4606..f09fcf8 100644
--- a/chrome/browser/history/top_sites.h
+++ b/chrome/browser/history/top_sites.h
@@ -14,18 +14,23 @@
#include "base/lock.h"
#include "base/ref_counted.h"
#include "base/ref_counted_memory.h"
+#include "chrome/browser/cancelable_request.h"
#include "chrome/browser/history/history_types.h"
+#include "chrome/browser/history/history.h"
+#include "chrome/browser/history/page_usage_data.h"
#include "chrome/common/thumbnail_score.h"
#include "googleurl/src/gurl.h"
class SkBitmap;
-struct ThumbnailScore;
+class Profile;
namespace history {
class TopSitesBackend;
class TopSitesTest;
+typedef std::vector<MostVisitedURL> MostVisitedURLList;
+
// Stores the data for the top "most visited" sites. This includes a cache of
// the most visited data from history, as well as the corresponding thumbnails
// of those sites.
@@ -38,8 +43,18 @@ class TopSitesTest;
// the UI thread is busy.
class TopSites : public base::RefCountedThreadSafe<TopSites> {
public:
- TopSites();
- ~TopSites();
+ explicit TopSites(Profile* profile);
+
+ class MockHistoryService {
+ // A mockup of a HistoryService used for testing TopSites.
+ public:
+ virtual HistoryService::Handle QuerySegmentUsageSince(
+ CancelableRequestConsumerBase* consumer,
+ base::Time from_time,
+ int max_result_count,
+ HistoryService::SegmentQueryCallback* callback) = 0;
+ virtual ~MockHistoryService() {}
+ };
// Initializes this component, returning true on success.
bool Init();
@@ -51,11 +66,17 @@ class TopSites : public base::RefCountedThreadSafe<TopSites> {
const SkBitmap& thumbnail,
const ThumbnailScore& score);
+ MostVisitedURLList GetMostVisitedURLs();
+
// TODO(brettw): write this.
// bool GetPageThumbnail(const GURL& url, RefCountedBytes** data) const;
private:
+ friend class base::RefCountedThreadSafe<TopSites>;
friend class TopSitesTest;
+ friend class TopSitesTest_GetMostVisited_Test;
+
+ ~TopSites();
struct Images {
scoped_refptr<RefCountedBytes> thumbnail;
@@ -65,11 +86,22 @@ class TopSites : public base::RefCountedThreadSafe<TopSites> {
// scoped_refptr<RefCountedBytes> favicon;
};
+ void StartQueryForMostVisited();
+
+ // Handler for the query response.
+ void OnTopSitesAvailable(CancelableRequestProvider::Handle handle,
+ std::vector<PageUsageData*>* data);
+
+ // Converts from PageUsageData to MostVisitedURL. redirects is a
+ // list of redirects for this URL. Empty list means no redirects.
+ static MostVisitedURL MakeMostVisitedURL(const PageUsageData& page_data,
+ const RedirectList& redirects);
+
// Saves the set of the top URLs visited by this user. The 0th item is the
// most popular.
//
// DANGER! This will clear all data from the input argument.
- void StoreMostVisited(std::vector<MostVisitedURL>* most_visited);
+ void StoreMostVisited(MostVisitedURLList* most_visited);
// Saves the given set of redirects. The redirects are in order of the
// given vector, so [0] -> [1] -> [2].
@@ -97,17 +129,25 @@ class TopSites : public base::RefCountedThreadSafe<TopSites> {
//
// URLs appearing in both old and new lists but having different indices will
// have their index into "new" be put into |moved_urls|.
- static void DiffMostVisited(const std::vector<MostVisitedURL>& old_list,
- const std::vector<MostVisitedURL>& new_list,
+ static void DiffMostVisited(const MostVisitedURLList& old_list,
+ const MostVisitedURLList& new_list,
std::vector<size_t>* added_urls,
std::vector<size_t>* deleted_urls,
std::vector<size_t>* moved_urls);
+ // For testing with a HistoryService mock.
+ void SetMockHistoryService(MockHistoryService* mhs);
+
+ Profile* profile_;
+ // A mockup to use for testing. If NULL, use the real HistoryService
+ // from the profile_. See SetMockHistoryService.
+ MockHistoryService* mock_history_service_;
+ CancelableRequestConsumerTSimple<PageUsageData*> cancelable_consumer_;
mutable Lock lock_;
// The cached version of the top sites. The 0th item in this vector is the
// #1 site.
- std::vector<MostVisitedURL> top_sites_;
+ MostVisitedURLList top_sites_;
// The images corresponding to the top_sites. This is indexed by the URL of
// the top site, so this doesn't have to be shuffled around when the ordering
@@ -127,4 +167,3 @@ class TopSites : public base::RefCountedThreadSafe<TopSites> {
} // namespace history
#endif // CHROME_BROWSER_HISTORY_TOP_SITES_H_
-