Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "chrome/browser/history/top_sites.h" | 5 #include "chrome/browser/history/top_sites.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <set> | 8 #include <set> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 715 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 726 } | 726 } |
| 727 | 727 |
| 728 void TopSites::ApplyBlacklistAndPinnedURLs(const MostVisitedURLList& urls, | 728 void TopSites::ApplyBlacklistAndPinnedURLs(const MostVisitedURLList& urls, |
| 729 MostVisitedURLList* out) { | 729 MostVisitedURLList* out) { |
| 730 MostVisitedURLList urls_copy; | 730 MostVisitedURLList urls_copy; |
| 731 for (size_t i = 0; i < urls.size(); i++) { | 731 for (size_t i = 0; i < urls.size(); i++) { |
| 732 if (!IsBlacklisted(urls[i].url)) | 732 if (!IsBlacklisted(urls[i].url)) |
| 733 urls_copy.push_back(urls[i]); | 733 urls_copy.push_back(urls[i]); |
| 734 } | 734 } |
| 735 | 735 |
| 736 for (size_t pinned_index = 0; pinned_index < kTopSitesShown; pinned_index++) { | 736 for (size_t pinned_index = 0; pinned_index < kTopSitesShown; pinned_index++) { |
|
sky
2011/10/27 16:16:27
I think you want to change this one too. At which
Evan Stade
2011/10/27 16:31:21
well technically I can remove all the pinning code
| |
| 737 GURL url; | 737 GURL url; |
| 738 bool found = GetPinnedURLAtIndex(pinned_index, &url); | 738 bool found = GetPinnedURLAtIndex(pinned_index, &url); |
| 739 if (!found) | 739 if (!found) |
| 740 continue; | 740 continue; |
| 741 | 741 |
| 742 DCHECK(!url.is_empty()); | 742 DCHECK(!url.is_empty()); |
| 743 int cur_index = IndexOf(urls_copy, url); | 743 int cur_index = IndexOf(urls_copy, url); |
| 744 MostVisitedURL tmp; | 744 MostVisitedURL tmp; |
| 745 if (cur_index < 0) { | 745 if (cur_index < 0) { |
| 746 // Pinned URL not in urls. | 746 // Pinned URL not in urls. |
| 747 tmp.url = url; | 747 tmp.url = url; |
| 748 } else { | 748 } else { |
| 749 tmp = urls_copy[cur_index]; | 749 tmp = urls_copy[cur_index]; |
| 750 urls_copy.erase(urls_copy.begin() + cur_index); | 750 urls_copy.erase(urls_copy.begin() + cur_index); |
| 751 } | 751 } |
| 752 if (pinned_index > out->size()) | 752 if (pinned_index > out->size()) |
| 753 out->resize(pinned_index); // Add empty URLs as fillers. | 753 out->resize(pinned_index); // Add empty URLs as fillers. |
| 754 out->insert(out->begin() + pinned_index, tmp); | 754 out->insert(out->begin() + pinned_index, tmp); |
| 755 } | 755 } |
| 756 | 756 |
| 757 // Add non-pinned URLs in the empty spots. | 757 // Add non-pinned URLs in the empty spots. |
| 758 size_t current_url = 0; // Index into the remaining URLs in urls_copy. | 758 size_t current_url = 0; // Index into the remaining URLs in urls_copy. |
| 759 for (size_t i = 0; i < kTopSitesShown && current_url < urls_copy.size(); | 759 for (size_t i = 0; i < kTopSitesNumber && current_url < urls_copy.size(); |
| 760 i++) { | 760 i++) { |
| 761 if (i == out->size()) { | 761 if (i == out->size()) { |
| 762 out->push_back(urls_copy[current_url]); | 762 out->push_back(urls_copy[current_url]); |
| 763 current_url++; | 763 current_url++; |
| 764 } else if (i < out->size()) { | 764 } else if (i < out->size()) { |
| 765 if ((*out)[i].url.is_empty()) { | 765 if ((*out)[i].url.is_empty()) { |
| 766 // Replace the filler | 766 // Replace the filler |
| 767 (*out)[i] = urls_copy[current_url]; | 767 (*out)[i] = urls_copy[current_url]; |
| 768 current_url++; | 768 current_url++; |
| 769 } | 769 } |
| (...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1030 SetTopSites(pages); | 1030 SetTopSites(pages); |
| 1031 | 1031 |
| 1032 // Used only in testing. | 1032 // Used only in testing. |
| 1033 content::NotificationService::current()->Notify( | 1033 content::NotificationService::current()->Notify( |
| 1034 chrome::NOTIFICATION_TOP_SITES_UPDATED, | 1034 chrome::NOTIFICATION_TOP_SITES_UPDATED, |
| 1035 content::Source<TopSites>(this), | 1035 content::Source<TopSites>(this), |
| 1036 content::Details<CancelableRequestProvider::Handle>(&handle)); | 1036 content::Details<CancelableRequestProvider::Handle>(&handle)); |
| 1037 } | 1037 } |
| 1038 | 1038 |
| 1039 } // namespace history | 1039 } // namespace history |
| OLD | NEW |