| 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 #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> |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 70 DCHECK(suggestions_service_); | 70 DCHECK(suggestions_service_); |
| 71 if (supervisor_) | 71 if (supervisor_) |
| 72 supervisor_->SetObserver(this); | 72 supervisor_->SetObserver(this); |
| 73 } | 73 } |
| 74 | 74 |
| 75 MostVisitedSites::~MostVisitedSites() { | 75 MostVisitedSites::~MostVisitedSites() { |
| 76 if (supervisor_) | 76 if (supervisor_) |
| 77 supervisor_->SetObserver(nullptr); | 77 supervisor_->SetObserver(nullptr); |
| 78 } | 78 } |
| 79 | 79 |
| 80 bool MostVisitedSites::DoesSourceExist(NTPTileSource source) const { |
| 81 switch (source) { |
| 82 case NTPTileSource::TOP_SITES: |
| 83 return top_sites_ != nullptr; |
| 84 case NTPTileSource::SUGGESTIONS_SERVICE: |
| 85 return suggestions_service_ != nullptr; |
| 86 case NTPTileSource::POPULAR: |
| 87 return popular_sites_ != nullptr; |
| 88 case NTPTileSource::WHITELIST: |
| 89 return supervisor_ != nullptr; |
| 90 } |
| 91 NOTREACHED(); |
| 92 return false; |
| 93 } |
| 94 |
| 80 void MostVisitedSites::SetMostVisitedURLsObserver(Observer* observer, | 95 void MostVisitedSites::SetMostVisitedURLsObserver(Observer* observer, |
| 81 int num_sites) { | 96 int num_sites) { |
| 82 DCHECK(observer); | 97 DCHECK(observer); |
| 83 observer_ = observer; | 98 observer_ = observer; |
| 84 num_sites_ = num_sites; | 99 num_sites_ = num_sites; |
| 85 | 100 |
| 86 // The order for this condition is important, ShouldShowPopularSites() should | 101 // The order for this condition is important, ShouldShowPopularSites() should |
| 87 // always be called last to keep metrics as relevant as possible. | 102 // always be called last to keep metrics as relevant as possible. |
| 88 if (popular_sites_ && NeedPopularSites(prefs_, num_sites_) && | 103 if (popular_sites_ && NeedPopularSites(prefs_, num_sites_) && |
| 89 ShouldShowPopularSites()) { | 104 ShouldShowPopularSites()) { |
| (...skipping 311 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 401 | 416 |
| 402 void MostVisitedSites::TopSitesChanged(TopSites* top_sites, | 417 void MostVisitedSites::TopSitesChanged(TopSites* top_sites, |
| 403 ChangeReason change_reason) { | 418 ChangeReason change_reason) { |
| 404 if (mv_source_ == NTPTileSource::TOP_SITES) { | 419 if (mv_source_ == NTPTileSource::TOP_SITES) { |
| 405 // The displayed tiles are invalidated. | 420 // The displayed tiles are invalidated. |
| 406 InitiateTopSitesQuery(); | 421 InitiateTopSitesQuery(); |
| 407 } | 422 } |
| 408 } | 423 } |
| 409 | 424 |
| 410 } // namespace ntp_tiles | 425 } // namespace ntp_tiles |
| OLD | NEW |