Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "components/suggestions/image_manager.h" | 5 #include "components/suggestions/image_manager.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/location.h" | 8 #include "base/location.h" |
| 9 #include "base/task_runner_util.h" | 9 #include "base/task_runner_util.h" |
| 10 #include "components/suggestions/image_encoder.h" | 10 #include "components/suggestions/image_encoder.h" |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 50 void ImageManager::Initialize(const SuggestionsProfile& suggestions) { | 50 void ImageManager::Initialize(const SuggestionsProfile& suggestions) { |
| 51 image_url_map_.clear(); | 51 image_url_map_.clear(); |
| 52 for (int i = 0; i < suggestions.suggestions_size(); ++i) { | 52 for (int i = 0; i < suggestions.suggestions_size(); ++i) { |
| 53 const ChromeSuggestion& suggestion = suggestions.suggestions(i); | 53 const ChromeSuggestion& suggestion = suggestions.suggestions(i); |
| 54 if (suggestion.has_thumbnail()) { | 54 if (suggestion.has_thumbnail()) { |
| 55 image_url_map_[GURL(suggestion.url())] = GURL(suggestion.thumbnail()); | 55 image_url_map_[GURL(suggestion.url())] = GURL(suggestion.thumbnail()); |
| 56 } | 56 } |
| 57 } | 57 } |
| 58 } | 58 } |
| 59 | 59 |
| 60 void ImageManager::AddImageURL(const GURL& url, const GURL& image_url) { | |
| 61 image_url_map_[url] = image_url; | |
|
Bernhard Bauer
2015/09/04 13:42:41
Add a thread check?
Marc Treib
2015/09/04 13:49:03
Done.
| |
| 62 } | |
| 63 | |
| 60 void ImageManager::GetImageForURL( | 64 void ImageManager::GetImageForURL( |
| 61 const GURL& url, | 65 const GURL& url, |
| 62 base::Callback<void(const GURL&, const SkBitmap*)> callback) { | 66 base::Callback<void(const GURL&, const SkBitmap*)> callback) { |
| 63 DCHECK(thread_checker_.CalledOnValidThread()); | 67 DCHECK(thread_checker_.CalledOnValidThread()); |
| 64 // If |url| is not found in |image_url_map_|, then invoke |callback| with | 68 // If |url| is not found in |image_url_map_|, then invoke |callback| with |
| 65 // NULL since there is no associated image for this |url|. | 69 // NULL since there is no associated image for this |url|. |
| 66 GURL image_url; | 70 GURL image_url; |
| 67 if (!GetImageURL(url, &image_url)) { | 71 if (!GetImageURL(url, &image_url)) { |
| 68 callback.Run(url, NULL); | 72 callback.Run(url, NULL); |
| 69 return; | 73 return; |
| (...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 223 it != pending_cache_requests_.end(); ++it) { | 227 it != pending_cache_requests_.end(); ++it) { |
| 224 const ImageCacheRequest& request = it->second; | 228 const ImageCacheRequest& request = it->second; |
| 225 for (CallbackVector::const_iterator callback_it = request.callbacks.begin(); | 229 for (CallbackVector::const_iterator callback_it = request.callbacks.begin(); |
| 226 callback_it != request.callbacks.end(); ++callback_it) { | 230 callback_it != request.callbacks.end(); ++callback_it) { |
| 227 ServeFromCacheOrNetwork(request.url, request.image_url, *callback_it); | 231 ServeFromCacheOrNetwork(request.url, request.image_url, *callback_it); |
| 228 } | 232 } |
| 229 } | 233 } |
| 230 } | 234 } |
| 231 | 235 |
| 232 } // namespace suggestions | 236 } // namespace suggestions |
| OLD | NEW |