OLD | NEW |
---|---|
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CHROME_BROWSER_HISTORY_TOP_SITES_IMPL_H_ | 5 #ifndef CHROME_BROWSER_HISTORY_TOP_SITES_IMPL_H_ |
6 #define CHROME_BROWSER_HISTORY_TOP_SITES_IMPL_H_ | 6 #define CHROME_BROWSER_HISTORY_TOP_SITES_IMPL_H_ |
7 | 7 |
8 #include <list> | 8 #include <list> |
9 #include <set> | 9 #include <set> |
10 #include <string> | 10 #include <string> |
11 #include <utility> | 11 #include <utility> |
12 #include <vector> | 12 #include <vector> |
13 | 13 |
14 #include "base/basictypes.h" | 14 #include "base/basictypes.h" |
15 #include "base/callback.h" | 15 #include "base/callback.h" |
16 #include "base/gtest_prod_util.h" | 16 #include "base/gtest_prod_util.h" |
17 #include "base/memory/ref_counted.h" | 17 #include "base/memory/ref_counted.h" |
18 #include "base/synchronization/lock.h" | 18 #include "base/synchronization/lock.h" |
19 #include "base/task/cancelable_task_tracker.h" | 19 #include "base/task/cancelable_task_tracker.h" |
20 #include "base/time/time.h" | 20 #include "base/time/time.h" |
21 #include "base/timer/timer.h" | 21 #include "base/timer/timer.h" |
22 #include "chrome/browser/history/history_service.h" | 22 #include "chrome/browser/history/history_service.h" |
23 #include "chrome/browser/history/top_sites.h" | |
24 #include "chrome/browser/history/top_sites_backend.h" | |
25 #include "components/history/core/browser/history_types.h" | 23 #include "components/history/core/browser/history_types.h" |
26 #include "components/history/core/browser/page_usage_data.h" | 24 #include "components/history/core/browser/page_usage_data.h" |
25 #include "components/history/core/browser/top_sites.h" | |
26 #include "components/history/core/browser/top_sites_backend.h" | |
27 #include "components/history/core/common/thumbnail_score.h" | 27 #include "components/history/core/common/thumbnail_score.h" |
28 #include "content/public/browser/notification_observer.h" | |
28 #include "third_party/skia/include/core/SkColor.h" | 29 #include "third_party/skia/include/core/SkColor.h" |
29 #include "ui/gfx/image/image.h" | 30 #include "ui/gfx/image/image.h" |
30 #include "url/gurl.h" | 31 #include "url/gurl.h" |
31 | 32 |
32 class Profile; | 33 class Profile; |
33 | 34 |
34 namespace base { | 35 namespace base { |
35 class FilePath; | 36 class FilePath; |
36 class RefCountedBytes; | 37 class RefCountedBytes; |
37 class RefCountedMemory; | 38 class RefCountedMemory; |
39 class SingleThreadTaskRunner; | |
38 } | 40 } |
39 | 41 |
40 namespace history { | 42 namespace history { |
41 | 43 |
42 class TopSitesCache; | 44 class TopSitesCache; |
43 class TopSitesImplTest; | 45 class TopSitesImplTest; |
44 | 46 |
45 // This class allows requests for most visited urls and thumbnails on any | 47 // This class allows requests for most visited urls and thumbnails on any |
46 // thread. All other methods must be invoked on the UI thread. All mutations | 48 // thread. All other methods must be invoked on the UI thread. All mutations |
47 // to internal state happen on the UI thread and are scheduled to update the | 49 // to internal state happen on the UI thread and are scheduled to update the |
48 // db using TopSitesBackend. | 50 // db using TopSitesBackend. |
49 class TopSitesImpl : public TopSites { | 51 class TopSitesImpl : public TopSites, public content::NotificationObserver { |
50 public: | 52 public: |
51 explicit TopSitesImpl(Profile* profile); | 53 TopSitesImpl(Profile* profile, |
54 const PrepopulatedPageList& prepopulated_pages); | |
52 | 55 |
53 // Initializes TopSitesImpl. | 56 // Initializes TopSitesImpl. |
54 void Init(const base::FilePath& db_name); | 57 void Init(const base::FilePath& db_name, |
58 const scoped_refptr<base::SingleThreadTaskRunner>& db_task_runner); | |
55 | 59 |
56 bool SetPageThumbnail(const GURL& url, | 60 bool SetPageThumbnail(const GURL& url, |
57 const gfx::Image& thumbnail, | 61 const gfx::Image& thumbnail, |
58 const ThumbnailScore& score) override; | 62 const ThumbnailScore& score) override; |
59 bool SetPageThumbnailToJPEGBytes(const GURL& url, | 63 bool SetPageThumbnailToJPEGBytes(const GURL& url, |
60 const base::RefCountedMemory* memory, | 64 const base::RefCountedMemory* memory, |
61 const ThumbnailScore& score) override; | 65 const ThumbnailScore& score) override; |
62 void GetMostVisitedURLs(const GetMostVisitedURLsCallback& callback, | 66 void GetMostVisitedURLs(const GetMostVisitedURLsCallback& callback, |
63 bool include_forced_urls) override; | 67 bool include_forced_urls) override; |
64 bool GetPageThumbnail(const GURL& url, | 68 bool GetPageThumbnail(const GURL& url, |
65 bool prefix_match, | 69 bool prefix_match, |
66 scoped_refptr<base::RefCountedMemory>* bytes) override; | 70 scoped_refptr<base::RefCountedMemory>* bytes) override; |
67 bool GetPageThumbnailScore(const GURL& url, ThumbnailScore* score) override; | 71 bool GetPageThumbnailScore(const GURL& url, ThumbnailScore* score) override; |
68 bool GetTemporaryPageThumbnailScore(const GURL& url, | 72 bool GetTemporaryPageThumbnailScore(const GURL& url, |
69 ThumbnailScore* score) override; | 73 ThumbnailScore* score) override; |
70 void SyncWithHistory() override; | 74 void SyncWithHistory() override; |
71 bool HasBlacklistedItems() const override; | 75 bool HasBlacklistedItems() const override; |
72 void AddBlacklistedURL(const GURL& url) override; | 76 void AddBlacklistedURL(const GURL& url) override; |
73 void RemoveBlacklistedURL(const GURL& url) override; | 77 void RemoveBlacklistedURL(const GURL& url) override; |
74 bool IsBlacklisted(const GURL& url) override; | 78 bool IsBlacklisted(const GURL& url) override; |
75 void ClearBlacklistedURLs() override; | 79 void ClearBlacklistedURLs() override; |
76 base::CancelableTaskTracker::TaskId StartQueryForMostVisited() override; | 80 base::CancelableTaskTracker::TaskId StartQueryForMostVisited() override; |
77 bool IsKnownURL(const GURL& url) override; | 81 bool IsKnownURL(const GURL& url) override; |
78 const std::string& GetCanonicalURLString(const GURL& url) const override; | 82 const std::string& GetCanonicalURLString(const GURL& url) const override; |
79 bool IsNonForcedFull() override; | 83 bool IsNonForcedFull() override; |
80 bool IsForcedFull() override; | 84 bool IsForcedFull() override; |
81 MostVisitedURLList GetPrepopulatePages() override; | 85 PrepopulatedPageList GetPrepopulatedPages() override; |
droger
2015/01/27 10:08:36
Could you return a const reference here?
sdefresne
2015/01/27 13:55:16
GetPrepopulatedPages() is a virtual method defined
sdefresne
2015/01/27 13:55:16
GetPrepopulatedPages() is a virtual method defined
| |
82 bool loaded() const override; | 86 bool loaded() const override; |
83 bool AddForcedURL(const GURL& url, const base::Time& time) override; | 87 bool AddForcedURL(const GURL& url, const base::Time& time) override; |
84 | 88 |
85 // RefcountedKeyedService: | 89 // RefcountedKeyedService: |
86 void ShutdownOnUIThread() override; | 90 void ShutdownOnUIThread() override; |
87 | 91 |
88 protected: | 92 protected: |
89 ~TopSitesImpl() override; | 93 ~TopSitesImpl() override; |
90 | 94 |
91 private: | 95 private: |
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
247 // cached list and be able to run callbacks immediately. | 251 // cached list and be able to run callbacks immediately. |
248 PendingCallbacks pending_callbacks_; | 252 PendingCallbacks pending_callbacks_; |
249 | 253 |
250 // Stores thumbnails for unknown pages. When SetPageThumbnail is | 254 // Stores thumbnails for unknown pages. When SetPageThumbnail is |
251 // called, if we don't know about that URL yet and we don't have | 255 // called, if we don't know about that URL yet and we don't have |
252 // enough Top Sites (new profile), we store it until the next | 256 // enough Top Sites (new profile), we store it until the next |
253 // SetNonForcedTopSites call. | 257 // SetNonForcedTopSites call. |
254 TempImages temp_images_; | 258 TempImages temp_images_; |
255 | 259 |
256 // URL List of prepopulated page. | 260 // URL List of prepopulated page. |
257 std::vector<GURL> prepopulated_page_urls_; | 261 PrepopulatedPageList prepopulated_pages_; |
258 | 262 |
259 // Are we loaded? | 263 // Are we loaded? |
260 bool loaded_; | 264 bool loaded_; |
261 | 265 |
262 DISALLOW_COPY_AND_ASSIGN(TopSitesImpl); | 266 DISALLOW_COPY_AND_ASSIGN(TopSitesImpl); |
263 }; | 267 }; |
264 | 268 |
265 } // namespace history | 269 } // namespace history |
266 | 270 |
267 #endif // CHROME_BROWSER_HISTORY_TOP_SITES_IMPL_H_ | 271 #endif // CHROME_BROWSER_HISTORY_TOP_SITES_IMPL_H_ |
OLD | NEW |