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

Side by Side Diff: chrome/browser/history/top_sites.cc

Issue 8401026: top sites: allow TopSites to return all 20 cached sites (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: eliminate kTopSitesShown Created 9 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
43 43
44 namespace history { 44 namespace history {
45 45
46 // How many top sites to store in the cache. 46 // How many top sites to store in the cache.
47 static const size_t kTopSitesNumber = 20; 47 static const size_t kTopSitesNumber = 20;
48 48
49 // Max number of temporary images we'll cache. See comment above 49 // Max number of temporary images we'll cache. See comment above
50 // temp_images_ for details. 50 // temp_images_ for details.
51 static const size_t kMaxTempTopImages = 8; 51 static const size_t kMaxTempTopImages = 8;
52 52
53 static const size_t kTopSitesShown = 8;
54 static const int kDaysOfHistory = 90; 53 static const int kDaysOfHistory = 90;
55 // Time from startup to first HistoryService query. 54 // Time from startup to first HistoryService query.
56 static const int64 kUpdateIntervalSecs = 15; 55 static const int64 kUpdateIntervalSecs = 15;
57 // Intervals between requests to HistoryService. 56 // Intervals between requests to HistoryService.
58 static const int64 kMinUpdateIntervalMinutes = 1; 57 static const int64 kMinUpdateIntervalMinutes = 1;
59 static const int64 kMaxUpdateIntervalMinutes = 60; 58 static const int64 kMaxUpdateIntervalMinutes = 60;
60 59
61 const TopSites::PrepopulatedPage kPrepopulatedPages[] = { 60 const TopSites::PrepopulatedPage kPrepopulatedPages[] = {
62 { IDS_CHROME_WELCOME_URL, IDS_NEW_TAB_CHROME_WELCOME_PAGE_TITLE, 61 { IDS_CHROME_WELCOME_URL, IDS_NEW_TAB_CHROME_WELCOME_PAGE_TITLE,
63 IDR_PRODUCT_LOGO_16, IDR_NEWTAB_CHROME_WELCOME_PAGE_THUMBNAIL, 62 IDR_PRODUCT_LOGO_16, IDR_NEWTAB_CHROME_WELCOME_PAGE_THUMBNAIL,
(...skipping 662 matching lines...) Expand 10 before | Expand all | Expand 10 after
726 } 725 }
727 726
728 void TopSites::ApplyBlacklistAndPinnedURLs(const MostVisitedURLList& urls, 727 void TopSites::ApplyBlacklistAndPinnedURLs(const MostVisitedURLList& urls,
729 MostVisitedURLList* out) { 728 MostVisitedURLList* out) {
730 MostVisitedURLList urls_copy; 729 MostVisitedURLList urls_copy;
731 for (size_t i = 0; i < urls.size(); i++) { 730 for (size_t i = 0; i < urls.size(); i++) {
732 if (!IsBlacklisted(urls[i].url)) 731 if (!IsBlacklisted(urls[i].url))
733 urls_copy.push_back(urls[i]); 732 urls_copy.push_back(urls[i]);
734 } 733 }
735 734
736 for (size_t pinned_index = 0; pinned_index < kTopSitesShown; pinned_index++) { 735 for (size_t pinned_index = 0; pinned_index < kTopSitesNumber;
736 pinned_index++) {
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
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
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698