OLD | NEW |
---|---|
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
sdefresne
2014/12/19 15:11:41
Do not change copyright notice when moving files.
| |
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_SERVICE_H_ |
6 #define CHROME_BROWSER_HISTORY_TOP_SITES_IMPL_H_ | 6 #define CHROME_BROWSER_HISTORY_TOP_SITES_SERVICE_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" | 23 #include "chrome/browser/history/top_sites_backend.h" |
24 #include "chrome/browser/history/top_sites_provider.h" | |
25 #include "components/history/core/browser/history_types.h" | 25 #include "components/history/core/browser/history_types.h" |
26 #include "components/history/core/browser/page_usage_data.h" | 26 #include "components/history/core/browser/page_usage_data.h" |
27 #include "components/history/core/common/thumbnail_score.h" | 27 #include "components/history/core/common/thumbnail_score.h" |
28 #include "third_party/skia/include/core/SkColor.h" | 28 #include "third_party/skia/include/core/SkColor.h" |
29 #include "ui/gfx/image/image.h" | 29 #include "ui/gfx/image/image.h" |
30 #include "url/gurl.h" | 30 #include "url/gurl.h" |
31 | 31 |
32 class Profile; | 32 class Profile; |
33 | 33 |
34 namespace base { | 34 namespace base { |
35 class FilePath; | 35 class FilePath; |
36 class RefCountedBytes; | 36 class RefCountedBytes; |
37 class RefCountedMemory; | 37 class RefCountedMemory; |
38 } | 38 } |
39 | 39 |
40 namespace history { | 40 namespace history { |
41 | 41 |
42 class TopSitesCache; | 42 class TopSitesCache; |
43 class TopSitesImplTest; | 43 class TopSitesImplTest; |
44 | 44 |
45 // This class allows requests for most visited urls and thumbnails on any | 45 // 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 | 46 // 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 | 47 // to internal state happen on the UI thread and are scheduled to update the |
48 // db using TopSitesBackend. | 48 // db using TopSitesBackend. |
49 class TopSitesImpl : public TopSites { | 49 class TopSitesService : public KeyedService, public TopSitesProvider { |
sdefresne
2014/12/19 15:11:41
TopSitesImpl should not be the KeyedService, it sh
Jitu( very slow this week)
2014/12/26 14:04:27
Done.
| |
50 public: | 50 public: |
51 explicit TopSitesImpl(Profile* profile); | 51 explicit TopSitesService(Profile* profile); |
52 | 52 |
53 // Initializes TopSitesImpl. | 53 // Initializes TopSitesImpl. |
54 void Init(const base::FilePath& db_name); | 54 void Init(const base::FilePath& db_name); |
55 | 55 |
56 bool SetPageThumbnail(const GURL& url, | 56 bool SetPageThumbnail(const GURL& url, |
57 const gfx::Image& thumbnail, | 57 const gfx::Image& thumbnail, |
58 const ThumbnailScore& score) override; | 58 const ThumbnailScore& score) override; |
59 bool SetPageThumbnailToJPEGBytes(const GURL& url, | 59 bool SetPageThumbnailToJPEGBytes(const GURL& url, |
60 const base::RefCountedMemory* memory, | 60 const base::RefCountedMemory* memory, |
61 const ThumbnailScore& score) override; | 61 const ThumbnailScore& score) override; |
(...skipping 15 matching lines...) Expand all Loading... | |
77 base::CancelableTaskTracker::TaskId StartQueryForMostVisited() override; | 77 base::CancelableTaskTracker::TaskId StartQueryForMostVisited() override; |
78 bool IsKnownURL(const GURL& url) override; | 78 bool IsKnownURL(const GURL& url) override; |
79 const std::string& GetCanonicalURLString(const GURL& url) const override; | 79 const std::string& GetCanonicalURLString(const GURL& url) const override; |
80 bool IsNonForcedFull() override; | 80 bool IsNonForcedFull() override; |
81 bool IsForcedFull() override; | 81 bool IsForcedFull() override; |
82 MostVisitedURLList GetPrepopulatePages() override; | 82 MostVisitedURLList GetPrepopulatePages() override; |
83 bool loaded() const override; | 83 bool loaded() const override; |
84 bool AddForcedURL(const GURL& url, const base::Time& time) override; | 84 bool AddForcedURL(const GURL& url, const base::Time& time) override; |
85 | 85 |
86 protected: | 86 protected: |
87 ~TopSitesImpl() override; | 87 ~TopSitesService() override; |
88 | 88 |
89 private: | 89 private: |
90 friend class TopSitesImplTest; | 90 friend class TopSitesImplTest; |
91 FRIEND_TEST_ALL_PREFIXES(TopSitesImplTest, DiffMostVisited); | 91 FRIEND_TEST_ALL_PREFIXES(TopSitesImplTest, DiffMostVisited); |
92 FRIEND_TEST_ALL_PREFIXES(TopSitesImplTest, DiffMostVisitedWithForced); | 92 FRIEND_TEST_ALL_PREFIXES(TopSitesImplTest, DiffMostVisitedWithForced); |
93 | 93 |
94 typedef base::Callback<void(const MostVisitedURLList&, | 94 typedef base::Callback<void(const MostVisitedURLList&, |
95 const MostVisitedURLList&)> PendingCallback; | 95 const MostVisitedURLList&)> PendingCallback; |
96 | 96 |
97 typedef std::pair<GURL, Images> TempImage; | 97 typedef std::pair<GURL, Images> TempImage; |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
143 void TimerFired(); | 143 void TimerFired(); |
144 | 144 |
145 // Finds the given URL in the redirect chain for the given TopSite, and | 145 // Finds the given URL in the redirect chain for the given TopSite, and |
146 // returns the distance from the destination in hops that the given URL is. | 146 // returns the distance from the destination in hops that the given URL is. |
147 // The URL is assumed to be in the list. The destination is 0. | 147 // The URL is assumed to be in the list. The destination is 0. |
148 static int GetRedirectDistanceForURL(const MostVisitedURL& most_visited, | 148 static int GetRedirectDistanceForURL(const MostVisitedURL& most_visited, |
149 const GURL& url); | 149 const GURL& url); |
150 | 150 |
151 // Add prepopulated pages: 'welcome to Chrome' and themes gallery to |urls|. | 151 // Add prepopulated pages: 'welcome to Chrome' and themes gallery to |urls|. |
152 // Returns true if any pages were added. | 152 // Returns true if any pages were added. |
153 bool AddPrepopulatedPages(MostVisitedURLList* urls, | 153 bool AddPrepopulatedPages(MostVisitedURLList* urls, size_t num_forced_urls); |
154 size_t num_forced_urls); | |
155 | 154 |
156 // Add all the forced URLs from |cache_| into |new_list|, making sure not to | 155 // Add all the forced URLs from |cache_| into |new_list|, making sure not to |
157 // add any URL that's already in |new_list|'s non-forced URLs. The forced URLs | 156 // add any URL that's already in |new_list|'s non-forced URLs. The forced URLs |
158 // in |cache_| and |new_list| are assumed to appear at the front of the list | 157 // in |cache_| and |new_list| are assumed to appear at the front of the list |
159 // and be sorted in increasing |last_forced_time|. This will still be true | 158 // and be sorted in increasing |last_forced_time|. This will still be true |
160 // after the call. If the list of forced URLs overflows the older ones are | 159 // after the call. If the list of forced URLs overflows the older ones are |
161 // dropped. Returns the number of forced URLs after the merge. | 160 // dropped. Returns the number of forced URLs after the merge. |
162 size_t MergeCachedForcedURLs(MostVisitedURLList* new_list); | 161 size_t MergeCachedForcedURLs(MostVisitedURLList* new_list); |
163 | 162 |
164 // Takes |urls|, produces it's copy in |out| after removing blacklisted URLs. | 163 // Takes |urls|, produces it's copy in |out| after removing blacklisted URLs. |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
223 Profile* profile_; | 222 Profile* profile_; |
224 | 223 |
225 // Lock used to access |thread_safe_cache_|. | 224 // Lock used to access |thread_safe_cache_|. |
226 mutable base::Lock lock_; | 225 mutable base::Lock lock_; |
227 | 226 |
228 // Task tracker for history and backend requests. | 227 // Task tracker for history and backend requests. |
229 base::CancelableTaskTracker cancelable_task_tracker_; | 228 base::CancelableTaskTracker cancelable_task_tracker_; |
230 | 229 |
231 // Timer that asks history for the top sites. This is used to make sure our | 230 // Timer that asks history for the top sites. This is used to make sure our |
232 // data stays in sync with history. | 231 // data stays in sync with history. |
233 base::OneShotTimer<TopSitesImpl> timer_; | 232 base::OneShotTimer<TopSitesService> timer_; |
234 | 233 |
235 // The time we started |timer_| at. Only valid if |timer_| is running. | 234 // The time we started |timer_| at. Only valid if |timer_| is running. |
236 base::TimeTicks timer_start_time_; | 235 base::TimeTicks timer_start_time_; |
237 | 236 |
238 content::NotificationRegistrar registrar_; | 237 content::NotificationRegistrar registrar_; |
239 | 238 |
240 // The number of URLs changed on the last update. | 239 // The number of URLs changed on the last update. |
241 size_t last_num_urls_changed_; | 240 size_t last_num_urls_changed_; |
242 | 241 |
243 // The pending requests for the top sites list. Can only be non-empty at | 242 // The pending requests for the top sites list. Can only be non-empty at |
244 // startup. After we read the top sites from the DB, we'll always have a | 243 // startup. After we read the top sites from the DB, we'll always have a |
245 // cached list and be able to run callbacks immediately. | 244 // cached list and be able to run callbacks immediately. |
246 PendingCallbacks pending_callbacks_; | 245 PendingCallbacks pending_callbacks_; |
247 | 246 |
248 // Stores thumbnails for unknown pages. When SetPageThumbnail is | 247 // Stores thumbnails for unknown pages. When SetPageThumbnail is |
249 // called, if we don't know about that URL yet and we don't have | 248 // called, if we don't know about that URL yet and we don't have |
250 // enough Top Sites (new profile), we store it until the next | 249 // enough Top Sites (new profile), we store it until the next |
251 // SetNonForcedTopSites call. | 250 // SetNonForcedTopSites call. |
252 TempImages temp_images_; | 251 TempImages temp_images_; |
253 | 252 |
254 // URL List of prepopulated page. | 253 // URL List of prepopulated page. |
255 std::vector<GURL> prepopulated_page_urls_; | 254 std::vector<GURL> prepopulated_page_urls_; |
256 | 255 |
257 // Are we loaded? | 256 // Are we loaded? |
258 bool loaded_; | 257 bool loaded_; |
259 | 258 |
260 DISALLOW_COPY_AND_ASSIGN(TopSitesImpl); | 259 DISALLOW_COPY_AND_ASSIGN(TopSitesService); |
261 }; | 260 }; |
262 | 261 |
263 } // namespace history | 262 } // namespace history |
264 | 263 |
265 #endif // CHROME_BROWSER_HISTORY_TOP_SITES_IMPL_H_ | 264 #endif // CHROME_BROWSER_HISTORY_TOP_SITES_SERVICE_H_ |
OLD | NEW |