| 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/scoped_observer.h" |
| 18 #include "base/synchronization/lock.h" | 19 #include "base/synchronization/lock.h" |
| 19 #include "base/task/cancelable_task_tracker.h" | 20 #include "base/task/cancelable_task_tracker.h" |
| 20 #include "base/time/time.h" | 21 #include "base/time/time.h" |
| 21 #include "base/timer/timer.h" | 22 #include "base/timer/timer.h" |
| 22 #include "chrome/browser/history/history_service.h" | 23 #include "chrome/browser/history/history_service.h" |
| 23 #include "chrome/browser/history/top_sites.h" | 24 #include "chrome/browser/history/top_sites.h" |
| 24 #include "chrome/browser/history/top_sites_backend.h" | 25 #include "chrome/browser/history/top_sites_backend.h" |
| 26 #include "components/history/core/browser/history_service_observer.h" |
| 25 #include "components/history/core/browser/history_types.h" | 27 #include "components/history/core/browser/history_types.h" |
| 26 #include "components/history/core/browser/page_usage_data.h" | 28 #include "components/history/core/browser/page_usage_data.h" |
| 27 #include "components/history/core/common/thumbnail_score.h" | 29 #include "components/history/core/common/thumbnail_score.h" |
| 28 #include "third_party/skia/include/core/SkColor.h" | 30 #include "third_party/skia/include/core/SkColor.h" |
| 29 #include "ui/gfx/image/image.h" | 31 #include "ui/gfx/image/image.h" |
| 30 #include "url/gurl.h" | 32 #include "url/gurl.h" |
| 31 | 33 |
| 32 class Profile; | 34 class Profile; |
| 33 | 35 |
| 34 namespace base { | 36 namespace base { |
| 35 class FilePath; | 37 class FilePath; |
| 36 class RefCountedBytes; | 38 class RefCountedBytes; |
| 37 class RefCountedMemory; | 39 class RefCountedMemory; |
| 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 HistoryServiceObserver { |
| 50 public: | 52 public: |
| 51 explicit TopSitesImpl(Profile* profile); | 53 explicit TopSitesImpl(Profile* profile); |
| 52 | 54 |
| 53 // Initializes TopSitesImpl. | 55 // Initializes TopSitesImpl. |
| 54 void Init(const base::FilePath& db_name); | 56 void Init(const base::FilePath& db_name); |
| 55 | 57 |
| 56 bool SetPageThumbnail(const GURL& url, | 58 bool SetPageThumbnail(const GURL& url, |
| 57 const gfx::Image& thumbnail, | 59 const gfx::Image& thumbnail, |
| 58 const ThumbnailScore& score) override; | 60 const ThumbnailScore& score) override; |
| 59 bool SetPageThumbnailToJPEGBytes(const GURL& url, | 61 bool SetPageThumbnailToJPEGBytes(const GURL& url, |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 203 void RestartQueryForTopSitesTimer(base::TimeDelta delta); | 205 void RestartQueryForTopSitesTimer(base::TimeDelta delta); |
| 204 | 206 |
| 205 // Callback from TopSites with the top sites/thumbnails. Should be called | 207 // Callback from TopSites with the top sites/thumbnails. Should be called |
| 206 // from the UI thread. | 208 // from the UI thread. |
| 207 void OnGotMostVisitedThumbnails( | 209 void OnGotMostVisitedThumbnails( |
| 208 const scoped_refptr<MostVisitedThumbnails>& thumbnails); | 210 const scoped_refptr<MostVisitedThumbnails>& thumbnails); |
| 209 | 211 |
| 210 // Called when history service returns a list of top URLs. | 212 // Called when history service returns a list of top URLs. |
| 211 void OnTopSitesAvailableFromHistory(const MostVisitedURLList* data); | 213 void OnTopSitesAvailableFromHistory(const MostVisitedURLList* data); |
| 212 | 214 |
| 215 // history::HistoryServiceObserver: |
| 216 void OnURLsDeleted( |
| 217 HistoryService* history_service, |
| 218 const history::URLsDeletedDetails& deleted_details) override; |
| 219 void HistoryServiceBeingDeleted(HistoryService* history_service) override; |
| 220 |
| 213 scoped_refptr<TopSitesBackend> backend_; | 221 scoped_refptr<TopSitesBackend> backend_; |
| 214 | 222 |
| 215 // The top sites data. | 223 // The top sites data. |
| 216 scoped_ptr<TopSitesCache> cache_; | 224 scoped_ptr<TopSitesCache> cache_; |
| 217 | 225 |
| 218 // Copy of the top sites data that may be accessed on any thread (assuming | 226 // Copy of the top sites data that may be accessed on any thread (assuming |
| 219 // you hold |lock_|). The data in |thread_safe_cache_| has blacklisted and | 227 // you hold |lock_|). The data in |thread_safe_cache_| has blacklisted and |
| 220 // pinned urls applied (|cache_| does not). | 228 // pinned urls applied (|cache_| does not). |
| 221 scoped_ptr<TopSitesCache> thread_safe_cache_; | 229 scoped_ptr<TopSitesCache> thread_safe_cache_; |
| 222 | 230 |
| (...skipping 27 matching lines...) Expand all Loading... |
| 250 // enough Top Sites (new profile), we store it until the next | 258 // enough Top Sites (new profile), we store it until the next |
| 251 // SetNonForcedTopSites call. | 259 // SetNonForcedTopSites call. |
| 252 TempImages temp_images_; | 260 TempImages temp_images_; |
| 253 | 261 |
| 254 // URL List of prepopulated page. | 262 // URL List of prepopulated page. |
| 255 std::vector<GURL> prepopulated_page_urls_; | 263 std::vector<GURL> prepopulated_page_urls_; |
| 256 | 264 |
| 257 // Are we loaded? | 265 // Are we loaded? |
| 258 bool loaded_; | 266 bool loaded_; |
| 259 | 267 |
| 268 ScopedObserver<HistoryService, HistoryServiceObserver> |
| 269 history_service_observer_; |
| 270 |
| 260 DISALLOW_COPY_AND_ASSIGN(TopSitesImpl); | 271 DISALLOW_COPY_AND_ASSIGN(TopSitesImpl); |
| 261 }; | 272 }; |
| 262 | 273 |
| 263 } // namespace history | 274 } // namespace history |
| 264 | 275 |
| 265 #endif // CHROME_BROWSER_HISTORY_TOP_SITES_IMPL_H_ | 276 #endif // CHROME_BROWSER_HISTORY_TOP_SITES_IMPL_H_ |
| OLD | NEW |