OLD | NEW |
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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 #import "components/image_fetcher/ios/ios_image_data_fetcher_wrapper.h" | 5 #import "components/image_fetcher/ios/ios_image_data_fetcher_wrapper.h" |
6 | 6 |
7 #import "base/mac/bind_objc_block.h" | 7 #import "base/mac/bind_objc_block.h" |
8 #import "base/mac/scoped_nsobject.h" | 8 #import "base/mac/scoped_nsobject.h" |
9 #include "base/memory/ptr_util.h" | 9 #include "base/memory/ptr_util.h" |
10 #include "base/task_runner.h" | 10 #include "base/task_runner.h" |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
105 void IOSImageDataFetcherWrapper::SetDataUseServiceName( | 105 void IOSImageDataFetcherWrapper::SetDataUseServiceName( |
106 DataUseServiceName data_use_service_name) { | 106 DataUseServiceName data_use_service_name) { |
107 image_data_fetcher_.SetDataUseServiceName(data_use_service_name); | 107 image_data_fetcher_.SetDataUseServiceName(data_use_service_name); |
108 } | 108 } |
109 | 109 |
110 ImageDataFetcher::ImageDataFetcherCallback | 110 ImageDataFetcher::ImageDataFetcherCallback |
111 IOSImageDataFetcherWrapper::CallbackForImageDataFetcher( | 111 IOSImageDataFetcherWrapper::CallbackForImageDataFetcher( |
112 IOSImageDataFetcherCallback callback) { | 112 IOSImageDataFetcherCallback callback) { |
113 scoped_refptr<base::TaskRunner> task_runner = task_runner_; | 113 scoped_refptr<base::TaskRunner> task_runner = task_runner_; |
114 | 114 |
115 return base::BindBlockArc(^(const std::string& image_data) { | 115 return base::BindBlockArc(^(const std::string& image_data, |
| 116 int http_response_code) { |
116 // Create a NSData from the returned data and notify the callback. | 117 // Create a NSData from the returned data and notify the callback. |
117 NSData* data = | 118 NSData* data = |
118 [NSData dataWithBytes:image_data.data() length:image_data.size()]; | 119 [NSData dataWithBytes:image_data.data() length:image_data.size()]; |
119 | 120 |
120 if (data.length < 12 || | 121 if (data.length < 12 || |
121 image_data.compare(0, 4, kWEBPFirstMagicPattern) != 0 || | 122 image_data.compare(0, 4, kWEBPFirstMagicPattern) != 0 || |
122 image_data.compare(8, 4, kWEBPSecondMagicPattern) != 0) { | 123 image_data.compare(8, 4, kWEBPSecondMagicPattern) != 0) { |
123 callback(data); | 124 callback(http_response_code, data); |
124 return; | 125 return; |
125 } | 126 } |
126 | 127 |
127 // The image is a webp image. | 128 // The image is a webp image. |
128 base::PostTaskAndReplyWithResult(task_runner.get(), FROM_HERE, | 129 base::PostTaskAndReplyWithResult(task_runner.get(), FROM_HERE, |
129 base::Bind(&DecodeWebpImage, data), | 130 base::Bind(&DecodeWebpImage, data), |
130 base::BindBlockArc(callback)); | 131 base::BindBlockArc(^(NSData* data) { |
| 132 callback(http_response_code, data); |
| 133 })); |
131 }); | 134 }); |
132 } | 135 } |
133 | 136 |
134 } // namespace image_fetcher | 137 } // namespace image_fetcher |
OLD | NEW |