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

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

Issue 7327007: Moving notification types which are chrome specific to a new header file chrome_notification_type... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 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 | Annotate | Revision Log
« no previous file with comments | « chrome/browser/history/top_sites.h ('k') | chrome/browser/importer/importer_host.h » ('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) 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"
11 #include "base/logging.h" 11 #include "base/logging.h"
12 #include "base/md5.h" 12 #include "base/md5.h"
13 #include "base/string_util.h" 13 #include "base/string_util.h"
14 #include "base/utf_string_conversions.h" 14 #include "base/utf_string_conversions.h"
15 #include "base/values.h" 15 #include "base/values.h"
16 #include "chrome/browser/history/history_backend.h" 16 #include "chrome/browser/history/history_backend.h"
17 #include "chrome/browser/history/history_notifications.h" 17 #include "chrome/browser/history/history_notifications.h"
18 #include "chrome/browser/history/page_usage_data.h" 18 #include "chrome/browser/history/page_usage_data.h"
19 #include "chrome/browser/history/top_sites_backend.h" 19 #include "chrome/browser/history/top_sites_backend.h"
20 #include "chrome/browser/history/top_sites_cache.h" 20 #include "chrome/browser/history/top_sites_cache.h"
21 #include "chrome/browser/prefs/pref_service.h" 21 #include "chrome/browser/prefs/pref_service.h"
22 #include "chrome/browser/prefs/scoped_user_pref_update.h" 22 #include "chrome/browser/prefs/scoped_user_pref_update.h"
23 #include "chrome/browser/profiles/profile.h" 23 #include "chrome/browser/profiles/profile.h"
24 #include "chrome/browser/ui/webui/ntp/most_visited_handler.h" 24 #include "chrome/browser/ui/webui/ntp/most_visited_handler.h"
25 #include "chrome/common/chrome_notification_types.h"
25 #include "chrome/common/chrome_switches.h" 26 #include "chrome/common/chrome_switches.h"
26 #include "chrome/common/pref_names.h" 27 #include "chrome/common/pref_names.h"
27 #include "chrome/common/thumbnail_score.h" 28 #include "chrome/common/thumbnail_score.h"
28 #include "content/browser/browser_thread.h" 29 #include "content/browser/browser_thread.h"
29 #include "content/browser/tab_contents/navigation_details.h" 30 #include "content/browser/tab_contents/navigation_details.h"
30 #include "content/browser/tab_contents/navigation_entry.h" 31 #include "content/browser/tab_contents/navigation_entry.h"
31 #include "content/common/notification_service.h" 32 #include "content/common/notification_service.h"
32 #include "grit/chromium_strings.h" 33 #include "grit/chromium_strings.h"
33 #include "grit/generated_resources.h" 34 #include "grit/generated_resources.h"
34 #include "grit/locale_settings.h" 35 #include "grit/locale_settings.h"
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
135 last_num_urls_changed_(0), 136 last_num_urls_changed_(0),
136 blacklist_(NULL), 137 blacklist_(NULL),
137 pinned_urls_(NULL), 138 pinned_urls_(NULL),
138 history_state_(HISTORY_LOADING), 139 history_state_(HISTORY_LOADING),
139 top_sites_state_(TOP_SITES_LOADING), 140 top_sites_state_(TOP_SITES_LOADING),
140 loaded_(false) { 141 loaded_(false) {
141 if (!profile_) 142 if (!profile_)
142 return; 143 return;
143 144
144 if (NotificationService::current()) { 145 if (NotificationService::current()) {
145 registrar_.Add(this, NotificationType::HISTORY_URLS_DELETED, 146 registrar_.Add(this, chrome::NOTIFICATION_HISTORY_URLS_DELETED,
146 Source<Profile>(profile_)); 147 Source<Profile>(profile_));
147 registrar_.Add(this, NotificationType::NAV_ENTRY_COMMITTED, 148 registrar_.Add(this, content::NOTIFICATION_NAV_ENTRY_COMMITTED,
148 NotificationService::AllSources()); 149 NotificationService::AllSources());
149 } 150 }
150 151
151 // We create update objects here to be sure that dictionaries are created 152 // We create update objects here to be sure that dictionaries are created
152 // in the user preferences. 153 // in the user preferences.
153 DictionaryPrefUpdate(profile_->GetPrefs(), 154 DictionaryPrefUpdate(profile_->GetPrefs(),
154 prefs::kNTPMostVisitedURLsBlacklist).Get(); 155 prefs::kNTPMostVisitedURLsBlacklist).Get();
155 DictionaryPrefUpdate(profile_->GetPrefs(), 156 DictionaryPrefUpdate(profile_->GetPrefs(),
156 prefs::kNTPMostVisitedPinnedURLs).Get(); 157 prefs::kNTPMostVisitedPinnedURLs).Get();
157 158
(...skipping 619 matching lines...) Expand 10 before | Expand all | Expand 10 after
777 const MostVisitedURLList& urls) { 778 const MostVisitedURLList& urls) {
778 PendingCallbackSet::const_iterator i; 779 PendingCallbackSet::const_iterator i;
779 for (i = pending_callbacks.begin(); 780 for (i = pending_callbacks.begin();
780 i != pending_callbacks.end(); ++i) { 781 i != pending_callbacks.end(); ++i) {
781 scoped_refptr<CancelableRequest<GetTopSitesCallback> > request = *i; 782 scoped_refptr<CancelableRequest<GetTopSitesCallback> > request = *i;
782 if (!request->canceled()) 783 if (!request->canceled())
783 request->ForwardResult(GetTopSitesCallback::TupleType(urls)); 784 request->ForwardResult(GetTopSitesCallback::TupleType(urls));
784 } 785 }
785 } 786 }
786 787
787 void TopSites::Observe(NotificationType type, 788 void TopSites::Observe(int type,
788 const NotificationSource& source, 789 const NotificationSource& source,
789 const NotificationDetails& details) { 790 const NotificationDetails& details) {
790 if (!loaded_) 791 if (!loaded_)
791 return; 792 return;
792 793
793 if (type == NotificationType::HISTORY_URLS_DELETED) { 794 if (type == chrome::NOTIFICATION_HISTORY_URLS_DELETED) {
794 Details<history::URLsDeletedDetails> deleted_details(details); 795 Details<history::URLsDeletedDetails> deleted_details(details);
795 if (deleted_details->all_history) { 796 if (deleted_details->all_history) {
796 SetTopSites(MostVisitedURLList()); 797 SetTopSites(MostVisitedURLList());
797 backend_->ResetDatabase(); 798 backend_->ResetDatabase();
798 } else { 799 } else {
799 std::set<size_t> indices_to_delete; // Indices into top_sites_. 800 std::set<size_t> indices_to_delete; // Indices into top_sites_.
800 for (std::set<GURL>::iterator i = deleted_details->urls.begin(); 801 for (std::set<GURL>::iterator i = deleted_details->urls.begin();
801 i != deleted_details->urls.end(); ++i) { 802 i != deleted_details->urls.end(); ++i) {
802 if (cache_->IsKnownURL(*i)) 803 if (cache_->IsKnownURL(*i))
803 indices_to_delete.insert(cache_->GetURLIndex(*i)); 804 indices_to_delete.insert(cache_->GetURLIndex(*i));
804 } 805 }
805 806
806 if (indices_to_delete.empty()) 807 if (indices_to_delete.empty())
807 return; 808 return;
808 809
809 MostVisitedURLList new_top_sites(cache_->top_sites()); 810 MostVisitedURLList new_top_sites(cache_->top_sites());
810 for (std::set<size_t>::reverse_iterator i = indices_to_delete.rbegin(); 811 for (std::set<size_t>::reverse_iterator i = indices_to_delete.rbegin();
811 i != indices_to_delete.rend(); i++) { 812 i != indices_to_delete.rend(); i++) {
812 size_t index = *i; 813 size_t index = *i;
813 RemovePinnedURL(new_top_sites[index].url); 814 RemovePinnedURL(new_top_sites[index].url);
814 new_top_sites.erase(new_top_sites.begin() + index); 815 new_top_sites.erase(new_top_sites.begin() + index);
815 } 816 }
816 SetTopSites(new_top_sites); 817 SetTopSites(new_top_sites);
817 } 818 }
818 StartQueryForMostVisited(); 819 StartQueryForMostVisited();
819 } else if (type == NotificationType::NAV_ENTRY_COMMITTED) { 820 } else if (type == content::NOTIFICATION_NAV_ENTRY_COMMITTED) {
820 if (!IsFull()) { 821 if (!IsFull()) {
821 content::LoadCommittedDetails* load_details = 822 content::LoadCommittedDetails* load_details =
822 Details<content::LoadCommittedDetails>(details).ptr(); 823 Details<content::LoadCommittedDetails>(details).ptr();
823 if (!load_details) 824 if (!load_details)
824 return; 825 return;
825 const GURL& url = load_details->entry->url(); 826 const GURL& url = load_details->entry->url();
826 if (!cache_->IsKnownURL(url) && HistoryService::CanAddURL(url)) { 827 if (!cache_->IsKnownURL(url) && HistoryService::CanAddURL(url)) {
827 // To avoid slamming history we throttle requests when the url updates. 828 // To avoid slamming history we throttle requests when the url updates.
828 // To do otherwise negatively impacts perf tests. 829 // To do otherwise negatively impacts perf tests.
829 RestartQueryForTopSitesTimer(GetUpdateDelay()); 830 RestartQueryForTopSitesTimer(GetUpdateDelay());
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
904 // Now that we're loaded we can service the queued up callbacks. Copy them 905 // Now that we're loaded we can service the queued up callbacks. Copy them
905 // here and service them outside the lock. 906 // here and service them outside the lock.
906 if (!pending_callbacks_.empty()) { 907 if (!pending_callbacks_.empty()) {
907 filtered_urls = thread_safe_cache_->top_sites(); 908 filtered_urls = thread_safe_cache_->top_sites();
908 pending_callbacks.swap(pending_callbacks_); 909 pending_callbacks.swap(pending_callbacks_);
909 } 910 }
910 } 911 }
911 912
912 ProcessPendingCallbacks(pending_callbacks, filtered_urls); 913 ProcessPendingCallbacks(pending_callbacks, filtered_urls);
913 914
914 NotificationService::current()->Notify(NotificationType::TOP_SITES_LOADED, 915 NotificationService::current()->Notify(chrome::NOTIFICATION_TOP_SITES_LOADED,
915 Source<Profile>(profile_), 916 Source<Profile>(profile_),
916 Details<TopSites>(this)); 917 Details<TopSites>(this));
917 } 918 }
918 919
919 void TopSites::ResetThreadSafeCache() { 920 void TopSites::ResetThreadSafeCache() {
920 base::AutoLock lock(lock_); 921 base::AutoLock lock(lock_);
921 MostVisitedURLList cached; 922 MostVisitedURLList cached;
922 ApplyBlacklistAndPinnedURLs(cache_->top_sites(), &cached); 923 ApplyBlacklistAndPinnedURLs(cache_->top_sites(), &cached);
923 thread_safe_cache_->SetTopSites(cached); 924 thread_safe_cache_->SetTopSites(cached);
924 } 925 }
925 926
926 void TopSites::ResetThreadSafeImageCache() { 927 void TopSites::ResetThreadSafeImageCache() {
927 base::AutoLock lock(lock_); 928 base::AutoLock lock(lock_);
928 thread_safe_cache_->SetThumbnails(cache_->images()); 929 thread_safe_cache_->SetThumbnails(cache_->images());
929 thread_safe_cache_->RemoveUnreferencedThumbnails(); 930 thread_safe_cache_->RemoveUnreferencedThumbnails();
930 } 931 }
931 932
932 void TopSites::NotifyTopSitesChanged() { 933 void TopSites::NotifyTopSitesChanged() {
933 NotificationService::current()->Notify( 934 NotificationService::current()->Notify(
934 NotificationType::TOP_SITES_CHANGED, 935 chrome::NOTIFICATION_TOP_SITES_CHANGED,
935 Source<TopSites>(this), 936 Source<TopSites>(this),
936 NotificationService::NoDetails()); 937 NotificationService::NoDetails());
937 } 938 }
938 939
939 void TopSites::RestartQueryForTopSitesTimer(base::TimeDelta delta) { 940 void TopSites::RestartQueryForTopSitesTimer(base::TimeDelta delta) {
940 if (timer_.IsRunning() && ((timer_start_time_ + timer_.GetCurrentDelay()) < 941 if (timer_.IsRunning() && ((timer_start_time_ + timer_.GetCurrentDelay()) <
941 (base::TimeTicks::Now() + delta))) { 942 (base::TimeTicks::Now() + delta))) {
942 return; 943 return;
943 } 944 }
944 945
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
998 } 999 }
999 } 1000 }
1000 1001
1001 void TopSites::OnTopSitesAvailableFromHistory( 1002 void TopSites::OnTopSitesAvailableFromHistory(
1002 CancelableRequestProvider::Handle handle, 1003 CancelableRequestProvider::Handle handle,
1003 MostVisitedURLList pages) { 1004 MostVisitedURLList pages) {
1004 SetTopSites(pages); 1005 SetTopSites(pages);
1005 1006
1006 // Used only in testing. 1007 // Used only in testing.
1007 NotificationService::current()->Notify( 1008 NotificationService::current()->Notify(
1008 NotificationType::TOP_SITES_UPDATED, 1009 chrome::NOTIFICATION_TOP_SITES_UPDATED,
1009 Source<TopSites>(this), 1010 Source<TopSites>(this),
1010 Details<CancelableRequestProvider::Handle>(&handle)); 1011 Details<CancelableRequestProvider::Handle>(&handle));
1011 } 1012 }
1012 1013
1013 } // namespace history 1014 } // namespace history
OLDNEW
« no previous file with comments | « chrome/browser/history/top_sites.h ('k') | chrome/browser/importer/importer_host.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698