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

Unified Diff: chrome/browser/history/top_sites.cc

Issue 3039029: New pinning algorithm. (Closed)
Patch Set: Add missing the else part. Created 10 years, 5 months 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | chrome/browser/history/top_sites_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/history/top_sites.cc
diff --git a/chrome/browser/history/top_sites.cc b/chrome/browser/history/top_sites.cc
index a568e2b02e8ef62d3125ed86d54073801ac82541..3d9a719b8cdacc24e3170e07bdbc39c43c0bab4c 100644
--- a/chrome/browser/history/top_sites.cc
+++ b/chrome/browser/history/top_sites.cc
@@ -370,36 +370,48 @@ void TopSites::MigratePinnedURLs() {
void TopSites::ApplyBlacklistAndPinnedURLs(const MostVisitedURLList& urls,
MostVisitedURLList* out) {
+ MostVisitedURLList urls_copy;
for (size_t i = 0; i < urls.size(); i++) {
if (!IsBlacklisted(urls[i].url))
- out->push_back(urls[i]);
+ urls_copy.push_back(urls[i]);
}
- for (DictionaryValue::key_iterator it = pinned_urls_->begin_keys();
- it != pinned_urls_->end_keys(); ++it) {
- GURL url(WideToASCII(*it));
-
- int index = IndexOf(*out, url);
- if (index == -1) {
- if (url.is_empty()) {
- MigratePinnedURLs();
- out->clear();
- ApplyBlacklistAndPinnedURLs(urls, out);
- return;
- }
- LOG(INFO) << "Unknown url: " << url.spec();
+ for (size_t pinned_index = 0; pinned_index < kTopSitesShown; pinned_index++) {
+ GURL url;
+ bool found = GetPinnedURLAtIndex(pinned_index, &url);
+ if (!found)
continue;
+
+ DCHECK(!url.is_empty());
+ int cur_index = IndexOf(urls_copy, url);
+ MostVisitedURL tmp;
+ if (cur_index < 0) {
+ // Pinned URL not in urls.
+ tmp.url = url;
+ } else {
+ tmp = urls_copy[cur_index];
+ urls_copy.erase(urls_copy.begin() + cur_index);
}
+ if (pinned_index > out->size())
+ out->resize(pinned_index); // Add empty URLs as fillers.
+ out->insert(out->begin() + pinned_index, tmp);
+ }
- size_t pinned_index = 0;
- bool result = GetIndexOfPinnedURL(url, &pinned_index);
- DCHECK(result) << url.spec();
- if (static_cast<int>(pinned_index) != index) {
- MostVisitedURL tmp = (*out)[index];
- out->erase(out->begin() + index);
- if (pinned_index > out->size())
- out->resize(pinned_index); // Add empty URLs as fillers.
- out->insert(out->begin() + pinned_index, tmp);
+ // Add non-pinned URLs in the empty spots.
+ size_t current_url = 0; // Index into the remaining URLs in urls_copy.
+ for (size_t i = 0; i < kTopSitesShown && current_url < urls_copy.size();
+ i++) {
+ if (i == out->size()) {
+ out->push_back(urls_copy[current_url]);
+ current_url++;
+ } else if (i < out->size()) {
+ if ((*out)[i].url.is_empty()) {
+ // Replace the filler
+ (*out)[i] = urls_copy[current_url];
+ current_url++;
+ }
+ } else {
+ NOTREACHED();
}
}
}
@@ -650,6 +662,7 @@ void TopSites::StartQueryForMostVisited() {
void TopSites::StartMigration() {
migration_in_progress_ = true;
StartQueryForMostVisited();
+ MigratePinnedURLs();
}
void TopSites::AddBlacklistedURL(const GURL& url) {
« no previous file with comments | « no previous file | chrome/browser/history/top_sites_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698