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

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

Issue 6142009: Upating the app, ceee, chrome, ipc, media, and net directories to use the correct lock.h file. (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Unified patch updating all references to the new base/synchronization/lock.h Created 9 years, 11 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/host_zoom_map.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 "app/l10n_util.h" 10 #include "app/l10n_util.h"
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after
218 void TopSites::GetMostVisitedURLs(CancelableRequestConsumer* consumer, 218 void TopSites::GetMostVisitedURLs(CancelableRequestConsumer* consumer,
219 GetTopSitesCallback* callback) { 219 GetTopSitesCallback* callback) {
220 // WARNING: this may be invoked on any thread. 220 // WARNING: this may be invoked on any thread.
221 scoped_refptr<CancelableRequest<GetTopSitesCallback> > request( 221 scoped_refptr<CancelableRequest<GetTopSitesCallback> > request(
222 new CancelableRequest<GetTopSitesCallback>(callback)); 222 new CancelableRequest<GetTopSitesCallback>(callback));
223 // This ensures cancellation of requests when either the consumer or the 223 // This ensures cancellation of requests when either the consumer or the
224 // provider is deleted. Deletion of requests is also guaranteed. 224 // provider is deleted. Deletion of requests is also guaranteed.
225 AddRequest(request, consumer); 225 AddRequest(request, consumer);
226 MostVisitedURLList filtered_urls; 226 MostVisitedURLList filtered_urls;
227 { 227 {
228 AutoLock lock(lock_); 228 base::AutoLock lock(lock_);
229 if (!loaded_) { 229 if (!loaded_) {
230 // A request came in before we finished loading. Put the request in 230 // A request came in before we finished loading. Put the request in
231 // pending_callbacks_ and we'll notify it when we finish loading. 231 // pending_callbacks_ and we'll notify it when we finish loading.
232 pending_callbacks_.insert(request); 232 pending_callbacks_.insert(request);
233 return; 233 return;
234 } 234 }
235 235
236 filtered_urls = thread_safe_cache_->top_sites(); 236 filtered_urls = thread_safe_cache_->top_sites();
237 } 237 }
238 request->ForwardResult(GetTopSitesCallback::TupleType(filtered_urls)); 238 request->ForwardResult(GetTopSitesCallback::TupleType(filtered_urls));
239 } 239 }
240 240
241 bool TopSites::GetPageThumbnail(const GURL& url, 241 bool TopSites::GetPageThumbnail(const GURL& url,
242 scoped_refptr<RefCountedBytes>* bytes) { 242 scoped_refptr<RefCountedBytes>* bytes) {
243 // WARNING: this may be invoked on any thread. 243 // WARNING: this may be invoked on any thread.
244 AutoLock lock(lock_); 244 base::AutoLock lock(lock_);
245 return thread_safe_cache_->GetPageThumbnail(url, bytes); 245 return thread_safe_cache_->GetPageThumbnail(url, bytes);
246 } 246 }
247 247
248 // Returns the index of |url| in |urls|, or -1 if not found. 248 // Returns the index of |url| in |urls|, or -1 if not found.
249 static int IndexOf(const MostVisitedURLList& urls, const GURL& url) { 249 static int IndexOf(const MostVisitedURLList& urls, const GURL& url) {
250 for (size_t i = 0; i < urls.size(); i++) { 250 for (size_t i = 0; i < urls.size(); i++) {
251 if (urls[i].url == url) 251 if (urls[i].url == url)
252 return i; 252 return i;
253 } 253 }
254 return -1; 254 return -1;
(...skipping 546 matching lines...) Expand 10 before | Expand all | Expand 10 after
801 801
802 return kTopSitesNumber + blacklist_->size(); 802 return kTopSitesNumber + blacklist_->size();
803 } 803 }
804 804
805 void TopSites::MoveStateToLoaded() { 805 void TopSites::MoveStateToLoaded() {
806 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 806 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
807 807
808 MostVisitedURLList filtered_urls; 808 MostVisitedURLList filtered_urls;
809 PendingCallbackSet pending_callbacks; 809 PendingCallbackSet pending_callbacks;
810 { 810 {
811 AutoLock lock(lock_); 811 base::AutoLock lock(lock_);
812 812
813 if (loaded_) 813 if (loaded_)
814 return; // Don't do anything if we're already loaded. 814 return; // Don't do anything if we're already loaded.
815 loaded_ = true; 815 loaded_ = true;
816 816
817 // Now that we're loaded we can service the queued up callbacks. Copy them 817 // Now that we're loaded we can service the queued up callbacks. Copy them
818 // here and service them outside the lock. 818 // here and service them outside the lock.
819 if (!pending_callbacks_.empty()) { 819 if (!pending_callbacks_.empty()) {
820 filtered_urls = thread_safe_cache_->top_sites(); 820 filtered_urls = thread_safe_cache_->top_sites();
821 pending_callbacks.swap(pending_callbacks_); 821 pending_callbacks.swap(pending_callbacks_);
822 } 822 }
823 } 823 }
824 824
825 ProcessPendingCallbacks(pending_callbacks, filtered_urls); 825 ProcessPendingCallbacks(pending_callbacks, filtered_urls);
826 826
827 NotificationService::current()->Notify(NotificationType::TOP_SITES_LOADED, 827 NotificationService::current()->Notify(NotificationType::TOP_SITES_LOADED,
828 Source<Profile>(profile_), 828 Source<Profile>(profile_),
829 Details<TopSites>(this)); 829 Details<TopSites>(this));
830 } 830 }
831 831
832 void TopSites::ResetThreadSafeCache() { 832 void TopSites::ResetThreadSafeCache() {
833 AutoLock lock(lock_); 833 base::AutoLock lock(lock_);
834 MostVisitedURLList cached; 834 MostVisitedURLList cached;
835 ApplyBlacklistAndPinnedURLs(cache_->top_sites(), &cached); 835 ApplyBlacklistAndPinnedURLs(cache_->top_sites(), &cached);
836 thread_safe_cache_->SetTopSites(cached); 836 thread_safe_cache_->SetTopSites(cached);
837 } 837 }
838 838
839 void TopSites::ResetThreadSafeImageCache() { 839 void TopSites::ResetThreadSafeImageCache() {
840 AutoLock lock(lock_); 840 base::AutoLock lock(lock_);
841 thread_safe_cache_->SetThumbnails(cache_->images()); 841 thread_safe_cache_->SetThumbnails(cache_->images());
842 thread_safe_cache_->RemoveUnreferencedThumbnails(); 842 thread_safe_cache_->RemoveUnreferencedThumbnails();
843 } 843 }
844 844
845 void TopSites::RestartQueryForTopSitesTimer(base::TimeDelta delta) { 845 void TopSites::RestartQueryForTopSitesTimer(base::TimeDelta delta) {
846 if (timer_.IsRunning() && ((timer_start_time_ + timer_.GetCurrentDelay()) < 846 if (timer_.IsRunning() && ((timer_start_time_ + timer_.GetCurrentDelay()) <
847 (base::TimeTicks::Now() + delta))) { 847 (base::TimeTicks::Now() + delta))) {
848 return; 848 return;
849 } 849 }
850 850
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
910 SetTopSites(pages); 910 SetTopSites(pages);
911 911
912 // Used only in testing. 912 // Used only in testing.
913 NotificationService::current()->Notify( 913 NotificationService::current()->Notify(
914 NotificationType::TOP_SITES_UPDATED, 914 NotificationType::TOP_SITES_UPDATED,
915 Source<TopSites>(this), 915 Source<TopSites>(this),
916 Details<CancelableRequestProvider::Handle>(&handle)); 916 Details<CancelableRequestProvider::Handle>(&handle));
917 } 917 }
918 918
919 } // namespace history 919 } // namespace history
OLDNEW
« no previous file with comments | « chrome/browser/history/top_sites.h ('k') | chrome/browser/host_zoom_map.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698