OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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_H_ | 5 #ifndef CHROME_BROWSER_HISTORY_TOP_SITES_H_ |
6 #define CHROME_BROWSER_HISTORY_TOP_SITES_H_ | 6 #define CHROME_BROWSER_HISTORY_TOP_SITES_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <map> | 9 #include <list> |
10 #include <set> | 10 #include <set> |
11 #include <string> | 11 #include <string> |
12 #include <vector> | |
13 | 12 |
14 #include "base/basictypes.h" | 13 #include "base/basictypes.h" |
15 #include "base/gtest_prod_util.h" | 14 #include "base/gtest_prod_util.h" |
16 #include "base/lock.h" | 15 #include "base/lock.h" |
| 16 #include "base/time.h" |
17 #include "base/timer.h" | 17 #include "base/timer.h" |
18 #include "base/ref_counted.h" | 18 #include "base/ref_counted.h" |
19 #include "base/ref_counted_memory.h" | 19 #include "base/ref_counted_memory.h" |
20 #include "chrome/browser/browser_thread.h" | 20 #include "chrome/browser/browser_thread.h" |
21 #include "chrome/browser/cancelable_request.h" | 21 #include "chrome/browser/cancelable_request.h" |
22 #include "chrome/browser/history/history_types.h" | 22 #include "chrome/browser/history/history_types.h" |
23 #include "chrome/browser/history/history.h" | 23 #include "chrome/browser/history/history.h" |
24 #include "chrome/browser/history/page_usage_data.h" | 24 #include "chrome/browser/history/page_usage_data.h" |
25 #include "chrome/common/notification_service.h" | 25 #include "chrome/common/notification_service.h" |
26 #include "chrome/common/thumbnail_score.h" | 26 #include "chrome/common/thumbnail_score.h" |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
138 // URLs appearing in both old and new lists but having different indices will | 138 // URLs appearing in both old and new lists but having different indices will |
139 // have their index into "new" be put into |moved_urls|. | 139 // have their index into "new" be put into |moved_urls|. |
140 static void DiffMostVisited(const MostVisitedURLList& old_list, | 140 static void DiffMostVisited(const MostVisitedURLList& old_list, |
141 const MostVisitedURLList& new_list, | 141 const MostVisitedURLList& new_list, |
142 TopSitesDelta* delta); | 142 TopSitesDelta* delta); |
143 | 143 |
144 private: | 144 private: |
145 friend class base::RefCountedThreadSafe<TopSites>; | 145 friend class base::RefCountedThreadSafe<TopSites>; |
146 friend class TopSitesTest; | 146 friend class TopSitesTest; |
147 | 147 |
| 148 typedef std::pair<GURL, Images> TempImage; |
| 149 typedef std::list<TempImage> TempImages; |
| 150 |
148 // Enumeration of the possible states history can be in. | 151 // Enumeration of the possible states history can be in. |
149 enum HistoryLoadState { | 152 enum HistoryLoadState { |
150 // We're waiting for history to finish loading. | 153 // We're waiting for history to finish loading. |
151 HISTORY_LOADING, | 154 HISTORY_LOADING, |
152 | 155 |
153 // History finished loading and we need to migrate top sites out of history. | 156 // History finished loading and we need to migrate top sites out of history. |
154 HISTORY_MIGRATING, | 157 HISTORY_MIGRATING, |
155 | 158 |
156 // History is loaded. | 159 // History is loaded. |
157 HISTORY_LOADED | 160 HISTORY_LOADED |
(...skipping 26 matching lines...) Expand all Loading... |
184 // returned by HistoryService. | 187 // returned by HistoryService. |
185 bool SetPageThumbnailEncoded(const GURL& url, | 188 bool SetPageThumbnailEncoded(const GURL& url, |
186 const RefCountedBytes* thumbnail, | 189 const RefCountedBytes* thumbnail, |
187 const ThumbnailScore& score); | 190 const ThumbnailScore& score); |
188 | 191 |
189 // Encodes the bitmap to bytes for storage to the db. Returns true if the | 192 // Encodes the bitmap to bytes for storage to the db. Returns true if the |
190 // bitmap was successfully encoded. | 193 // bitmap was successfully encoded. |
191 static bool EncodeBitmap(const SkBitmap& bitmap, | 194 static bool EncodeBitmap(const SkBitmap& bitmap, |
192 scoped_refptr<RefCountedBytes>* bytes); | 195 scoped_refptr<RefCountedBytes>* bytes); |
193 | 196 |
| 197 // Removes the cached thumbnail for url. Does nothing if |url| if not cached |
| 198 // in |temp_images_|. |
| 199 void RemoveTemporaryThumbnailByURL(const GURL& url); |
| 200 |
194 // Add a thumbnail for an unknown url. See temp_thumbnails_map_. | 201 // Add a thumbnail for an unknown url. See temp_thumbnails_map_. |
195 void AddTemporaryThumbnail(const GURL& url, | 202 void AddTemporaryThumbnail(const GURL& url, |
196 const RefCountedBytes* thumbnail, | 203 const RefCountedBytes* thumbnail, |
197 const ThumbnailScore& score); | 204 const ThumbnailScore& score); |
198 | 205 |
199 // Query history service for the list of available thumbnails. | 206 // Query history service for the list of available thumbnails. |
200 void StartQueryForMostVisited(); | 207 void StartQueryForMostVisited(); |
201 | 208 |
202 // Finds the given URL in the redirect chain for the given TopSite, and | 209 // Finds the given URL in the redirect chain for the given TopSite, and |
203 // returns the distance from the destination in hops that the given URL is. | 210 // returns the distance from the destination in hops that the given URL is. |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
288 | 295 |
289 // Lock used to access |thread_safe_cache_|. | 296 // Lock used to access |thread_safe_cache_|. |
290 mutable Lock lock_; | 297 mutable Lock lock_; |
291 | 298 |
292 CancelableRequestConsumer cancelable_consumer_; | 299 CancelableRequestConsumer cancelable_consumer_; |
293 | 300 |
294 // Timer that asks history for the top sites. This is used to make sure our | 301 // Timer that asks history for the top sites. This is used to make sure our |
295 // data stays in sync with history. | 302 // data stays in sync with history. |
296 base::OneShotTimer<TopSites> timer_; | 303 base::OneShotTimer<TopSites> timer_; |
297 | 304 |
| 305 // The time we started |timer_| at. Only valid if |timer_| is running. |
| 306 base::TimeTicks timer_start_time_; |
| 307 |
298 NotificationRegistrar registrar_; | 308 NotificationRegistrar registrar_; |
299 | 309 |
300 // The number of URLs changed on the last update. | 310 // The number of URLs changed on the last update. |
301 size_t last_num_urls_changed_; | 311 size_t last_num_urls_changed_; |
302 | 312 |
303 // The map of requests for the top sites list. Can only be | 313 // The map of requests for the top sites list. Can only be |
304 // non-empty at startup. After we read the top sites from the DB, we'll | 314 // non-empty at startup. After we read the top sites from the DB, we'll |
305 // always have a cached list. | 315 // always have a cached list. |
306 PendingCallbackSet pending_callbacks_; | 316 PendingCallbackSet pending_callbacks_; |
307 | 317 |
308 // Stores thumbnails for unknown pages. When SetPageThumbnail is | 318 // Stores thumbnails for unknown pages. When SetPageThumbnail is |
309 // called, if we don't know about that URL yet and we don't have | 319 // called, if we don't know about that URL yet and we don't have |
310 // enough Top Sites (new profile), we store it until the next | 320 // enough Top Sites (new profile), we store it until the next |
311 // SetTopSites call. | 321 // SetTopSites call. |
312 URLToImagesMap temp_thumbnails_map_; | 322 TempImages temp_images_; |
313 | 323 |
314 // Blacklisted and pinned URLs are stored in Preferences. | 324 // Blacklisted and pinned URLs are stored in Preferences. |
315 | 325 |
316 // Blacklisted URLs. They are filtered out from the list of Top | 326 // Blacklisted URLs. They are filtered out from the list of Top |
317 // Sites when GetMostVisitedURLs is called. Note that we are still | 327 // Sites when GetMostVisitedURLs is called. Note that we are still |
318 // storing all URLs, but filtering on access. It is a dictionary, | 328 // storing all URLs, but filtering on access. It is a dictionary, |
319 // key is the URL, value is a dummy value. This is owned by the | 329 // key is the URL, value is a dummy value. This is owned by the |
320 // PrefService. | 330 // PrefService. |
321 DictionaryValue* blacklist_; | 331 DictionaryValue* blacklist_; |
322 | 332 |
(...skipping 10 matching lines...) Expand all Loading... |
333 | 343 |
334 // Are we loaded? | 344 // Are we loaded? |
335 bool loaded_; | 345 bool loaded_; |
336 | 346 |
337 DISALLOW_COPY_AND_ASSIGN(TopSites); | 347 DISALLOW_COPY_AND_ASSIGN(TopSites); |
338 }; | 348 }; |
339 | 349 |
340 } // namespace history | 350 } // namespace history |
341 | 351 |
342 #endif // CHROME_BROWSER_HISTORY_TOP_SITES_H_ | 352 #endif // CHROME_BROWSER_HISTORY_TOP_SITES_H_ |
OLD | NEW |