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

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

Issue 3135035: Fix broken thumbnails for sites with redirects. (Closed)
Patch Set: Comment. Created 10 years, 4 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 | « chrome/browser/history/top_sites.h ('k') | 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) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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 231 matching lines...) Expand 10 before | Expand all | Expand 10 after
242 if (request->canceled()) 242 if (request->canceled())
243 return; 243 return;
244 244
245 ApplyBlacklistAndPinnedURLs(top_sites_, &filtered_urls); 245 ApplyBlacklistAndPinnedURLs(top_sites_, &filtered_urls);
246 } 246 }
247 request->ForwardResult(GetTopSitesCallback::TupleType(filtered_urls)); 247 request->ForwardResult(GetTopSitesCallback::TupleType(filtered_urls));
248 } 248 }
249 249
250 bool TopSites::GetPageThumbnail(const GURL& url, RefCountedBytes** data) const { 250 bool TopSites::GetPageThumbnail(const GURL& url, RefCountedBytes** data) const {
251 AutoLock lock(lock_); 251 AutoLock lock(lock_);
252 std::map<GURL, Images>::const_iterator found = top_images_.find(url); 252 std::map<GURL, Images>::const_iterator found =
253 top_images_.find(GetCanonicalURL(url));
253 if (found == top_images_.end()) { 254 if (found == top_images_.end()) {
254 found = temp_thumbnails_map_.find(url); 255 found = temp_thumbnails_map_.find(url);
255 if (found == temp_thumbnails_map_.end()) 256 if (found == temp_thumbnails_map_.end())
256 return false; // No thumbnail for this URL. 257 return false; // No thumbnail for this URL.
257 } 258 }
258 259
259 Images image = found->second; 260 Images image = found->second;
260 *data = image.thumbnail.get(); 261 *data = image.thumbnail.get();
261 return true; 262 return true;
262 } 263 }
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
372 } 373 }
373 } 374 }
374 375
375 std::string TopSites::GetURLString(const GURL& url) { 376 std::string TopSites::GetURLString(const GURL& url) {
376 lock_.AssertAcquired(); 377 lock_.AssertAcquired();
377 return GetCanonicalURL(url).spec(); 378 return GetCanonicalURL(url).spec();
378 } 379 }
379 380
380 std::string TopSites::GetURLHash(const GURL& url) { 381 std::string TopSites::GetURLHash(const GURL& url) {
381 lock_.AssertAcquired(); 382 lock_.AssertAcquired();
382 return MD5String(GetCanonicalURL(url).spec()); 383 // We don't use canonical URLs here to be able to blacklist only one of
384 // the two 'duplicate' sites, e.g. 'gmail.com' and 'mail.google.com'.
385 return MD5String(url.spec());
383 } 386 }
384 387
385 void TopSites::UpdateMostVisited(MostVisitedURLList most_visited) { 388 void TopSites::UpdateMostVisited(MostVisitedURLList most_visited) {
386 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::DB)); 389 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::DB));
387 390
388 std::vector<size_t> added; // Indices into most_visited. 391 std::vector<size_t> added; // Indices into most_visited.
389 std::vector<size_t> deleted; // Indices into top_sites_. 392 std::vector<size_t> deleted; // Indices into top_sites_.
390 std::vector<size_t> moved; // Indices into most_visited. 393 std::vector<size_t> moved; // Indices into most_visited.
391 394
392 DiffMostVisited(top_sites_, most_visited, &added, &deleted, &moved); 395 DiffMostVisited(top_sites_, most_visited, &added, &deleted, &moved);
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
558 561
559 void TopSites::StoreRedirectChain(const RedirectList& redirects, 562 void TopSites::StoreRedirectChain(const RedirectList& redirects,
560 size_t destination) { 563 size_t destination) {
561 lock_.AssertAcquired(); 564 lock_.AssertAcquired();
562 if (redirects.empty()) { 565 if (redirects.empty()) {
563 NOTREACHED(); 566 NOTREACHED();
564 return; 567 return;
565 } 568 }
566 569
567 // Map all the redirected URLs to the destination. 570 // Map all the redirected URLs to the destination.
568 for (size_t i = 0; i < redirects.size(); i++) 571 for (size_t i = 0; i < redirects.size(); i++) {
569 canonical_urls_[redirects[i]] = destination; 572 // If this redirect is already known, don't replace it with a new one.
573 if (canonical_urls_.find(redirects[i]) == canonical_urls_.end())
574 canonical_urls_[redirects[i]] = destination;
575 }
570 } 576 }
571 577
572 GURL TopSites::GetCanonicalURL(const GURL& url) const { 578 GURL TopSites::GetCanonicalURL(const GURL& url) const {
573 lock_.AssertAcquired(); 579 lock_.AssertAcquired();
574 std::map<GURL, size_t>::const_iterator found = canonical_urls_.find(url); 580 std::map<GURL, size_t>::const_iterator found = canonical_urls_.find(url);
575 if (found == canonical_urls_.end()) 581 if (found == canonical_urls_.end())
576 return url; // Unknown URL - return unchanged. 582 return url; // Unknown URL - return unchanged.
577 return top_sites_[found->second].url; 583 return top_sites_[found->second].url;
578 } 584 }
579 585
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
627 if (i->second != kAlreadyFoundMarker) 633 if (i->second != kAlreadyFoundMarker)
628 deleted_urls->push_back(i->second); 634 deleted_urls->push_back(i->second);
629 } 635 }
630 } 636 }
631 637
632 void TopSites::StartQueryForMostVisited() { 638 void TopSites::StartQueryForMostVisited() {
633 if (mock_history_service_) { 639 if (mock_history_service_) {
634 // Testing with a mockup. 640 // Testing with a mockup.
635 // QueryMostVisitedURLs is not virtual, so we have to duplicate the code. 641 // QueryMostVisitedURLs is not virtual, so we have to duplicate the code.
636 mock_history_service_->QueryMostVisitedURLs( 642 mock_history_service_->QueryMostVisitedURLs(
637 kTopSitesNumber, 643 kTopSitesNumber + blacklist_->size(),
638 kDaysOfHistory, 644 kDaysOfHistory,
639 &cancelable_consumer_, 645 &cancelable_consumer_,
640 NewCallback(this, &TopSites::OnTopSitesAvailable)); 646 NewCallback(this, &TopSites::OnTopSitesAvailable));
641 } else { 647 } else {
642 if (!profile_) 648 if (!profile_)
643 return; 649 return;
644 650
645 HistoryService* hs = profile_->GetHistoryService(Profile::EXPLICIT_ACCESS); 651 HistoryService* hs = profile_->GetHistoryService(Profile::EXPLICIT_ACCESS);
646 // |hs| may be null during unit tests. 652 // |hs| may be null during unit tests.
647 if (hs) { 653 if (hs) {
648 hs->QueryMostVisitedURLs( 654 hs->QueryMostVisitedURLs(
649 kTopSitesNumber, 655 kTopSitesNumber + blacklist_->size(),
650 kDaysOfHistory, 656 kDaysOfHistory,
651 &cancelable_consumer_, 657 &cancelable_consumer_,
652 NewCallback(this, &TopSites::OnTopSitesAvailable)); 658 NewCallback(this, &TopSites::OnTopSitesAvailable));
653 } else { 659 } else {
654 LOG(INFO) << "History Service not available."; 660 LOG(INFO) << "History Service not available.";
655 } 661 }
656 } 662 }
657 } 663 }
658 664
659 void TopSites::StartMigration() { 665 void TopSites::StartMigration() {
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
757 763
758 int64 range = kMaxUpdateIntervalMinutes - kMinUpdateIntervalMinutes; 764 int64 range = kMaxUpdateIntervalMinutes - kMinUpdateIntervalMinutes;
759 int64 minutes = kMaxUpdateIntervalMinutes - 765 int64 minutes = kMaxUpdateIntervalMinutes -
760 last_num_urls_changed_ * range / top_sites_.size(); 766 last_num_urls_changed_ * range / top_sites_.size();
761 return base::TimeDelta::FromMinutes(minutes); 767 return base::TimeDelta::FromMinutes(minutes);
762 } 768 }
763 769
764 void TopSites::OnTopSitesAvailable( 770 void TopSites::OnTopSitesAvailable(
765 CancelableRequestProvider::Handle handle, 771 CancelableRequestProvider::Handle handle,
766 MostVisitedURLList pages) { 772 MostVisitedURLList pages) {
767
768 AddPrepopulatedPages(&pages); 773 AddPrepopulatedPages(&pages);
769 ChromeThread::PostTask(ChromeThread::DB, FROM_HERE, NewRunnableMethod( 774 ChromeThread::PostTask(ChromeThread::DB, FROM_HERE, NewRunnableMethod(
770 this, &TopSites::UpdateMostVisited, pages)); 775 this, &TopSites::UpdateMostVisited, pages));
771 } 776 }
772 777
773 // static 778 // static
774 void TopSites::ProcessPendingCallbacks(PendingCallbackSet pending_callbacks, 779 void TopSites::ProcessPendingCallbacks(PendingCallbackSet pending_callbacks,
775 const MostVisitedURLList& urls) { 780 const MostVisitedURLList& urls) {
776 PendingCallbackSet::iterator i; 781 PendingCallbackSet::iterator i;
777 for (i = pending_callbacks.begin(); 782 for (i = pending_callbacks.begin();
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
874 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::DB)); 879 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::DB));
875 db_.reset(new TopSitesDatabaseImpl()); 880 db_.reset(new TopSitesDatabaseImpl());
876 file_util::Delete(db_path_, false); 881 file_util::Delete(db_path_, false);
877 if (!db_->Init(db_path_)) { 882 if (!db_->Init(db_path_)) {
878 NOTREACHED() << "Failed to initialize database."; 883 NOTREACHED() << "Failed to initialize database.";
879 return; 884 return;
880 } 885 }
881 } 886 }
882 887
883 } // namespace history 888 } // namespace history
OLDNEW
« no previous file with comments | « chrome/browser/history/top_sites.h ('k') | chrome/browser/history/top_sites_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698