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

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

Issue 6901110: GTK: Query TopSites for the Most Visited pages and populate fill in the global History menu. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Make TopSites broadcast its change notification on all blacklist/pinned url changes. Created 9 years, 8 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 | Annotate | Revision Log
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/command_line.h" 10 #include "base/command_line.h"
(...skipping 814 matching lines...) Expand 10 before | Expand all | Expand 10 after
825 } 825 }
826 } 826 }
827 } 827 }
828 828
829 void TopSites::SetTopSites(const MostVisitedURLList& new_top_sites) { 829 void TopSites::SetTopSites(const MostVisitedURLList& new_top_sites) {
830 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 830 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
831 831
832 MostVisitedURLList top_sites(new_top_sites); 832 MostVisitedURLList top_sites(new_top_sites);
833 AddPrepopulatedPages(&top_sites); 833 AddPrepopulatedPages(&top_sites);
834 834
835 bool changed = false;
836 TopSitesDelta delta; 835 TopSitesDelta delta;
837 DiffMostVisited(cache_->top_sites(), top_sites, &delta); 836 DiffMostVisited(cache_->top_sites(), top_sites, &delta);
838 if (!delta.deleted.empty() || !delta.added.empty() || !delta.moved.empty()) { 837 if (!delta.deleted.empty() || !delta.added.empty() || !delta.moved.empty()) {
839 changed = true;
840 backend_->UpdateTopSites(delta); 838 backend_->UpdateTopSites(delta);
841 } 839 }
842 840
843 last_num_urls_changed_ = delta.added.size() + delta.moved.size(); 841 last_num_urls_changed_ = delta.added.size() + delta.moved.size();
844 842
845 // We always do the following steps (setting top sites in cache, and resetting 843 // We always do the following steps (setting top sites in cache, and resetting
846 // thread safe cache ...) as this method is invoked during startup at which 844 // thread safe cache ...) as this method is invoked during startup at which
847 // point the caches haven't been updated yet. 845 // point the caches haven't been updated yet.
848 cache_->SetTopSites(top_sites); 846 cache_->SetTopSites(top_sites);
849 847
850 // See if we have any tmp thumbnails for the new sites. 848 // See if we have any tmp thumbnails for the new sites.
851 if (!temp_images_.empty()) { 849 if (!temp_images_.empty()) {
852 for (size_t i = 0; i < top_sites.size(); ++i) { 850 for (size_t i = 0; i < top_sites.size(); ++i) {
853 const MostVisitedURL& mv = top_sites[i]; 851 const MostVisitedURL& mv = top_sites[i];
854 GURL canonical_url = cache_->GetCanonicalURL(mv.url); 852 GURL canonical_url = cache_->GetCanonicalURL(mv.url);
855 // At the time we get the thumbnail redirects aren't known, so we have to 853 // At the time we get the thumbnail redirects aren't known, so we have to
856 // iterate through all the images. 854 // iterate through all the images.
857 for (TempImages::iterator it = temp_images_.begin(); 855 for (TempImages::iterator it = temp_images_.begin();
858 it != temp_images_.end(); ++it) { 856 it != temp_images_.end(); ++it) {
859 if (canonical_url == cache_->GetCanonicalURL(it->first)) { 857 if (canonical_url == cache_->GetCanonicalURL(it->first)) {
860 SetPageThumbnailEncoded(mv.url, 858 SetPageThumbnailEncoded(mv.url,
861 it->second.thumbnail, 859 it->second.thumbnail,
862 it->second.thumbnail_score); 860 it->second.thumbnail_score);
863 changed = true;
864 temp_images_.erase(it); 861 temp_images_.erase(it);
865 break; 862 break;
866 } 863 }
867 } 864 }
868 } 865 }
869 } 866 }
870 867
871 if (top_sites.size() >= kTopSitesNumber) 868 if (top_sites.size() >= kTopSitesNumber)
872 temp_images_.clear(); 869 temp_images_.clear();
873 870
871 ResetThreadSafeImageCache();
sky 2011/04/28 22:31:43 We need to set the images after the cache.
Elliot Glaysher 2011/04/28 23:08:35 Reworked so sending the notification is its own fu
874 ResetThreadSafeCache(); 872 ResetThreadSafeCache();
875 ResetThreadSafeImageCache();
876
877 if (changed) {
878 NotificationService::current()->Notify(
879 NotificationType::TOP_SITES_CHANGED,
880 Source<TopSites>(this),
881 NotificationService::NoDetails());
882 }
883 873
884 // Restart the timer that queries history for top sites. This is done to 874 // Restart the timer that queries history for top sites. This is done to
885 // ensure we stay in sync with history. 875 // ensure we stay in sync with history.
886 RestartQueryForTopSitesTimer(GetUpdateDelay()); 876 RestartQueryForTopSitesTimer(GetUpdateDelay());
887 } 877 }
888 878
889 int TopSites::num_results_to_request_from_history() const { 879 int TopSites::num_results_to_request_from_history() const {
890 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 880 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
891 881
892 return kTopSitesNumber + blacklist_->size(); 882 return kTopSitesNumber + blacklist_->size();
(...skipping 20 matching lines...) Expand all
913 } 903 }
914 904
915 ProcessPendingCallbacks(pending_callbacks, filtered_urls); 905 ProcessPendingCallbacks(pending_callbacks, filtered_urls);
916 906
917 NotificationService::current()->Notify(NotificationType::TOP_SITES_LOADED, 907 NotificationService::current()->Notify(NotificationType::TOP_SITES_LOADED,
918 Source<Profile>(profile_), 908 Source<Profile>(profile_),
919 Details<TopSites>(this)); 909 Details<TopSites>(this));
920 } 910 }
921 911
922 void TopSites::ResetThreadSafeCache() { 912 void TopSites::ResetThreadSafeCache() {
923 base::AutoLock lock(lock_); 913 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
924 MostVisitedURLList cached; 914
925 ApplyBlacklistAndPinnedURLs(cache_->top_sites(), &cached); 915 {
926 thread_safe_cache_->SetTopSites(cached); 916 base::AutoLock lock(lock_);
917 MostVisitedURLList cached;
918 ApplyBlacklistAndPinnedURLs(cache_->top_sites(), &cached);
919 thread_safe_cache_->SetTopSites(cached);
920 }
921
922 NotificationService::current()->Notify(
923 NotificationType::TOP_SITES_CHANGED,
Evan Stade 2011/04/28 22:40:21 p.s. this is something the most visited handler fo
Elliot Glaysher 2011/04/28 23:08:35 sky added this notification earlier today. I was s
924 Source<TopSites>(this),
925 NotificationService::NoDetails());
927 } 926 }
928 927
929 void TopSites::ResetThreadSafeImageCache() { 928 void TopSites::ResetThreadSafeImageCache() {
930 base::AutoLock lock(lock_); 929 base::AutoLock lock(lock_);
931 thread_safe_cache_->SetThumbnails(cache_->images()); 930 thread_safe_cache_->SetThumbnails(cache_->images());
932 thread_safe_cache_->RemoveUnreferencedThumbnails(); 931 thread_safe_cache_->RemoveUnreferencedThumbnails();
933 } 932 }
934 933
935 void TopSites::RestartQueryForTopSitesTimer(base::TimeDelta delta) { 934 void TopSites::RestartQueryForTopSitesTimer(base::TimeDelta delta) {
936 if (timer_.IsRunning() && ((timer_start_time_ + timer_.GetCurrentDelay()) < 935 if (timer_.IsRunning() && ((timer_start_time_ + timer_.GetCurrentDelay()) <
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
1000 SetTopSites(pages); 999 SetTopSites(pages);
1001 1000
1002 // Used only in testing. 1001 // Used only in testing.
1003 NotificationService::current()->Notify( 1002 NotificationService::current()->Notify(
1004 NotificationType::TOP_SITES_UPDATED, 1003 NotificationType::TOP_SITES_UPDATED,
1005 Source<TopSites>(this), 1004 Source<TopSites>(this),
1006 Details<CancelableRequestProvider::Handle>(&handle)); 1005 Details<CancelableRequestProvider::Handle>(&handle));
1007 } 1006 }
1008 1007
1009 } // namespace history 1008 } // namespace history
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/ui/gtk/global_history_menu.h » ('j') | chrome/browser/ui/gtk/global_history_menu.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698