Chromium Code Reviews| 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/command_line.h" | 10 #include "base/command_line.h" |
| (...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 238 return; | 238 return; |
| 239 } | 239 } |
| 240 | 240 |
| 241 filtered_urls = thread_safe_cache_->top_sites(); | 241 filtered_urls = thread_safe_cache_->top_sites(); |
| 242 } | 242 } |
| 243 request->ForwardResult(GetTopSitesCallback::TupleType(filtered_urls)); | 243 request->ForwardResult(GetTopSitesCallback::TupleType(filtered_urls)); |
| 244 } | 244 } |
| 245 | 245 |
| 246 bool TopSites::GetPageThumbnail(const GURL& url, | 246 bool TopSites::GetPageThumbnail(const GURL& url, |
| 247 scoped_refptr<RefCountedBytes>* bytes) { | 247 scoped_refptr<RefCountedBytes>* bytes) { |
| 248 // The thumbnail may be found in the temporary images. | |
|
sky
2011/04/08 15:59:07
This breaks the thread safety of this class.
satorux1
2011/04/09 02:36:51
My bad. I missed WARNING. Moved the lock to the b
| |
| 249 for (TempImages::iterator i = temp_images_.begin(); i != temp_images_.end(); | |
| 250 ++i) { | |
| 251 if (i->first == url) { | |
| 252 *bytes = i->second.thumbnail; | |
| 253 return true; | |
| 254 } | |
| 255 } | |
| 256 | |
| 248 // WARNING: this may be invoked on any thread. | 257 // WARNING: this may be invoked on any thread. |
| 249 base::AutoLock lock(lock_); | 258 base::AutoLock lock(lock_); |
| 250 return thread_safe_cache_->GetPageThumbnail(url, bytes); | 259 return thread_safe_cache_->GetPageThumbnail(url, bytes); |
| 251 } | 260 } |
| 252 | 261 |
| 253 bool TopSites::GetPageThumbnailScore(const GURL& url, | 262 bool TopSites::GetPageThumbnailScore(const GURL& url, |
| 254 ThumbnailScore* score) { | 263 ThumbnailScore* score) { |
| 264 // The thumbnail score may be found in the temporary images. | |
| 265 for (TempImages::iterator i = temp_images_.begin(); i != temp_images_.end(); | |
| 266 ++i) { | |
| 267 if (i->first == url) { | |
| 268 *score = i->second.thumbnail_score; | |
| 269 return true; | |
| 270 } | |
| 271 } | |
| 272 | |
| 255 // WARNING: this may be invoked on any thread. | 273 // WARNING: this may be invoked on any thread. |
| 256 base::AutoLock lock(lock_); | 274 base::AutoLock lock(lock_); |
| 257 return thread_safe_cache_->GetPageThumbnailScore(url, score); | 275 return thread_safe_cache_->GetPageThumbnailScore(url, score); |
| 258 } | 276 } |
| 259 | 277 |
| 260 // Returns the index of |url| in |urls|, or -1 if not found. | 278 // Returns the index of |url| in |urls|, or -1 if not found. |
| 261 static int IndexOf(const MostVisitedURLList& urls, const GURL& url) { | 279 static int IndexOf(const MostVisitedURLList& urls, const GURL& url) { |
| 262 for (size_t i = 0; i < urls.size(); i++) { | 280 for (size_t i = 0; i < urls.size(); i++) { |
| 263 if (urls[i].url == url) | 281 if (urls[i].url == url) |
| 264 return i; | 282 return i; |
| (...skipping 698 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 963 SetTopSites(pages); | 981 SetTopSites(pages); |
| 964 | 982 |
| 965 // Used only in testing. | 983 // Used only in testing. |
| 966 NotificationService::current()->Notify( | 984 NotificationService::current()->Notify( |
| 967 NotificationType::TOP_SITES_UPDATED, | 985 NotificationType::TOP_SITES_UPDATED, |
| 968 Source<TopSites>(this), | 986 Source<TopSites>(this), |
| 969 Details<CancelableRequestProvider::Handle>(&handle)); | 987 Details<CancelableRequestProvider::Handle>(&handle)); |
| 970 } | 988 } |
| 971 | 989 |
| 972 } // namespace history | 990 } // namespace history |
| OLD | NEW |