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 "chrome/browser/search/suggestions/thumbnail_manager.h" | 5 #include "chrome/browser/search/suggestions/image_manager_impl.h" |
| 6 | 6 |
| 7 #include "base/memory/ref_counted_memory.h" | 7 #include "base/memory/ref_counted_memory.h" |
| 8 #include "content/public/browser/browser_thread.h" | 8 #include "content/public/browser/browser_thread.h" |
| 9 #include "net/base/load_flags.h" | 9 #include "net/base/load_flags.h" |
| 10 #include "net/url_request/url_request_context_getter.h" | 10 #include "net/url_request/url_request_context_getter.h" |
| 11 #include "ui/gfx/codec/jpeg_codec.h" | 11 #include "ui/gfx/codec/jpeg_codec.h" |
| 12 | 12 |
| 13 using leveldb_proto::ProtoDatabase; | 13 using leveldb_proto::ProtoDatabase; |
| 14 | 14 |
| 15 namespace { | 15 namespace { |
| 16 | 16 |
| 17 // From JPEG-encoded bytes to SkBitmap. | 17 // From JPEG-encoded bytes to SkBitmap. |
| 18 SkBitmap* DecodeThumbnail(const std::vector<unsigned char>& encoded_data) { | 18 SkBitmap* DecodeImage(const std::vector<unsigned char>& encoded_data) { |
| 19 return gfx::JPEGCodec::Decode(&encoded_data[0], encoded_data.size()); | 19 return gfx::JPEGCodec::Decode(&encoded_data[0], encoded_data.size()); |
| 20 } | 20 } |
| 21 | 21 |
| 22 } // namespace | 22 } // namespace |
| 23 | 23 |
| 24 namespace suggestions { | 24 namespace suggestions { |
| 25 | 25 |
| 26 ThumbnailManager::ThumbnailManager() : weak_ptr_factory_(this) {} | 26 ImageManagerImpl::ImageManagerImpl() : weak_ptr_factory_(this) {} |
| 27 | 27 |
| 28 ThumbnailManager::ThumbnailManager( | 28 ImageManagerImpl::ImageManagerImpl( |
| 29 net::URLRequestContextGetter* url_request_context, | 29 net::URLRequestContextGetter* url_request_context, |
| 30 scoped_ptr<ProtoDatabase<ThumbnailData> > database, | 30 scoped_ptr<ProtoDatabase<ImageData> > database, |
| 31 const base::FilePath& database_dir) | 31 const base::FilePath& database_dir) |
| 32 : url_request_context_(url_request_context), | 32 : url_request_context_(url_request_context), |
| 33 database_(database.Pass()), | 33 database_(database.Pass()), |
| 34 database_ready_(false), | 34 database_ready_(false), |
| 35 weak_ptr_factory_(this) { | 35 weak_ptr_factory_(this) { |
| 36 database_->Init(database_dir, base::Bind(&ThumbnailManager::OnDatabaseInit, | 36 database_->Init(database_dir, base::Bind(&ImageManagerImpl::OnDatabaseInit, |
| 37 weak_ptr_factory_.GetWeakPtr())); | 37 weak_ptr_factory_.GetWeakPtr())); |
| 38 } | 38 } |
| 39 | 39 |
| 40 ThumbnailManager::~ThumbnailManager() {} | 40 ImageManagerImpl::~ImageManagerImpl() {} |
| 41 | 41 |
| 42 ThumbnailManager::ThumbnailRequest::ThumbnailRequest() : fetcher(NULL) {} | 42 ImageManagerImpl::ImageRequest::ImageRequest() : fetcher(NULL) {} |
| 43 | 43 |
| 44 ThumbnailManager::ThumbnailRequest::ThumbnailRequest(chrome::BitmapFetcher* f) | 44 ImageManagerImpl::ImageRequest::ImageRequest(chrome::BitmapFetcher* f) |
| 45 : fetcher(f) {} | 45 : fetcher(f) {} |
| 46 | 46 |
| 47 ThumbnailManager::ThumbnailRequest::~ThumbnailRequest() { delete fetcher; } | 47 ImageManagerImpl::ImageRequest::~ImageRequest() { delete fetcher; } |
| 48 | 48 |
| 49 void ThumbnailManager::Initialize(const SuggestionsProfile& suggestions) { | 49 void ImageManagerImpl::Initialize(const SuggestionsProfile& suggestions) { |
| 50 thumbnail_url_map_.clear(); | 50 image_url_map_.clear(); |
| 51 for (int i = 0; i < suggestions.suggestions_size(); ++i) { | 51 for (int i = 0; i < suggestions.suggestions_size(); ++i) { |
| 52 const ChromeSuggestion& suggestion = suggestions.suggestions(i); | 52 const ChromeSuggestion& suggestion = suggestions.suggestions(i); |
| 53 if (suggestion.has_thumbnail()) { | 53 if (suggestion.has_thumbnail()) { |
| 54 thumbnail_url_map_[GURL(suggestion.url())] = GURL(suggestion.thumbnail()); | 54 image_url_map_[GURL(suggestion.url())] = GURL(suggestion.thumbnail()); |
| 55 } | 55 } |
| 56 } | 56 } |
| 57 } | 57 } |
| 58 | 58 |
| 59 void ThumbnailManager::GetImageForURL( | 59 void ImageManagerImpl::GetImageForURL( |
| 60 const GURL& url, | 60 const GURL& url, |
| 61 base::Callback<void(const GURL&, const SkBitmap*)> callback) { | 61 base::Callback<void(const GURL&, const SkBitmap*)> callback) { |
| 62 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 62 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 63 // If |url| is not found in |thumbnail_url_map_|, then invoke |callback| with | 63 // If |url| is not found in |image_url_map_|, then invoke |callback| with |
| 64 // NULL since there is no associated thumbnail for this |url|. | 64 // NULL since there is no associated image for this |url|. |
| 65 GURL thumbnail_url; | 65 GURL image_url; |
| 66 if (!GetThumbnailURL(url, &thumbnail_url)) { | 66 if (!GetImageURL(url, &image_url)) { |
| 67 callback.Run(url, NULL); | 67 callback.Run(url, NULL); |
| 68 return; | 68 return; |
| 69 } | 69 } |
| 70 | 70 |
| 71 // |database_| can be NULL if something went wrong in initialization. | 71 // |database_| can be NULL if something went wrong in initialization. |
| 72 if (database_.get() && !database_ready_) { | 72 if (database_.get() && !database_ready_) { |
| 73 // Once database is initialized, it will serve pending requests from either | 73 // Once database is initialized, it will serve pending requests from either |
| 74 // cache or network. | 74 // cache or network. |
| 75 QueueCacheRequest(url, thumbnail_url, callback); | 75 QueueCacheRequest(url, image_url, callback); |
| 76 return; | 76 return; |
| 77 } | 77 } |
| 78 | 78 |
| 79 ServeFromCacheOrNetwork(url, thumbnail_url, callback); | 79 ServeFromCacheOrNetwork(url, image_url, callback); |
| 80 } | 80 } |
| 81 | 81 |
| 82 bool ThumbnailManager::GetThumbnailURL(const GURL& url, GURL* thumbnail_url) { | 82 bool ImageManagerImpl::GetImageURL(const GURL& url, GURL* image_url) { |
| 83 std::map<GURL, GURL>::iterator it = thumbnail_url_map_.find(url); | 83 std::map<GURL, GURL>::iterator it = image_url_map_.find(url); |
| 84 if (it == thumbnail_url_map_.end()) return false; // Not found. | 84 if (it == image_url_map_.end()) return false; // Not found. |
| 85 *thumbnail_url = it->second; | 85 *image_url = it->second; |
| 86 return true; | 86 return true; |
| 87 } | 87 } |
| 88 | 88 |
| 89 void ThumbnailManager::QueueCacheRequest( | 89 void ImageManagerImpl::QueueCacheRequest( |
| 90 const GURL& url, const GURL& thumbnail_url, | 90 const GURL& url, const GURL& image_url, |
| 91 base::Callback<void(const GURL&, const SkBitmap*)> callback) { | 91 base::Callback<void(const GURL&, const SkBitmap*)> callback) { |
| 92 // To be served when the database has loaded. | 92 // To be served when the database has loaded. |
| 93 ThumbnailRequestMap::iterator it = pending_cache_requests_.find(url); | 93 ImageRequestMap::iterator it = pending_cache_requests_.find(url); |
| 94 if (it == pending_cache_requests_.end()) { | 94 if (it == pending_cache_requests_.end()) { |
| 95 ThumbnailRequest request(NULL); | 95 ImageRequest request(NULL); |
| 96 request.url = url; | 96 request.url = url; |
| 97 request.thumbnail_url = thumbnail_url; | 97 request.image_url = image_url; |
| 98 request.callbacks.push_back(callback); | 98 request.callbacks.push_back(callback); |
| 99 pending_cache_requests_[url].swap(&request); | 99 pending_cache_requests_[url].swap(&request); |
| 100 } else { | 100 } else { |
| 101 // Request already queued for this url. | 101 // Request already queued for this url. |
| 102 it->second.callbacks.push_back(callback); | 102 it->second.callbacks.push_back(callback); |
| 103 } | 103 } |
| 104 } | 104 } |
| 105 | 105 |
| 106 void ThumbnailManager::ServeFromCacheOrNetwork( | 106 void ImageManagerImpl::ServeFromCacheOrNetwork( |
| 107 const GURL& url, const GURL& thumbnail_url, | 107 const GURL& url, const GURL& image_url, |
| 108 base::Callback<void(const GURL&, const SkBitmap*)> callback) { | 108 base::Callback<void(const GURL&, const SkBitmap*)> callback) { |
| 109 // If there is a thumbnail available in memory, return it. | 109 // If there is a image available in memory, return it. |
| 110 if (!ServeFromCache(url, callback)) { | 110 if (!ServeFromCache(url, callback)) { |
| 111 StartOrQueueNetworkRequest(url, thumbnail_url, callback); | 111 StartOrQueueNetworkRequest(url, image_url, callback); |
| 112 } | 112 } |
| 113 } | 113 } |
| 114 | 114 |
| 115 bool ThumbnailManager::ServeFromCache( | 115 bool ImageManagerImpl::ServeFromCache( |
| 116 const GURL& url, | 116 const GURL& url, |
| 117 base::Callback<void(const GURL&, const SkBitmap*)> callback) { | 117 base::Callback<void(const GURL&, const SkBitmap*)> callback) { |
| 118 SkBitmap* bitmap = GetBitmapFromCache(url); | 118 SkBitmap* bitmap = GetBitmapFromCache(url); |
| 119 if (bitmap) { | 119 if (bitmap) { |
| 120 callback.Run(url, bitmap); | 120 callback.Run(url, bitmap); |
| 121 return true; | 121 return true; |
| 122 } | 122 } |
| 123 return false; | 123 return false; |
| 124 } | 124 } |
| 125 | 125 |
| 126 SkBitmap* ThumbnailManager::GetBitmapFromCache(const GURL& url) { | 126 SkBitmap* ImageManagerImpl::GetBitmapFromCache(const GURL& url) { |
| 127 ThumbnailMap::iterator thumb_iter = thumbnail_map_.find(url.spec()); | 127 ImageMap::iterator thumb_iter = image_map_.find(url.spec()); |
|
huangs
2014/08/07 20:33:32
NIT: rename |thumb_iter|.
Mathieu
2014/08/07 21:03:35
Done.
| |
| 128 if (thumb_iter != thumbnail_map_.end()) { | 128 if (thumb_iter != image_map_.end()) { |
| 129 return &thumb_iter->second; | 129 return &thumb_iter->second; |
| 130 } | 130 } |
| 131 return NULL; | 131 return NULL; |
| 132 } | 132 } |
| 133 | 133 |
| 134 void ThumbnailManager::StartOrQueueNetworkRequest( | 134 void ImageManagerImpl::StartOrQueueNetworkRequest( |
| 135 const GURL& url, const GURL& thumbnail_url, | 135 const GURL& url, const GURL& image_url, |
| 136 base::Callback<void(const GURL&, const SkBitmap*)> callback) { | 136 base::Callback<void(const GURL&, const SkBitmap*)> callback) { |
| 137 // Before starting to fetch the thumbnail. Look for a request in progress for | 137 // Before starting to fetch the image. Look for a request in progress for |
| 138 // |thumbnail_url|, and queue if appropriate. | 138 // |image_url|, and queue if appropriate. |
| 139 ThumbnailRequestMap::iterator it = pending_net_requests_.find(thumbnail_url); | 139 ImageRequestMap::iterator it = pending_net_requests_.find(image_url); |
| 140 if (it == pending_net_requests_.end()) { | 140 if (it == pending_net_requests_.end()) { |
| 141 // |thumbnail_url| is not being fetched, so create a request and initiate | 141 // |image_url| is not being fetched, so create a request and initiate |
| 142 // the fetch. | 142 // the fetch. |
| 143 ThumbnailRequest request(new chrome::BitmapFetcher(thumbnail_url, this)); | 143 ImageRequest request(new chrome::BitmapFetcher(image_url, this)); |
| 144 request.url = url; | 144 request.url = url; |
| 145 request.callbacks.push_back(callback); | 145 request.callbacks.push_back(callback); |
| 146 request.fetcher->Start( | 146 request.fetcher->Start( |
| 147 url_request_context_, std::string(), | 147 url_request_context_, std::string(), |
| 148 net::URLRequest::CLEAR_REFERRER_ON_TRANSITION_FROM_SECURE_TO_INSECURE, | 148 net::URLRequest::CLEAR_REFERRER_ON_TRANSITION_FROM_SECURE_TO_INSECURE, |
| 149 net::LOAD_NORMAL); | 149 net::LOAD_NORMAL); |
| 150 pending_net_requests_[thumbnail_url].swap(&request); | 150 pending_net_requests_[image_url].swap(&request); |
| 151 } else { | 151 } else { |
| 152 // Request in progress. Register as an interested callback. | 152 // Request in progress. Register as an interested callback. |
| 153 it->second.callbacks.push_back(callback); | 153 it->second.callbacks.push_back(callback); |
| 154 } | 154 } |
| 155 } | 155 } |
| 156 | 156 |
| 157 void ThumbnailManager::OnFetchComplete(const GURL thumbnail_url, | 157 void ImageManagerImpl::OnFetchComplete(const GURL image_url, |
| 158 const SkBitmap* bitmap) { | 158 const SkBitmap* bitmap) { |
| 159 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 159 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 160 | 160 |
| 161 ThumbnailRequestMap::iterator thumb_iter = | 161 ImageRequestMap::iterator thumb_iter = |
|
huangs
2014/08/07 20:33:32
NIT: rename |thumb_iter|.
Mathieu
2014/08/07 21:03:35
Done.
| |
| 162 pending_net_requests_.find(thumbnail_url); | 162 pending_net_requests_.find(image_url); |
| 163 DCHECK(thumb_iter != pending_net_requests_.end()); | 163 DCHECK(thumb_iter != pending_net_requests_.end()); |
| 164 | 164 |
| 165 ThumbnailRequest* request = &thumb_iter->second; | 165 ImageRequest* request = &thumb_iter->second; |
| 166 | 166 |
| 167 // Here |bitmap| could be NULL or a pointer to a bitmap which is owned by the | 167 // Here |bitmap| could be NULL or a pointer to a bitmap which is owned by the |
| 168 // BitmapFetcher and which ceases to exist after this function. Pass the | 168 // BitmapFetcher and which ceases to exist after this function. Pass the |
| 169 // un-owned pointer to the registered callbacks. | 169 // un-owned pointer to the registered callbacks. |
| 170 for (CallbackVector::iterator callback_iter = request->callbacks.begin(); | 170 for (CallbackVector::iterator callback_iter = request->callbacks.begin(); |
| 171 callback_iter != request->callbacks.end(); ++callback_iter) { | 171 callback_iter != request->callbacks.end(); ++callback_iter) { |
| 172 callback_iter->Run(request->url, bitmap); | 172 callback_iter->Run(request->url, bitmap); |
| 173 } | 173 } |
| 174 | 174 |
| 175 // Save the bitmap to the in-memory model as well as the database, because it | 175 // Save the bitmap to the in-memory model as well as the database, because it |
| 176 // is now the freshest representation of the thumbnail. | 176 // is now the freshest representation of the image. |
| 177 // TODO(mathp): Handle null (no thumbnail found), possible deletion in DB. | 177 // TODO(mathp): Handle null (no image found), possible deletion in DB. |
| 178 if (bitmap) SaveThumbnail(request->url, *bitmap); | 178 if (bitmap) SaveImage(request->url, *bitmap); |
| 179 | 179 |
| 180 // Erase the completed ThumbnailRequest. | 180 // Erase the completed ImageRequest. |
| 181 pending_net_requests_.erase(thumb_iter); | 181 pending_net_requests_.erase(thumb_iter); |
| 182 } | 182 } |
| 183 | 183 |
| 184 void ThumbnailManager::SaveThumbnail(const GURL& url, const SkBitmap& bitmap) { | 184 void ImageManagerImpl::SaveImage(const GURL& url, const SkBitmap& bitmap) { |
| 185 // Update the thumbnail map. | 185 // Update the image map. |
| 186 thumbnail_map_.insert(std::make_pair(url.spec(), bitmap)); | 186 image_map_.insert(std::make_pair(url.spec(), bitmap)); |
| 187 | 187 |
| 188 if (!database_ready_) return; | 188 if (!database_ready_) return; |
| 189 | 189 |
| 190 // Attempt to save a JPEG representation to the database. If not successful, | 190 // Attempt to save a JPEG representation to the database. If not successful, |
| 191 // the fetched bitmap will still be inserted in the cache, above. | 191 // the fetched bitmap will still be inserted in the cache, above. |
| 192 std::vector<unsigned char> encoded_data; | 192 std::vector<unsigned char> encoded_data; |
| 193 if (EncodeThumbnail(bitmap, &encoded_data)) { | 193 if (EncodeImage(bitmap, &encoded_data)) { |
| 194 // Save the resulting bitmap to the database. | 194 // Save the resulting bitmap to the database. |
| 195 ThumbnailData data; | 195 ImageData data; |
| 196 data.set_url(url.spec()); | 196 data.set_url(url.spec()); |
| 197 data.set_data(std::string(encoded_data.begin(), encoded_data.end())); | 197 data.set_data(std::string(encoded_data.begin(), encoded_data.end())); |
| 198 scoped_ptr<ProtoDatabase<ThumbnailData>::KeyEntryVector> entries_to_save( | 198 scoped_ptr<ProtoDatabase<ImageData>::KeyEntryVector> entries_to_save( |
| 199 new ProtoDatabase<ThumbnailData>::KeyEntryVector()); | 199 new ProtoDatabase<ImageData>::KeyEntryVector()); |
| 200 scoped_ptr<std::vector<std::string> > keys_to_remove( | 200 scoped_ptr<std::vector<std::string> > keys_to_remove( |
| 201 new std::vector<std::string>()); | 201 new std::vector<std::string>()); |
| 202 entries_to_save->push_back(std::make_pair(data.url(), data)); | 202 entries_to_save->push_back(std::make_pair(data.url(), data)); |
| 203 database_->UpdateEntries(entries_to_save.Pass(), keys_to_remove.Pass(), | 203 database_->UpdateEntries(entries_to_save.Pass(), keys_to_remove.Pass(), |
| 204 base::Bind(&ThumbnailManager::OnDatabaseSave, | 204 base::Bind(&ImageManagerImpl::OnDatabaseSave, |
| 205 weak_ptr_factory_.GetWeakPtr())); | 205 weak_ptr_factory_.GetWeakPtr())); |
| 206 } | 206 } |
| 207 } | 207 } |
| 208 | 208 |
| 209 void ThumbnailManager::OnDatabaseInit(bool success) { | 209 void ImageManagerImpl::OnDatabaseInit(bool success) { |
| 210 if (!success) { | 210 if (!success) { |
| 211 DVLOG(1) << "Thumbnail database init failed."; | 211 DVLOG(1) << "Image database init failed."; |
| 212 database_.reset(); | 212 database_.reset(); |
| 213 ServePendingCacheRequests(); | 213 ServePendingCacheRequests(); |
| 214 return; | 214 return; |
| 215 } | 215 } |
| 216 database_->LoadEntries(base::Bind(&ThumbnailManager::OnDatabaseLoad, | 216 database_->LoadEntries(base::Bind(&ImageManagerImpl::OnDatabaseLoad, |
| 217 weak_ptr_factory_.GetWeakPtr())); | 217 weak_ptr_factory_.GetWeakPtr())); |
| 218 } | 218 } |
| 219 | 219 |
| 220 void ThumbnailManager::OnDatabaseLoad(bool success, | 220 void ImageManagerImpl::OnDatabaseLoad(bool success, |
| 221 scoped_ptr<ThumbnailVector> entries) { | 221 scoped_ptr<ImageDataVector> entries) { |
| 222 if (!success) { | 222 if (!success) { |
| 223 DVLOG(1) << "Thumbnail database load failed."; | 223 DVLOG(1) << "Image database load failed."; |
| 224 database_.reset(); | 224 database_.reset(); |
| 225 ServePendingCacheRequests(); | 225 ServePendingCacheRequests(); |
| 226 return; | 226 return; |
| 227 } | 227 } |
| 228 database_ready_ = true; | 228 database_ready_ = true; |
| 229 | 229 |
| 230 LoadEntriesInCache(entries.Pass()); | 230 LoadEntriesInCache(entries.Pass()); |
| 231 ServePendingCacheRequests(); | 231 ServePendingCacheRequests(); |
| 232 } | 232 } |
| 233 | 233 |
| 234 void ThumbnailManager::OnDatabaseSave(bool success) { | 234 void ImageManagerImpl::OnDatabaseSave(bool success) { |
| 235 if (!success) { | 235 if (!success) { |
| 236 DVLOG(1) << "Thumbnail database save failed."; | 236 DVLOG(1) << "Image database save failed."; |
| 237 database_.reset(); | 237 database_.reset(); |
| 238 database_ready_ = false; | 238 database_ready_ = false; |
| 239 } | 239 } |
| 240 } | 240 } |
| 241 | 241 |
| 242 void ThumbnailManager::LoadEntriesInCache( | 242 void ImageManagerImpl::LoadEntriesInCache( |
|
huangs
2014/08/07 20:33:32
Unwrap.
Mathieu
2014/08/07 21:03:35
Done.
| |
| 243 scoped_ptr<ThumbnailVector> entries) { | 243 scoped_ptr<ImageDataVector> entries) { |
| 244 for (ThumbnailVector::iterator it = entries->begin(); it != entries->end(); | 244 for (ImageDataVector::iterator it = entries->begin(); it != entries->end(); |
| 245 ++it) { | 245 ++it) { |
| 246 std::vector<unsigned char> encoded_data(it->data().begin(), | 246 std::vector<unsigned char> encoded_data(it->data().begin(), |
| 247 it->data().end()); | 247 it->data().end()); |
| 248 | 248 |
| 249 scoped_ptr<SkBitmap> bitmap(DecodeThumbnail(encoded_data)); | 249 scoped_ptr<SkBitmap> bitmap(DecodeImage(encoded_data)); |
| 250 if (bitmap.get()) { | 250 if (bitmap.get()) { |
| 251 thumbnail_map_.insert(std::make_pair(it->url(), *bitmap)); | 251 image_map_.insert(std::make_pair(it->url(), *bitmap)); |
| 252 } | 252 } |
| 253 } | 253 } |
| 254 } | 254 } |
| 255 | 255 |
| 256 void ThumbnailManager::ServePendingCacheRequests() { | 256 void ImageManagerImpl::ServePendingCacheRequests() { |
| 257 for (ThumbnailRequestMap::iterator it = pending_cache_requests_.begin(); | 257 for (ImageRequestMap::iterator it = pending_cache_requests_.begin(); |
| 258 it != pending_cache_requests_.end(); ++it) { | 258 it != pending_cache_requests_.end(); ++it) { |
| 259 const ThumbnailRequest& request = it->second; | 259 const ImageRequest& request = it->second; |
| 260 for (CallbackVector::const_iterator callback_it = request.callbacks.begin(); | 260 for (CallbackVector::const_iterator callback_it = request.callbacks.begin(); |
| 261 callback_it != request.callbacks.end(); ++callback_it) { | 261 callback_it != request.callbacks.end(); ++callback_it) { |
| 262 ServeFromCacheOrNetwork(request.url, request.thumbnail_url, *callback_it); | 262 ServeFromCacheOrNetwork(request.url, request.image_url, *callback_it); |
| 263 } | 263 } |
| 264 } | 264 } |
| 265 } | 265 } |
| 266 | 266 |
| 267 // static | 267 // static |
| 268 bool ThumbnailManager::EncodeThumbnail(const SkBitmap& bitmap, | 268 bool ImageManagerImpl::EncodeImage(const SkBitmap& bitmap, |
| 269 std::vector<unsigned char>* dest) { | 269 std::vector<unsigned char>* dest) { |
| 270 SkAutoLockPixels bitmap_lock(bitmap); | 270 SkAutoLockPixels bitmap_lock(bitmap); |
| 271 if (!bitmap.readyToDraw() || bitmap.isNull()) { | 271 if (!bitmap.readyToDraw() || bitmap.isNull()) { |
| 272 return false; | 272 return false; |
| 273 } | 273 } |
| 274 return gfx::JPEGCodec::Encode( | 274 return gfx::JPEGCodec::Encode( |
| 275 reinterpret_cast<unsigned char*>(bitmap.getAddr32(0, 0)), | 275 reinterpret_cast<unsigned char*>(bitmap.getAddr32(0, 0)), |
| 276 gfx::JPEGCodec::FORMAT_SkBitmap, bitmap.width(), bitmap.height(), | 276 gfx::JPEGCodec::FORMAT_SkBitmap, bitmap.width(), bitmap.height(), |
| 277 bitmap.width() * bitmap.bytesPerPixel(), 100, dest); | 277 bitmap.width() * bitmap.bytesPerPixel(), 100, dest); |
| 278 } | 278 } |
| 279 | 279 |
| 280 } // namespace suggestions | 280 } // namespace suggestions |
| OLD | NEW |