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

Side by Side Diff: components/suggestions/image_manager.cc

Issue 1314493013: Popular sites on the NTP: add thumbnails! (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix android_clang_dbg_recipe build Created 5 years, 3 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
OLDNEW
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
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 DCHECK(thread_checker_.CalledOnValidThread());
62 image_url_map_[url] = image_url;
63 }
64
60 void ImageManager::GetImageForURL( 65 void ImageManager::GetImageForURL(
61 const GURL& url, 66 const GURL& url,
62 base::Callback<void(const GURL&, const SkBitmap*)> callback) { 67 base::Callback<void(const GURL&, const SkBitmap*)> callback) {
63 DCHECK(thread_checker_.CalledOnValidThread()); 68 DCHECK(thread_checker_.CalledOnValidThread());
64 // If |url| is not found in |image_url_map_|, then invoke |callback| with 69 // If |url| is not found in |image_url_map_|, then invoke |callback| with
65 // NULL since there is no associated image for this |url|. 70 // NULL since there is no associated image for this |url|.
66 GURL image_url; 71 GURL image_url;
67 if (!GetImageURL(url, &image_url)) { 72 if (!GetImageURL(url, &image_url)) {
68 callback.Run(url, NULL); 73 callback.Run(url, NULL);
69 return; 74 return;
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
223 it != pending_cache_requests_.end(); ++it) { 228 it != pending_cache_requests_.end(); ++it) {
224 const ImageCacheRequest& request = it->second; 229 const ImageCacheRequest& request = it->second;
225 for (CallbackVector::const_iterator callback_it = request.callbacks.begin(); 230 for (CallbackVector::const_iterator callback_it = request.callbacks.begin();
226 callback_it != request.callbacks.end(); ++callback_it) { 231 callback_it != request.callbacks.end(); ++callback_it) {
227 ServeFromCacheOrNetwork(request.url, request.image_url, *callback_it); 232 ServeFromCacheOrNetwork(request.url, request.image_url, *callback_it);
228 } 233 }
229 } 234 }
230 } 235 }
231 236
232 } // namespace suggestions 237 } // namespace suggestions
OLDNEW
« no previous file with comments | « components/suggestions/image_manager.h ('k') | components/suggestions/image_manager_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698