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 "components/suggestions/image_encoder.h" | 8 #include "components/suggestions/image_encoder.h" |
9 #include "components/suggestions/image_fetcher.h" | 9 #include "components/suggestions/image_fetcher.h" |
10 | 10 |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
59 // Once database is initialized, it will serve pending requests from either | 59 // Once database is initialized, it will serve pending requests from either |
60 // cache or network. | 60 // cache or network. |
61 QueueCacheRequest(url, image_url, callback); | 61 QueueCacheRequest(url, image_url, callback); |
62 return; | 62 return; |
63 } | 63 } |
64 | 64 |
65 ServeFromCacheOrNetwork(url, image_url, callback); | 65 ServeFromCacheOrNetwork(url, image_url, callback); |
66 } | 66 } |
67 | 67 |
68 void ImageManager::OnImageFetched(const GURL& url, const SkBitmap* bitmap) { | 68 void ImageManager::OnImageFetched(const GURL& url, const SkBitmap* bitmap) { |
69 SaveImage(url, *bitmap); | 69 if (bitmap) // |bitmap| can be nullptr if image fetch was unsuccessful. |
| 70 SaveImage(url, *bitmap); |
70 } | 71 } |
71 | 72 |
72 bool ImageManager::GetImageURL(const GURL& url, GURL* image_url) { | 73 bool ImageManager::GetImageURL(const GURL& url, GURL* image_url) { |
| 74 DCHECK(image_url); |
73 std::map<GURL, GURL>::iterator it = image_url_map_.find(url); | 75 std::map<GURL, GURL>::iterator it = image_url_map_.find(url); |
74 if (it == image_url_map_.end()) return false; // Not found. | 76 if (it == image_url_map_.end()) return false; // Not found. |
75 *image_url = it->second; | 77 *image_url = it->second; |
76 return true; | 78 return true; |
77 } | 79 } |
78 | 80 |
79 void ImageManager::QueueCacheRequest( | 81 void ImageManager::QueueCacheRequest( |
80 const GURL& url, const GURL& image_url, | 82 const GURL& url, const GURL& image_url, |
81 base::Callback<void(const GURL&, const SkBitmap*)> callback) { | 83 base::Callback<void(const GURL&, const SkBitmap*)> callback) { |
82 // To be served when the database has loaded. | 84 // To be served when the database has loaded. |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
197 it != pending_cache_requests_.end(); ++it) { | 199 it != pending_cache_requests_.end(); ++it) { |
198 const ImageCacheRequest& request = it->second; | 200 const ImageCacheRequest& request = it->second; |
199 for (CallbackVector::const_iterator callback_it = request.callbacks.begin(); | 201 for (CallbackVector::const_iterator callback_it = request.callbacks.begin(); |
200 callback_it != request.callbacks.end(); ++callback_it) { | 202 callback_it != request.callbacks.end(); ++callback_it) { |
201 ServeFromCacheOrNetwork(request.url, request.image_url, *callback_it); | 203 ServeFromCacheOrNetwork(request.url, request.image_url, *callback_it); |
202 } | 204 } |
203 } | 205 } |
204 } | 206 } |
205 | 207 |
206 } // namespace suggestions | 208 } // namespace suggestions |
OLD | NEW |