| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 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 COMPONENTS_NTP_TILES_MOST_VISITED_SITES_H_ | 5 #ifndef COMPONENTS_NTP_TILES_MOST_VISITED_SITES_H_ |
| 6 #define COMPONENTS_NTP_TILES_MOST_VISITED_SITES_H_ | 6 #define COMPONENTS_NTP_TILES_MOST_VISITED_SITES_H_ |
| 7 | 7 |
| 8 #include <stddef.h> | 8 #include <stddef.h> |
| 9 | 9 |
| 10 #include <memory> | 10 #include <memory> |
| 11 #include <string> | 11 #include <string> |
| 12 #include <vector> | 12 #include <vector> |
| 13 | 13 |
| 14 #include "base/compiler_specific.h" | 14 #include "base/compiler_specific.h" |
| 15 #include "base/files/file_path.h" | 15 #include "base/files/file_path.h" |
| 16 #include "base/macros.h" | 16 #include "base/macros.h" |
| 17 #include "base/memory/weak_ptr.h" | 17 #include "base/memory/weak_ptr.h" |
| 18 #include "base/scoped_observer.h" | 18 #include "base/scoped_observer.h" |
| 19 #include "components/history/core/browser/history_types.h" | 19 #include "components/history/core/browser/history_types.h" |
| 20 #include "components/history/core/browser/top_sites_observer.h" | 20 #include "components/history/core/browser/top_sites_observer.h" |
| 21 #include "components/image_fetcher/image_decoder.h" |
| 21 #include "components/ntp_tiles/popular_sites.h" | 22 #include "components/ntp_tiles/popular_sites.h" |
| 22 #include "components/suggestions/proto/suggestions.pb.h" | 23 #include "components/suggestions/proto/suggestions.pb.h" |
| 23 #include "components/suggestions/suggestions_service.h" | 24 #include "components/suggestions/suggestions_service.h" |
| 24 #include "url/gurl.h" | 25 #include "url/gurl.h" |
| 25 | 26 |
| 26 namespace gfx { | 27 namespace gfx { |
| 27 class Image; | 28 class Image; |
| 28 } | 29 } |
| 29 | 30 |
| 30 namespace history { | 31 namespace history { |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 129 }; | 130 }; |
| 130 | 131 |
| 131 MostVisitedSites(scoped_refptr<base::SequencedWorkerPool> blocking_pool, | 132 MostVisitedSites(scoped_refptr<base::SequencedWorkerPool> blocking_pool, |
| 132 PrefService* prefs, | 133 PrefService* prefs, |
| 133 const TemplateURLService* template_url_service, | 134 const TemplateURLService* template_url_service, |
| 134 variations::VariationsService* variations_service, | 135 variations::VariationsService* variations_service, |
| 135 net::URLRequestContextGetter* download_context, | 136 net::URLRequestContextGetter* download_context, |
| 136 const base::FilePath& popular_sites_directory, | 137 const base::FilePath& popular_sites_directory, |
| 137 scoped_refptr<history::TopSites> top_sites, | 138 scoped_refptr<history::TopSites> top_sites, |
| 138 suggestions::SuggestionsService* suggestions, | 139 suggestions::SuggestionsService* suggestions, |
| 139 MostVisitedSitesSupervisor* supervisor); | 140 MostVisitedSitesSupervisor* supervisor, |
| 141 image_fetcher::ImageDecoder* image_decoder); |
| 140 | 142 |
| 141 ~MostVisitedSites() override; | 143 ~MostVisitedSites() override; |
| 142 | 144 |
| 143 // Does not take ownership of |observer|, which must outlive this object and | 145 // Does not take ownership of |observer|, which must outlive this object and |
| 144 // must not be null. | 146 // must not be null. |
| 145 void SetMostVisitedURLsObserver(Observer* observer, int num_sites); | 147 void SetMostVisitedURLsObserver(Observer* observer, int num_sites); |
| 146 | 148 |
| 149 // TODO(markusheintz): Replace bitmap with gfx::Image() |
| 147 using ThumbnailCallback = base::Callback< | 150 using ThumbnailCallback = base::Callback< |
| 148 void(bool /* is_local_thumbnail */, const SkBitmap* /* bitmap */)>; | 151 void(bool /* is_local_thumbnail */, const SkBitmap* /* bitmap */)>; |
| 149 void GetURLThumbnail(const GURL& url, const ThumbnailCallback& callback); | |
| 150 void AddOrRemoveBlacklistedUrl(const GURL& url, bool add_url); | 152 void AddOrRemoveBlacklistedUrl(const GURL& url, bool add_url); |
| 151 void RecordTileTypeMetrics(const std::vector<int>& tile_types); | 153 void RecordTileTypeMetrics(const std::vector<int>& tile_types); |
| 152 void RecordOpenedMostVisitedItem(int index, int tile_type); | 154 void RecordOpenedMostVisitedItem(int index, int tile_type); |
| 153 | 155 |
| 154 // MostVisitedSitesSupervisor::Observer implementation. | 156 // MostVisitedSitesSupervisor::Observer implementation. |
| 155 void OnBlockedSitesChanged() override; | 157 void OnBlockedSitesChanged() override; |
| 156 | 158 |
| 157 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry); | 159 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry); |
| 158 | 160 |
| 159 private: | 161 private: |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 206 SuggestionsPtrVector* dst); | 208 SuggestionsPtrVector* dst); |
| 207 | 209 |
| 208 void SaveCurrentSuggestionsToPrefs(); | 210 void SaveCurrentSuggestionsToPrefs(); |
| 209 | 211 |
| 210 // Notifies the observer about the availability of suggestions. | 212 // Notifies the observer about the availability of suggestions. |
| 211 // Also records impressions UMA if not done already. | 213 // Also records impressions UMA if not done already. |
| 212 void NotifyMostVisitedURLsObserver(); | 214 void NotifyMostVisitedURLsObserver(); |
| 213 | 215 |
| 214 void OnPopularSitesAvailable(bool success); | 216 void OnPopularSitesAvailable(bool success); |
| 215 | 217 |
| 216 // Runs on the UI Thread. | |
| 217 void OnLocalThumbnailFetched( | |
| 218 const GURL& url, | |
| 219 const ThumbnailCallback& callback, | |
| 220 std::unique_ptr<SkBitmap> bitmap); | |
| 221 | |
| 222 // Callback for when the thumbnail lookup is complete. | 218 // Callback for when the thumbnail lookup is complete. |
| 223 // Runs on the UI Thread. | 219 // Runs on the UI Thread. |
| 224 void OnObtainedThumbnail( | 220 void OnObtainedThumbnail( |
| 225 bool is_local_thumbnail, | 221 bool is_local_thumbnail, |
| 226 const ThumbnailCallback& callback, | 222 const ThumbnailCallback& callback, |
| 227 const GURL& url, | 223 const GURL& url, |
| 228 const gfx::Image& bitmap); | 224 const gfx::Image& bitmap); |
| 229 | 225 |
| 230 // Records thumbnail-related UMA histogram metrics. | 226 // Records thumbnail-related UMA histogram metrics. |
| 231 void RecordThumbnailUMAMetrics(); | 227 void RecordThumbnailUMAMetrics(); |
| 232 | 228 |
| 233 // Records UMA histogram metrics related to the number of impressions. | 229 // Records UMA histogram metrics related to the number of impressions. |
| 234 void RecordImpressionUMAMetrics(); | 230 void RecordImpressionUMAMetrics(); |
| 235 | 231 |
| 236 // history::TopSitesObserver implementation. | 232 // history::TopSitesObserver implementation. |
| 237 void TopSitesLoaded(history::TopSites* top_sites) override; | 233 void TopSitesLoaded(history::TopSites* top_sites) override; |
| 238 void TopSitesChanged(history::TopSites* top_sites, | 234 void TopSitesChanged(history::TopSites* top_sites, |
| 239 ChangeReason change_reason) override; | 235 ChangeReason change_reason) override; |
| 240 | 236 |
| 241 PrefService* prefs_; | 237 PrefService* prefs_; |
| 242 const TemplateURLService* template_url_service_; | 238 const TemplateURLService* template_url_service_; |
| 243 variations::VariationsService* variations_service_; | 239 variations::VariationsService* variations_service_; |
| 244 net::URLRequestContextGetter* download_context_; | 240 net::URLRequestContextGetter* download_context_; |
| 245 base::FilePath popular_sites_directory_; | 241 base::FilePath popular_sites_directory_; |
| 246 scoped_refptr<history::TopSites> top_sites_; | 242 scoped_refptr<history::TopSites> top_sites_; |
| 247 suggestions::SuggestionsService* suggestions_service_; | 243 suggestions::SuggestionsService* suggestions_service_; |
| 248 MostVisitedSitesSupervisor* supervisor_; | 244 MostVisitedSitesSupervisor* supervisor_; |
| 245 std::unique_ptr<image_fetcher::ImageDecoder> image_decoder_; |
| 249 | 246 |
| 250 Observer* observer_; | 247 Observer* observer_; |
| 251 | 248 |
| 252 // The maximum number of most visited sites to return. | 249 // The maximum number of most visited sites to return. |
| 253 int num_sites_; | 250 int num_sites_; |
| 254 | 251 |
| 255 // Whether we have received an initial set of most visited sites (from either | 252 // Whether we have received an initial set of most visited sites (from either |
| 256 // TopSites or the SuggestionsService). | 253 // TopSites or the SuggestionsService). |
| 257 bool received_most_visited_sites_; | 254 bool received_most_visited_sites_; |
| 258 | 255 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 280 scoped_refptr<base::SequencedWorkerPool> blocking_pool_; | 277 scoped_refptr<base::SequencedWorkerPool> blocking_pool_; |
| 281 scoped_refptr<base::TaskRunner> blocking_runner_; | 278 scoped_refptr<base::TaskRunner> blocking_runner_; |
| 282 | 279 |
| 283 // For callbacks may be run after destruction. | 280 // For callbacks may be run after destruction. |
| 284 base::WeakPtrFactory<MostVisitedSites> weak_ptr_factory_; | 281 base::WeakPtrFactory<MostVisitedSites> weak_ptr_factory_; |
| 285 | 282 |
| 286 DISALLOW_COPY_AND_ASSIGN(MostVisitedSites); | 283 DISALLOW_COPY_AND_ASSIGN(MostVisitedSites); |
| 287 }; | 284 }; |
| 288 | 285 |
| 289 #endif // COMPONENTS_NTP_TILES_MOST_VISITED_SITES_H_ | 286 #endif // COMPONENTS_NTP_TILES_MOST_VISITED_SITES_H_ |
| OLD | NEW |