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

Unified Diff: components/image_fetcher/ios/ios_image_data_fetcher_wrapper.mm

Issue 2689213010: Add a static method to WebPDecoder to decode WebP (Closed)
Patch Set: Address comment Created 3 years, 10 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | components/image_fetcher/ios/ios_image_data_fetcher_wrapper_unittest.mm » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/image_fetcher/ios/ios_image_data_fetcher_wrapper.mm
diff --git a/components/image_fetcher/ios/ios_image_data_fetcher_wrapper.mm b/components/image_fetcher/ios/ios_image_data_fetcher_wrapper.mm
index 247a8475a29594cd9446e6ec4766bdafdf8f1500..233731ebe0372517404917998ad808fa23f3046a 100644
--- a/components/image_fetcher/ios/ios_image_data_fetcher_wrapper.mm
+++ b/components/image_fetcher/ios/ios_image_data_fetcher_wrapper.mm
@@ -5,7 +5,6 @@
#import "components/image_fetcher/ios/ios_image_data_fetcher_wrapper.h"
#import "base/mac/bind_objc_block.h"
-#import "base/mac/scoped_nsobject.h"
#include "base/memory/ptr_util.h"
#include "base/task_runner.h"
#include "base/task_runner_util.h"
@@ -19,56 +18,6 @@
#error "This file requires ARC support."
#endif
-#pragma mark - WebpDecoderDelegate
-
-namespace {
-
-// TODO(crbug.com/687921): Refactor this.
-class WebpDecoderDelegate : public webp_transcode::WebpDecoder::Delegate {
- public:
- WebpDecoderDelegate() = default;
-
- NSData* data() const { return decoded_image_; }
-
- // WebpDecoder::Delegate methods
- void OnFinishedDecoding(bool success) override {
- if (!success)
- decoded_image_ = nil;
- }
- void SetImageFeatures(
- size_t total_size,
- webp_transcode::WebpDecoder::DecodedImageFormat format) override {
- decoded_image_ = [[NSMutableData alloc] initWithCapacity:total_size];
- }
- void OnDataDecoded(NSData* data) override {
- DCHECK(decoded_image_);
- [decoded_image_ appendData:data];
- }
-
- private:
- ~WebpDecoderDelegate() override = default;
- NSMutableData* decoded_image_;
-
- DISALLOW_COPY_AND_ASSIGN(WebpDecoderDelegate);
-};
-
-// Content-type header for WebP images.
-const char kWEBPFirstMagicPattern[] = "RIFF";
-const char kWEBPSecondMagicPattern[] = "WEBP";
-
-// Returns a NSData object containing the decoded image.
-// Returns nil in case of failure.
-NSData* DecodeWebpImage(NSData* webp_image) {
- scoped_refptr<WebpDecoderDelegate> delegate(new WebpDecoderDelegate);
- scoped_refptr<webp_transcode::WebpDecoder> decoder(
- new webp_transcode::WebpDecoder(delegate.get()));
- decoder->OnDataReceived(webp_image);
- DLOG_IF(ERROR, !delegate->data()) << "WebP image decoding failed.";
- return delegate->data();
-}
-
-} // namespace
-
#pragma mark - IOSImageDataFetcherWrapper
namespace image_fetcher {
@@ -118,21 +67,21 @@ IOSImageDataFetcherWrapper::CallbackForImageDataFetcher(
NSData* data =
[NSData dataWithBytes:image_data.data() length:image_data.size()];
- if (data.length < 12 ||
- image_data.compare(0, 4, kWEBPFirstMagicPattern) != 0 ||
- image_data.compare(8, 4, kWEBPSecondMagicPattern) != 0) {
+ if (!webp_transcode::WebpDecoder::IsWebpImage(image_data)) {
callback(data, metadata);
return;
}
+ // The image is a webp image.
RequestMetadata webp_metadata = metadata;
- // The image is a webp image.
- base::PostTaskAndReplyWithResult(task_runner.get(), FROM_HERE,
- base::Bind(&DecodeWebpImage, data),
- base::BindBlockArc(^(NSData* data) {
- callback(data, webp_metadata);
- }));
+ base::PostTaskAndReplyWithResult(
+ task_runner.get(), FROM_HERE, base::BindBlockArc(^NSData*() {
+ return webp_transcode::WebpDecoder::DecodeWebpImage(data);
+ }),
+ base::BindBlockArc(^(NSData* decodedData) {
+ callback(decodedData, webp_metadata);
+ }));
});
}
« no previous file with comments | « no previous file | components/image_fetcher/ios/ios_image_data_fetcher_wrapper_unittest.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698