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_fetcher.h" | 8 #include "components/suggestions/image_fetcher.h" |
9 | |
10 #if defined(OS_IOS) | |
11 #include "components/suggestions/image_manager_utils_ios.h" | |
12 #else | |
9 #include "ui/gfx/codec/jpeg_codec.h" | 13 #include "ui/gfx/codec/jpeg_codec.h" |
14 #endif | |
10 | 15 |
11 using leveldb_proto::ProtoDatabase; | 16 using leveldb_proto::ProtoDatabase; |
12 | 17 |
13 namespace { | 18 namespace { |
14 | 19 |
15 // From JPEG-encoded bytes to SkBitmap. | 20 // From encoded bytes to SkBitmap. |
16 SkBitmap* DecodeImage(const std::vector<unsigned char>& encoded_data) { | 21 SkBitmap* DecodeImage(const std::vector<unsigned char>& encoded_data) { |
22 #if defined(OS_IOS) | |
23 return suggestions::DecodeJPEGToSkBitmap(encoded_data); | |
blundell
2014/10/10 06:01:05
nit: this should be in the suggestions namespace,
Mathieu
2014/10/10 18:06:10
Done.
| |
24 #else | |
17 return gfx::JPEGCodec::Decode(&encoded_data[0], encoded_data.size()); | 25 return gfx::JPEGCodec::Decode(&encoded_data[0], encoded_data.size()); |
26 #endif | |
18 } | 27 } |
19 | 28 |
20 } // namespace | 29 } // namespace |
21 | 30 |
22 namespace suggestions { | 31 namespace suggestions { |
23 | 32 |
24 ImageManager::ImageManager() : weak_ptr_factory_(this) {} | 33 ImageManager::ImageManager() : weak_ptr_factory_(this) {} |
25 | 34 |
26 ImageManager::ImageManager(scoped_ptr<ImageFetcher> image_fetcher, | 35 ImageManager::ImageManager(scoped_ptr<ImageFetcher> image_fetcher, |
27 scoped_ptr<ProtoDatabase<ImageData> > database, | 36 scoped_ptr<ProtoDatabase<ImageData> > database, |
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
208 for (CallbackVector::const_iterator callback_it = request.callbacks.begin(); | 217 for (CallbackVector::const_iterator callback_it = request.callbacks.begin(); |
209 callback_it != request.callbacks.end(); ++callback_it) { | 218 callback_it != request.callbacks.end(); ++callback_it) { |
210 ServeFromCacheOrNetwork(request.url, request.image_url, *callback_it); | 219 ServeFromCacheOrNetwork(request.url, request.image_url, *callback_it); |
211 } | 220 } |
212 } | 221 } |
213 } | 222 } |
214 | 223 |
215 // static | 224 // static |
216 bool ImageManager::EncodeImage(const SkBitmap& bitmap, | 225 bool ImageManager::EncodeImage(const SkBitmap& bitmap, |
217 std::vector<unsigned char>* dest) { | 226 std::vector<unsigned char>* dest) { |
227 #if defined(OS_IOS) | |
228 return suggestions::EncodeSkBitmapToJPEG(bitmap, dest); | |
blundell
2014/10/10 06:01:05
this is in the suggestions namespace.
Mathieu
2014/10/10 18:06:10
Done.
| |
229 #else | |
218 SkAutoLockPixels bitmap_lock(bitmap); | 230 SkAutoLockPixels bitmap_lock(bitmap); |
219 if (!bitmap.readyToDraw() || bitmap.isNull()) { | 231 if (!bitmap.readyToDraw() || bitmap.isNull()) { |
220 return false; | 232 return false; |
221 } | 233 } |
222 return gfx::JPEGCodec::Encode( | 234 return gfx::JPEGCodec::Encode( |
223 reinterpret_cast<unsigned char*>(bitmap.getAddr32(0, 0)), | 235 reinterpret_cast<unsigned char*>(bitmap.getAddr32(0, 0)), |
224 gfx::JPEGCodec::FORMAT_SkBitmap, bitmap.width(), bitmap.height(), | 236 gfx::JPEGCodec::FORMAT_SkBitmap, bitmap.width(), bitmap.height(), |
225 bitmap.rowBytes(), 100, dest); | 237 bitmap.rowBytes(), 100, dest); |
238 #endif | |
226 } | 239 } |
227 | 240 |
228 } // namespace suggestions | 241 } // namespace suggestions |
OLD | NEW |