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

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

Issue 59903010: Ensure using chrome://thumb2/... adds the URL as a forced URL in TopSites so that a thumbnail is ca… (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Take 2. Created 7 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
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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_impl.h" 5 #include "chrome/browser/history/top_sites_impl.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 589 matching lines...) Expand 10 before | Expand all | Expand 10 after
600 url.redirects.push_back(url.url); 600 url.redirects.push_back(url.url);
601 url.title = l10n_util::GetStringUTF16(kPrepopulatedPages[i].title_id); 601 url.title = l10n_util::GetStringUTF16(kPrepopulatedPages[i].title_id);
602 } 602 }
603 return urls; 603 return urls;
604 } 604 }
605 605
606 bool TopSitesImpl::loaded() const { 606 bool TopSitesImpl::loaded() const {
607 return loaded_; 607 return loaded_;
608 } 608 }
609 609
610 bool TopSitesImpl::AddForcedURL(const GURL& url, const base::Time& time) {
611 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
612 size_t num_forced = cache_->GetNumForcedURLs();
613 MostVisitedURLList new_list(cache_->top_sites());
614 MostVisitedURL new_url;
615
616 if (cache_->IsKnownURL(url)) {
617 size_t index = cache_->GetURLIndex(url);
618 // Do nothing if we currently have that URL as non-forced.
619 if (new_list[index].last_forced_time.is_null())
620 return false;
621
622 // Update the |last_forced_time| of the already existing URL. Delete it and
623 // reinsert it at the right location.
624 new_url = new_list[index];
625 new_list.erase(new_list.begin() + index);
626 num_forced--;
627 } else {
628 new_url.url = url;
629 new_url.redirects.push_back(url);
630 }
631 new_url.last_forced_time = time;
632 // Add forced URLs and sort. Added to the end of the list of forced URLs
633 // since this is almost always where it needs to go, unless the user's local
634 // clock is fiddled with.
635 MostVisitedURLList::iterator mid = new_list.begin() + num_forced;
636 new_list.insert(mid, new_url);
637 mid = new_list.begin() + num_forced; // Mid was invalidated.
638 std::inplace_merge(new_list.begin(), mid, mid + 1, ForcedURLComparator);
639 SetTopSites(new_list);
640 return true;
641 }
642
610 bool TopSitesImpl::AddPrepopulatedPages(MostVisitedURLList* urls, 643 bool TopSitesImpl::AddPrepopulatedPages(MostVisitedURLList* urls,
611 size_t num_forced_urls) { 644 size_t num_forced_urls) {
612 bool added = false; 645 bool added = false;
613 MostVisitedURLList prepopulate_urls = GetPrepopulatePages(); 646 MostVisitedURLList prepopulate_urls = GetPrepopulatePages();
614 for (size_t i = 0; i < prepopulate_urls.size(); ++i) { 647 for (size_t i = 0; i < prepopulate_urls.size(); ++i) {
615 if (urls->size() - num_forced_urls < kNonForcedTopSitesNumber && 648 if (urls->size() - num_forced_urls < kNonForcedTopSitesNumber &&
616 IndexOf(*urls, prepopulate_urls[i].url) == -1) { 649 IndexOf(*urls, prepopulate_urls[i].url) == -1) {
617 urls->push_back(prepopulate_urls[i]); 650 urls->push_back(prepopulate_urls[i]);
618 added = true; 651 added = true;
619 } 652 }
(...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after
903 SetTopSites(pages); 936 SetTopSites(pages);
904 937
905 // Used only in testing. 938 // Used only in testing.
906 content::NotificationService::current()->Notify( 939 content::NotificationService::current()->Notify(
907 chrome::NOTIFICATION_TOP_SITES_UPDATED, 940 chrome::NOTIFICATION_TOP_SITES_UPDATED,
908 content::Source<TopSitesImpl>(this), 941 content::Source<TopSitesImpl>(this),
909 content::Details<CancelableRequestProvider::Handle>(&handle)); 942 content::Details<CancelableRequestProvider::Handle>(&handle));
910 } 943 }
911 944
912 } // namespace history 945 } // namespace history
OLDNEW
« no previous file with comments | « chrome/browser/history/top_sites_impl.h ('k') | chrome/browser/history/top_sites_impl_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698