| OLD | NEW |
| 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/bind.h" | 10 #include "base/bind.h" |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 #include "chrome/browser/ui/webui/ntp/most_visited_handler.h" | 25 #include "chrome/browser/ui/webui/ntp/most_visited_handler.h" |
| 26 #include "chrome/browser/ui/webui/ntp/new_tab_ui.h" | 26 #include "chrome/browser/ui/webui/ntp/new_tab_ui.h" |
| 27 #include "chrome/common/chrome_notification_types.h" | 27 #include "chrome/common/chrome_notification_types.h" |
| 28 #include "chrome/common/pref_names.h" | 28 #include "chrome/common/pref_names.h" |
| 29 #include "chrome/common/thumbnail_score.h" | 29 #include "chrome/common/thumbnail_score.h" |
| 30 #include "content/browser/browser_thread.h" | 30 #include "content/browser/browser_thread.h" |
| 31 #include "content/browser/tab_contents/navigation_controller.h" | 31 #include "content/browser/tab_contents/navigation_controller.h" |
| 32 #include "content/browser/tab_contents/navigation_details.h" | 32 #include "content/browser/tab_contents/navigation_details.h" |
| 33 #include "content/browser/tab_contents/navigation_entry.h" | 33 #include "content/browser/tab_contents/navigation_entry.h" |
| 34 #include "content/browser/tab_contents/tab_contents.h" | 34 #include "content/browser/tab_contents/tab_contents.h" |
| 35 #include "content/common/notification_service.h" | 35 #include "content/public/browser/notification_service.h" |
| 36 #include "grit/chromium_strings.h" | 36 #include "grit/chromium_strings.h" |
| 37 #include "grit/generated_resources.h" | 37 #include "grit/generated_resources.h" |
| 38 #include "grit/locale_settings.h" | 38 #include "grit/locale_settings.h" |
| 39 #include "ui/base/l10n/l10n_util.h" | 39 #include "ui/base/l10n/l10n_util.h" |
| 40 #include "ui/gfx/image/image_util.h" | 40 #include "ui/gfx/image/image_util.h" |
| 41 | 41 |
| 42 namespace history { | 42 namespace history { |
| 43 | 43 |
| 44 // How many top sites to store in the cache. | 44 // How many top sites to store in the cache. |
| 45 static const size_t kTopSitesNumber = 20; | 45 static const size_t kTopSitesNumber = 20; |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 141 profile_(profile), | 141 profile_(profile), |
| 142 last_num_urls_changed_(0), | 142 last_num_urls_changed_(0), |
| 143 blacklist_(NULL), | 143 blacklist_(NULL), |
| 144 pinned_urls_(NULL), | 144 pinned_urls_(NULL), |
| 145 history_state_(HISTORY_LOADING), | 145 history_state_(HISTORY_LOADING), |
| 146 top_sites_state_(TOP_SITES_LOADING), | 146 top_sites_state_(TOP_SITES_LOADING), |
| 147 loaded_(false) { | 147 loaded_(false) { |
| 148 if (!profile_) | 148 if (!profile_) |
| 149 return; | 149 return; |
| 150 | 150 |
| 151 if (NotificationService::current()) { | 151 if (content::NotificationService::current()) { |
| 152 registrar_.Add(this, chrome::NOTIFICATION_HISTORY_URLS_DELETED, | 152 registrar_.Add(this, chrome::NOTIFICATION_HISTORY_URLS_DELETED, |
| 153 content::Source<Profile>(profile_)); | 153 content::Source<Profile>(profile_)); |
| 154 // Listen for any nav commits. We'll ignore those not related to this | 154 // Listen for any nav commits. We'll ignore those not related to this |
| 155 // profile when we get the notification. | 155 // profile when we get the notification. |
| 156 registrar_.Add(this, content::NOTIFICATION_NAV_ENTRY_COMMITTED, | 156 registrar_.Add(this, content::NOTIFICATION_NAV_ENTRY_COMMITTED, |
| 157 NotificationService::AllSources()); | 157 content::NotificationService::AllSources()); |
| 158 } | 158 } |
| 159 | 159 |
| 160 // We create update objects here to be sure that dictionaries are created | 160 // We create update objects here to be sure that dictionaries are created |
| 161 // in the user preferences. | 161 // in the user preferences. |
| 162 DictionaryPrefUpdate(profile_->GetPrefs(), | 162 DictionaryPrefUpdate(profile_->GetPrefs(), |
| 163 prefs::kNTPMostVisitedURLsBlacklist).Get(); | 163 prefs::kNTPMostVisitedURLsBlacklist).Get(); |
| 164 DictionaryPrefUpdate(profile_->GetPrefs(), | 164 DictionaryPrefUpdate(profile_->GetPrefs(), |
| 165 prefs::kNTPMostVisitedPinnedURLs).Get(); | 165 prefs::kNTPMostVisitedPinnedURLs).Get(); |
| 166 | 166 |
| 167 // Now the dictionaries are guaranteed to exist and we can cache pointers | 167 // Now the dictionaries are guaranteed to exist and we can cache pointers |
| (...skipping 757 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 925 // Now that we're loaded we can service the queued up callbacks. Copy them | 925 // Now that we're loaded we can service the queued up callbacks. Copy them |
| 926 // here and service them outside the lock. | 926 // here and service them outside the lock. |
| 927 if (!pending_callbacks_.empty()) { | 927 if (!pending_callbacks_.empty()) { |
| 928 filtered_urls = thread_safe_cache_->top_sites(); | 928 filtered_urls = thread_safe_cache_->top_sites(); |
| 929 pending_callbacks.swap(pending_callbacks_); | 929 pending_callbacks.swap(pending_callbacks_); |
| 930 } | 930 } |
| 931 } | 931 } |
| 932 | 932 |
| 933 ProcessPendingCallbacks(pending_callbacks, filtered_urls); | 933 ProcessPendingCallbacks(pending_callbacks, filtered_urls); |
| 934 | 934 |
| 935 NotificationService::current()->Notify(chrome::NOTIFICATION_TOP_SITES_LOADED, | 935 content::NotificationService::current()->Notify( |
| 936 content::Source<Profile>(profile_), | 936 chrome::NOTIFICATION_TOP_SITES_LOADED, |
| 937 content::Details<TopSites>(this)); | 937 content::Source<Profile>(profile_), |
| 938 content::Details<TopSites>(this)); |
| 938 } | 939 } |
| 939 | 940 |
| 940 void TopSites::ResetThreadSafeCache() { | 941 void TopSites::ResetThreadSafeCache() { |
| 941 base::AutoLock lock(lock_); | 942 base::AutoLock lock(lock_); |
| 942 MostVisitedURLList cached; | 943 MostVisitedURLList cached; |
| 943 ApplyBlacklistAndPinnedURLs(cache_->top_sites(), &cached); | 944 ApplyBlacklistAndPinnedURLs(cache_->top_sites(), &cached); |
| 944 thread_safe_cache_->SetTopSites(cached); | 945 thread_safe_cache_->SetTopSites(cached); |
| 945 } | 946 } |
| 946 | 947 |
| 947 void TopSites::ResetThreadSafeImageCache() { | 948 void TopSites::ResetThreadSafeImageCache() { |
| 948 base::AutoLock lock(lock_); | 949 base::AutoLock lock(lock_); |
| 949 thread_safe_cache_->SetThumbnails(cache_->images()); | 950 thread_safe_cache_->SetThumbnails(cache_->images()); |
| 950 thread_safe_cache_->RemoveUnreferencedThumbnails(); | 951 thread_safe_cache_->RemoveUnreferencedThumbnails(); |
| 951 } | 952 } |
| 952 | 953 |
| 953 void TopSites::NotifyTopSitesChanged() { | 954 void TopSites::NotifyTopSitesChanged() { |
| 954 NotificationService::current()->Notify( | 955 content::NotificationService::current()->Notify( |
| 955 chrome::NOTIFICATION_TOP_SITES_CHANGED, | 956 chrome::NOTIFICATION_TOP_SITES_CHANGED, |
| 956 content::Source<TopSites>(this), | 957 content::Source<TopSites>(this), |
| 957 NotificationService::NoDetails()); | 958 content::NotificationService::NoDetails()); |
| 958 } | 959 } |
| 959 | 960 |
| 960 void TopSites::RestartQueryForTopSitesTimer(base::TimeDelta delta) { | 961 void TopSites::RestartQueryForTopSitesTimer(base::TimeDelta delta) { |
| 961 if (timer_.IsRunning() && ((timer_start_time_ + timer_.GetCurrentDelay()) < | 962 if (timer_.IsRunning() && ((timer_start_time_ + timer_.GetCurrentDelay()) < |
| 962 (base::TimeTicks::Now() + delta))) { | 963 (base::TimeTicks::Now() + delta))) { |
| 963 return; | 964 return; |
| 964 } | 965 } |
| 965 | 966 |
| 966 timer_start_time_ = base::TimeTicks::Now(); | 967 timer_start_time_ = base::TimeTicks::Now(); |
| 967 timer_.Stop(); | 968 timer_.Stop(); |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1018 } | 1019 } |
| 1019 } | 1020 } |
| 1020 } | 1021 } |
| 1021 | 1022 |
| 1022 void TopSites::OnTopSitesAvailableFromHistory( | 1023 void TopSites::OnTopSitesAvailableFromHistory( |
| 1023 CancelableRequestProvider::Handle handle, | 1024 CancelableRequestProvider::Handle handle, |
| 1024 MostVisitedURLList pages) { | 1025 MostVisitedURLList pages) { |
| 1025 SetTopSites(pages); | 1026 SetTopSites(pages); |
| 1026 | 1027 |
| 1027 // Used only in testing. | 1028 // Used only in testing. |
| 1028 NotificationService::current()->Notify( | 1029 content::NotificationService::current()->Notify( |
| 1029 chrome::NOTIFICATION_TOP_SITES_UPDATED, | 1030 chrome::NOTIFICATION_TOP_SITES_UPDATED, |
| 1030 content::Source<TopSites>(this), | 1031 content::Source<TopSites>(this), |
| 1031 content::Details<CancelableRequestProvider::Handle>(&handle)); | 1032 content::Details<CancelableRequestProvider::Handle>(&handle)); |
| 1032 } | 1033 } |
| 1033 | 1034 |
| 1034 } // namespace history | 1035 } // namespace history |
| OLD | NEW |