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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « no previous file | chrome/browser/history/top_sites_unittest.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 (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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 8
9 #include "app/l10n_util.h" 9 #include "app/l10n_util.h"
10 #include "base/command_line.h" 10 #include "base/command_line.h"
(...skipping 352 matching lines...) Expand 10 before | Expand all | Expand 10 after
363 } 363 }
364 } 364 }
365 pinned_urls_->Clear(); 365 pinned_urls_->Clear();
366 for (std::map<GURL, size_t>::iterator it = tmp_map.begin(); 366 for (std::map<GURL, size_t>::iterator it = tmp_map.begin();
367 it != tmp_map.end(); ++it) 367 it != tmp_map.end(); ++it)
368 AddPinnedURL(it->first, it->second); 368 AddPinnedURL(it->first, it->second);
369 } 369 }
370 370
371 void TopSites::ApplyBlacklistAndPinnedURLs(const MostVisitedURLList& urls, 371 void TopSites::ApplyBlacklistAndPinnedURLs(const MostVisitedURLList& urls,
372 MostVisitedURLList* out) { 372 MostVisitedURLList* out) {
373 MostVisitedURLList urls_copy;
373 for (size_t i = 0; i < urls.size(); i++) { 374 for (size_t i = 0; i < urls.size(); i++) {
374 if (!IsBlacklisted(urls[i].url)) 375 if (!IsBlacklisted(urls[i].url))
375 out->push_back(urls[i]); 376 urls_copy.push_back(urls[i]);
376 } 377 }
377 378
378 for (DictionaryValue::key_iterator it = pinned_urls_->begin_keys(); 379 for (size_t pinned_index = 0; pinned_index < kTopSitesShown; pinned_index++) {
379 it != pinned_urls_->end_keys(); ++it) { 380 GURL url;
380 GURL url(WideToASCII(*it)); 381 bool found = GetPinnedURLAtIndex(pinned_index, &url);
382 if (!found)
383 continue;
381 384
382 int index = IndexOf(*out, url); 385 DCHECK(!url.is_empty());
383 if (index == -1) { 386 int cur_index = IndexOf(urls_copy, url);
384 if (url.is_empty()) { 387 MostVisitedURL tmp;
385 MigratePinnedURLs(); 388 if (cur_index < 0) {
386 out->clear(); 389 // Pinned URL not in urls.
387 ApplyBlacklistAndPinnedURLs(urls, out); 390 tmp.url = url;
388 return; 391 } else {
392 tmp = urls_copy[cur_index];
393 urls_copy.erase(urls_copy.begin() + cur_index);
394 }
395 if (pinned_index > out->size())
396 out->resize(pinned_index); // Add empty URLs as fillers.
397 out->insert(out->begin() + pinned_index, tmp);
398 }
399
400 // Add non-pinned URLs in the empty spots.
401 size_t current_url = 0; // Index into the remaining URLs in urls_copy.
402 for (size_t i = 0; i < kTopSitesShown && current_url < urls_copy.size();
403 i++) {
404 if (i == out->size()) {
405 out->push_back(urls_copy[current_url]);
406 current_url++;
407 } else if (i < out->size()) {
408 if ((*out)[i].url.is_empty()) {
409 // Replace the filler
410 (*out)[i] = urls_copy[current_url];
411 current_url++;
389 } 412 }
390 LOG(INFO) << "Unknown url: " << url.spec(); 413 } else {
391 continue; 414 NOTREACHED();
392 }
393
394 size_t pinned_index = 0;
395 bool result = GetIndexOfPinnedURL(url, &pinned_index);
396 DCHECK(result) << url.spec();
397 if (static_cast<int>(pinned_index) != index) {
398 MostVisitedURL tmp = (*out)[index];
399 out->erase(out->begin() + index);
400 if (pinned_index > out->size())
401 out->resize(pinned_index); // Add empty URLs as fillers.
402 out->insert(out->begin() + pinned_index, tmp);
403 } 415 }
404 } 416 }
405 } 417 }
406 418
407 std::wstring TopSites::GetURLString(const GURL& url) { 419 std::wstring TopSites::GetURLString(const GURL& url) {
408 return ASCIIToWide(GetCanonicalURL(url).spec()); 420 return ASCIIToWide(GetCanonicalURL(url).spec());
409 } 421 }
410 422
411 std::wstring TopSites::GetURLHash(const GURL& url) { 423 std::wstring TopSites::GetURLHash(const GURL& url) {
412 return ASCIIToWide(MD5String(GetCanonicalURL(url).spec())); 424 return ASCIIToWide(MD5String(GetCanonicalURL(url).spec()));
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after
643 NewCallback(this, &TopSites::OnTopSitesAvailable)); 655 NewCallback(this, &TopSites::OnTopSitesAvailable));
644 } else { 656 } else {
645 LOG(INFO) << "History Service not available."; 657 LOG(INFO) << "History Service not available.";
646 } 658 }
647 } 659 }
648 } 660 }
649 661
650 void TopSites::StartMigration() { 662 void TopSites::StartMigration() {
651 migration_in_progress_ = true; 663 migration_in_progress_ = true;
652 StartQueryForMostVisited(); 664 StartQueryForMostVisited();
665 MigratePinnedURLs();
653 } 666 }
654 667
655 void TopSites::AddBlacklistedURL(const GURL& url) { 668 void TopSites::AddBlacklistedURL(const GURL& url) {
656 RemovePinnedURL(url); 669 RemovePinnedURL(url);
657 Value* dummy = Value::CreateNullValue(); 670 Value* dummy = Value::CreateNullValue();
658 blacklist_->SetWithoutPathExpansion(GetURLHash(url), dummy); 671 blacklist_->SetWithoutPathExpansion(GetURLHash(url), dummy);
659 } 672 }
660 673
661 bool TopSites::IsBlacklisted(const GURL& url) { 674 bool TopSites::IsBlacklisted(const GURL& url) {
662 bool result = blacklist_->HasKey(GetURLHash(url)); 675 bool result = blacklist_->HasKey(GetURLHash(url));
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
826 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::DB)); 839 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::DB));
827 db_.reset(new TopSitesDatabaseImpl()); 840 db_.reset(new TopSitesDatabaseImpl());
828 file_util::Delete(db_path_, false); 841 file_util::Delete(db_path_, false);
829 if (!db_->Init(db_path_)) { 842 if (!db_->Init(db_path_)) {
830 NOTREACHED() << "Failed to initialize database."; 843 NOTREACHED() << "Failed to initialize database.";
831 return; 844 return;
832 } 845 }
833 } 846 }
834 847
835 } // namespace history 848 } // namespace history
OLDNEW
« 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