Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(147)

Side by Side Diff: components/ntp_tiles/most_visited_sites.cc

Issue 2388783004: Ensure PopularSite icon availability in ntp_tiles. (Closed)
Patch Set: Merge branch 'master' into icons Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « components/ntp_tiles/most_visited_sites.h ('k') | components/ntp_tiles/popular_sites.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 #include "components/ntp_tiles/most_visited_sites.h" 5 #include "components/ntp_tiles/most_visited_sites.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <set> 8 #include <set>
9 #include <string> 9 #include <string>
10 #include <utility> 10 #include <utility>
11 11
12 #if defined(OS_ANDROID) 12 #if defined(OS_ANDROID)
13 #include <jni.h> 13 #include <jni.h>
14 #endif 14 #endif
15 15
16 #include "base/callback.h" 16 #include "base/callback.h"
17 #include "base/command_line.h" 17 #include "base/command_line.h"
18 #include "base/feature_list.h" 18 #include "base/feature_list.h"
19 #include "base/metrics/field_trial.h" 19 #include "base/metrics/field_trial.h"
20 #include "base/strings/string_util.h" 20 #include "base/strings/string_util.h"
21 #include "base/strings/utf_string_conversions.h" 21 #include "base/strings/utf_string_conversions.h"
22 #include "components/history/core/browser/top_sites.h" 22 #include "components/history/core/browser/top_sites.h"
23 #include "components/ntp_tiles/constants.h" 23 #include "components/ntp_tiles/constants.h"
24 #include "components/ntp_tiles/icon_cacher.h"
24 #include "components/ntp_tiles/metrics.h" 25 #include "components/ntp_tiles/metrics.h"
25 #include "components/ntp_tiles/pref_names.h" 26 #include "components/ntp_tiles/pref_names.h"
26 #include "components/ntp_tiles/switches.h" 27 #include "components/ntp_tiles/switches.h"
27 #include "components/pref_registry/pref_registry_syncable.h" 28 #include "components/pref_registry/pref_registry_syncable.h"
28 #include "components/prefs/pref_service.h" 29 #include "components/prefs/pref_service.h"
29 30
30 #if defined(OS_ANDROID) 31 #if defined(OS_ANDROID)
31 #include "base/android/jni_android.h" 32 #include "base/android/jni_android.h"
32 #include "jni/MostVisitedSites_jni.h" 33 #include "jni/MostVisitedSites_jni.h"
33 #endif 34 #endif
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
77 bool AreURLsEquivalent(const GURL& url1, const GURL& url2) { 78 bool AreURLsEquivalent(const GURL& url1, const GURL& url2) {
78 return url1.host() == url2.host() && url1.path() == url2.path(); 79 return url1.host() == url2.host() && url1.path() == url2.path();
79 } 80 }
80 81
81 } // namespace 82 } // namespace
82 83
83 MostVisitedSites::MostVisitedSites(PrefService* prefs, 84 MostVisitedSites::MostVisitedSites(PrefService* prefs,
84 scoped_refptr<history::TopSites> top_sites, 85 scoped_refptr<history::TopSites> top_sites,
85 SuggestionsService* suggestions, 86 SuggestionsService* suggestions,
86 std::unique_ptr<PopularSites> popular_sites, 87 std::unique_ptr<PopularSites> popular_sites,
88 std::unique_ptr<IconCacher> icon_cacher,
87 MostVisitedSitesSupervisor* supervisor) 89 MostVisitedSitesSupervisor* supervisor)
88 : prefs_(prefs), 90 : prefs_(prefs),
89 top_sites_(top_sites), 91 top_sites_(top_sites),
90 suggestions_service_(suggestions), 92 suggestions_service_(suggestions),
91 popular_sites_(std::move(popular_sites)), 93 popular_sites_(std::move(popular_sites)),
94 icon_cacher_(std::move(icon_cacher)),
92 supervisor_(supervisor), 95 supervisor_(supervisor),
93 observer_(nullptr), 96 observer_(nullptr),
94 num_sites_(0), 97 num_sites_(0),
95 waiting_for_most_visited_sites_(true), 98 waiting_for_most_visited_sites_(true),
96 waiting_for_popular_sites_(true), 99 waiting_for_popular_sites_(true),
97 recorded_impressions_(false), 100 recorded_impressions_(false),
98 top_sites_observer_(this), 101 top_sites_observer_(this),
99 mv_source_(NTPTileSource::SUGGESTIONS_SERVICE), 102 mv_source_(NTPTileSource::SUGGESTIONS_SERVICE),
100 weak_ptr_factory_(this) { 103 weak_ptr_factory_(this) {
101 DCHECK(prefs_); 104 DCHECK(prefs_);
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after
338 // Skip tiles already present in personal or whitelists. 341 // Skip tiles already present in personal or whitelists.
339 if (hosts.find(host) != hosts.end()) 342 if (hosts.find(host) != hosts.end())
340 continue; 343 continue;
341 344
342 NTPTile tile; 345 NTPTile tile;
343 tile.title = popular_site.title; 346 tile.title = popular_site.title;
344 tile.url = GURL(popular_site.url); 347 tile.url = GURL(popular_site.url);
345 tile.source = NTPTileSource::POPULAR; 348 tile.source = NTPTileSource::POPULAR;
346 349
347 popular_sites_tiles.push_back(std::move(tile)); 350 popular_sites_tiles.push_back(std::move(tile));
351 icon_cacher_->StartFetch(
352 popular_site, base::Bind(&MostVisitedSites::OnIconMadeAvailable,
353 base::Unretained(this), popular_site.url));
348 if (popular_sites_tiles.size() >= num_popular_sites_tiles) 354 if (popular_sites_tiles.size() >= num_popular_sites_tiles)
349 break; 355 break;
350 } 356 }
351 } 357 }
352 return popular_sites_tiles; 358 return popular_sites_tiles;
353 } 359 }
354 360
355 void MostVisitedSites::SaveNewTiles(NTPTilesVector personal_tiles) { 361 void MostVisitedSites::SaveNewTiles(NTPTilesVector personal_tiles) {
356 NTPTilesVector whitelist_tiles = 362 NTPTilesVector whitelist_tiles =
357 CreateWhitelistEntryPointTiles(personal_tiles); 363 CreateWhitelistEntryPointTiles(personal_tiles);
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
403 } 409 }
404 410
405 void MostVisitedSites::OnPopularSitesAvailable(bool success) { 411 void MostVisitedSites::OnPopularSitesAvailable(bool success) {
406 waiting_for_popular_sites_ = false; 412 waiting_for_popular_sites_ = false;
407 413
408 if (!success) { 414 if (!success) {
409 LOG(WARNING) << "Download of popular sites failed"; 415 LOG(WARNING) << "Download of popular sites failed";
410 return; 416 return;
411 } 417 }
412 418
413 // Pass the popular sites to the observer. This will cause it to fetch any
414 // missing icons, but will *not* cause it to display the popular sites.
415 observer_->OnPopularURLsAvailable(popular_sites_->sites());
416
417 // Re-build the tile list. Once done, this will notify the observer. 419 // Re-build the tile list. Once done, this will notify the observer.
418 BuildCurrentTiles(); 420 BuildCurrentTiles();
419 } 421 }
420 422
423 void MostVisitedSites::OnIconMadeAvailable(const GURL& site_url,
424 bool newly_available) {
425 if (newly_available)
426 observer_->OnIconMadeAvailable(site_url);
427 }
428
421 void MostVisitedSites::TopSitesLoaded(TopSites* top_sites) {} 429 void MostVisitedSites::TopSitesLoaded(TopSites* top_sites) {}
422 430
423 void MostVisitedSites::TopSitesChanged(TopSites* top_sites, 431 void MostVisitedSites::TopSitesChanged(TopSites* top_sites,
424 ChangeReason change_reason) { 432 ChangeReason change_reason) {
425 if (mv_source_ == NTPTileSource::TOP_SITES) { 433 if (mv_source_ == NTPTileSource::TOP_SITES) {
426 // The displayed tiles are invalidated. 434 // The displayed tiles are invalidated.
427 InitiateTopSitesQuery(); 435 InitiateTopSitesQuery();
428 } 436 }
429 } 437 }
430 438
431 } // namespace ntp_tiles 439 } // namespace ntp_tiles
OLDNEW
« no previous file with comments | « components/ntp_tiles/most_visited_sites.h ('k') | components/ntp_tiles/popular_sites.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698