Commit 10b2d3e1 authored by Sylvain Defresne's avatar Sylvain Defresne Committed by Commit Bot

[ios] Remove uses of scoped_block.h & scoped_nsobject.h

Most of the include are obsolete. The remaining one can be removed
as all the code is compiled with ARC thus there is no need to have
a C++ smart pointer to call retain/release when the compiler can
do it automatically.

Bug: 1051997
Change-Id: I77b60876b2b1616ebc369a63e9e8562d5ec9f42d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2073884Reviewed-by: default avatarGauthier Ambard <gambard@chromium.org>
Commit-Queue: Sylvain Defresne <sdefresne@chromium.org>
Cr-Commit-Position: refs/heads/master@{#744670}
parent 9fb704a0
...@@ -8,7 +8,6 @@ ...@@ -8,7 +8,6 @@
#include <memory> #include <memory>
#include "base/mac/scoped_block.h"
#include "base/memory/ref_counted.h" #include "base/memory/ref_counted.h"
#include "base/stl_util.h" #include "base/stl_util.h"
#include "base/test/task_environment.h" #include "base/test/task_environment.h"
...@@ -107,11 +106,11 @@ namespace image_fetcher { ...@@ -107,11 +106,11 @@ namespace image_fetcher {
class IOSImageDataFetcherWrapperTest : public PlatformTest { class IOSImageDataFetcherWrapperTest : public PlatformTest {
protected: protected:
IOSImageDataFetcherWrapperTest() IOSImageDataFetcherWrapperTest()
: callback_([^(NSData* data) { : callback_(^(NSData* data, const RequestMetadata&) {
result_data_ = data; result_data_ = data;
result_ = [UIImage imageWithData:data]; result_ = [UIImage imageWithData:data];
called_ = true; called_ = true;
} copy]) { }) {
shared_factory_ = shared_factory_ =
base::MakeRefCounted<network::WeakWrapperSharedURLLoaderFactory>( base::MakeRefCounted<network::WeakWrapperSharedURLLoaderFactory>(
&factory_); &factory_);
...@@ -128,12 +127,12 @@ class IOSImageDataFetcherWrapperTest : public PlatformTest { ...@@ -128,12 +127,12 @@ class IOSImageDataFetcherWrapperTest : public PlatformTest {
// Message loop for the main test thread. // Message loop for the main test thread.
base::test::TaskEnvironment environment_; base::test::TaskEnvironment environment_;
base::mac::ScopedBlock<ImageDataFetcherBlock> callback_; __strong ImageDataFetcherBlock callback_;
network::TestURLLoaderFactory factory_; network::TestURLLoaderFactory factory_;
scoped_refptr<network::SharedURLLoaderFactory> shared_factory_; scoped_refptr<network::SharedURLLoaderFactory> shared_factory_;
std::unique_ptr<IOSImageDataFetcherWrapper> image_fetcher_; std::unique_ptr<IOSImageDataFetcherWrapper> image_fetcher_;
NSData* result_data_ = nil; __strong NSData* result_data_ = nil;
UIImage* result_ = nil; __strong UIImage* result_ = nil;
bool called_ = false; bool called_ = false;
private: private:
......
...@@ -10,7 +10,6 @@ ...@@ -10,7 +10,6 @@
#include <memory> #include <memory>
#import "base/mac/scoped_nsobject.h"
#include "base/memory/ref_counted.h" #include "base/memory/ref_counted.h"
#include "third_party/libwebp/src/webp/decode.h" #include "third_party/libwebp/src/webp/decode.h"
...@@ -89,8 +88,8 @@ class WebpDecoder : public base::RefCountedThreadSafe<WebpDecoder> { ...@@ -89,8 +88,8 @@ class WebpDecoder : public base::RefCountedThreadSafe<WebpDecoder> {
WebPDecoderConfig config_; WebPDecoderConfig config_;
WebpDecoder::State state_; WebpDecoder::State state_;
std::unique_ptr<WebPIDecoder, WebPIDecoderDeleter> incremental_decoder_; std::unique_ptr<WebPIDecoder, WebPIDecoderDeleter> incremental_decoder_;
base::scoped_nsobject<NSData> output_buffer_; __strong NSData* output_buffer_;
base::scoped_nsobject<NSMutableData> features_; __strong NSMutableData* features_;
int has_alpha_; int has_alpha_;
}; };
......
...@@ -190,7 +190,7 @@ void WebpDecoder::DoReadFeatures(NSData* data) { ...@@ -190,7 +190,7 @@ void WebpDecoder::DoReadFeatures(NSData* data) {
if (features_) if (features_)
[features_ appendData:data]; [features_ appendData:data];
else else
features_.reset([[NSMutableData alloc] initWithData:data]); features_ = [[NSMutableData alloc] initWithData:data];
VP8StatusCode status = VP8StatusCode status =
WebPGetFeatures(static_cast<const uint8_t*>([features_ bytes]), WebPGetFeatures(static_cast<const uint8_t*>([features_ bytes]),
[features_ length], &config_.input); [features_ length], &config_.input);
...@@ -217,16 +217,16 @@ void WebpDecoder::DoReadFeatures(NSData* data) { ...@@ -217,16 +217,16 @@ void WebpDecoder::DoReadFeatures(NSData* data) {
break; break;
} }
WriteTiffHeader(dst, width, height, bytes_per_px, has_alpha_); WriteTiffHeader(dst, width, height, bytes_per_px, has_alpha_);
output_buffer_.reset([[NSData alloc] initWithBytesNoCopy:dst output_buffer_ = [[NSData alloc] initWithBytesNoCopy:dst
length:total_size length:total_size
freeWhenDone:YES]); freeWhenDone:YES];
config_.output.is_external_memory = 1; config_.output.is_external_memory = 1;
config_.output.u.RGBA.rgba = dst + kHeaderSize; config_.output.u.RGBA.rgba = dst + kHeaderSize;
// Start decoding. // Start decoding.
state_ = READING_DATA; state_ = READING_DATA;
incremental_decoder_.reset(WebPINewDecoder(&config_.output)); incremental_decoder_.reset(WebPINewDecoder(&config_.output));
DoReadData(features_); DoReadData(features_);
features_.reset(); features_ = nil;
break; break;
} }
case VP8_STATUS_NOT_ENOUGH_DATA: case VP8_STATUS_NOT_ENOUGH_DATA:
...@@ -276,34 +276,33 @@ bool WebpDecoder::DoSendData() { ...@@ -276,34 +276,33 @@ bool WebpDecoder::DoSendData() {
return false; return false;
DCHECK_EQ(static_cast<const uint8_t*>([output_buffer_ bytes]) + kHeaderSize, DCHECK_EQ(static_cast<const uint8_t*>([output_buffer_ bytes]) + kHeaderSize,
data_ptr); data_ptr);
base::scoped_nsobject<NSData> result_data; NSData* result_data = nil;
// When the WebP image is larger than |kRecompressionThreshold| it is // When the WebP image is larger than |kRecompressionThreshold| it is
// compressed to JPEG or PNG. Otherwise, the uncompressed TIFF is used. // compressed to JPEG or PNG. Otherwise, the uncompressed TIFF is used.
DecodedImageFormat format = TIFF; DecodedImageFormat format = TIFF;
if (width * height > kRecompressionThreshold) { if (width * height > kRecompressionThreshold) {
base::scoped_nsobject<UIImage> tiff_image( UIImage* tiff_image = [[UIImage alloc] initWithData:output_buffer_];
[[UIImage alloc] initWithData:output_buffer_]);
if (!tiff_image) if (!tiff_image)
return false; return false;
// Compress to PNG if the image is transparent, JPEG otherwise. // Compress to PNG if the image is transparent, JPEG otherwise.
// TODO(droger): Use PNG instead of JPEG if the WebP image is lossless. // TODO(droger): Use PNG instead of JPEG if the WebP image is lossless.
if (has_alpha_) { if (has_alpha_) {
result_data.reset(UIImagePNGRepresentation(tiff_image)); result_data = UIImagePNGRepresentation(tiff_image);
format = PNG; format = PNG;
} else { } else {
result_data.reset(UIImageJPEGRepresentation(tiff_image, kJpegQuality)); result_data = UIImageJPEGRepresentation(tiff_image, kJpegQuality);
format = JPEG; format = JPEG;
} }
if (!result_data) if (!result_data)
return false; return false;
} else { } else {
result_data.reset(output_buffer_); result_data = output_buffer_;
} }
UMA_HISTOGRAM_ENUMERATION("WebP.DecodedImageFormat", format, UMA_HISTOGRAM_ENUMERATION("WebP.DecodedImageFormat", format,
DECODED_FORMAT_COUNT); DECODED_FORMAT_COUNT);
delegate_->SetImageFeatures([result_data length], format); delegate_->SetImageFeatures([result_data length], format);
delegate_->OnDataDecoded(result_data); delegate_->OnDataDecoded(result_data);
output_buffer_.reset(); output_buffer_ = nil;
return true; return true;
} }
......
...@@ -16,7 +16,6 @@ ...@@ -16,7 +16,6 @@
#include "base/files/file_path.h" #include "base/files/file_path.h"
#include "base/logging.h" #include "base/logging.h"
#include "base/mac/scoped_cftyperef.h" #include "base/mac/scoped_cftyperef.h"
#import "base/mac/scoped_nsobject.h"
#include "base/memory/ref_counted.h" #include "base/memory/ref_counted.h"
#include "base/path_service.h" #include "base/path_service.h"
#include "base/stl_util.h" #include "base/stl_util.h"
...@@ -47,7 +46,7 @@ class WebpDecoderDelegate : public WebpDecoder::Delegate { ...@@ -47,7 +46,7 @@ class WebpDecoderDelegate : public WebpDecoder::Delegate {
private: private:
virtual ~WebpDecoderDelegate() {} virtual ~WebpDecoderDelegate() {}
base::scoped_nsobject<NSMutableData> image_; __strong NSMutableData* image_;
}; };
class WebpDecoderTest : public testing::Test { class WebpDecoderTest : public testing::Test {
...@@ -169,12 +168,10 @@ class WebpDecoderTest : public testing::Test { ...@@ -169,12 +168,10 @@ class WebpDecoderTest : public testing::Test {
TEST_F(WebpDecoderTest, DecodeToJpeg) { TEST_F(WebpDecoderTest, DecodeToJpeg) {
// Load a WebP image from disk. // Load a WebP image from disk.
base::scoped_nsobject<NSData> webp_image( NSData* webp_image = LoadImage(base::FilePath("test.webp"));
LoadImage(base::FilePath("test.webp")));
ASSERT_TRUE(webp_image != nil); ASSERT_TRUE(webp_image != nil);
// Load reference image. // Load reference image.
base::scoped_nsobject<NSData> jpg_image( NSData* jpg_image = LoadImage(base::FilePath("test.jpg"));
LoadImage(base::FilePath("test.jpg")));
ASSERT_TRUE(jpg_image != nil); ASSERT_TRUE(jpg_image != nil);
// Convert to JPEG. // Convert to JPEG.
EXPECT_CALL(*delegate_, OnFinishedDecoding(true)).Times(1); EXPECT_CALL(*delegate_, OnFinishedDecoding(true)).Times(1);
...@@ -188,12 +185,10 @@ TEST_F(WebpDecoderTest, DecodeToJpeg) { ...@@ -188,12 +185,10 @@ TEST_F(WebpDecoderTest, DecodeToJpeg) {
TEST_F(WebpDecoderTest, DecodeToPng) { TEST_F(WebpDecoderTest, DecodeToPng) {
// Load a WebP image from disk. // Load a WebP image from disk.
base::scoped_nsobject<NSData> webp_image( NSData* webp_image = LoadImage(base::FilePath("test_alpha.webp"));
LoadImage(base::FilePath("test_alpha.webp")));
ASSERT_TRUE(webp_image != nil); ASSERT_TRUE(webp_image != nil);
// Load reference image. // Load reference image.
base::scoped_nsobject<NSData> png_image( NSData* png_image = LoadImage(base::FilePath("test_alpha.png"));
LoadImage(base::FilePath("test_alpha.png")));
ASSERT_TRUE(png_image != nil); ASSERT_TRUE(png_image != nil);
// Convert to PNG. // Convert to PNG.
EXPECT_CALL(*delegate_, OnFinishedDecoding(true)).Times(1); EXPECT_CALL(*delegate_, OnFinishedDecoding(true)).Times(1);
...@@ -207,12 +202,10 @@ TEST_F(WebpDecoderTest, DecodeToPng) { ...@@ -207,12 +202,10 @@ TEST_F(WebpDecoderTest, DecodeToPng) {
TEST_F(WebpDecoderTest, DecodeToTiff) { TEST_F(WebpDecoderTest, DecodeToTiff) {
// Load a WebP image from disk. // Load a WebP image from disk.
base::scoped_nsobject<NSData> webp_image( NSData* webp_image = LoadImage(base::FilePath("test_small.webp"));
LoadImage(base::FilePath("test_small.webp")));
ASSERT_TRUE(webp_image != nil); ASSERT_TRUE(webp_image != nil);
// Load reference image. // Load reference image.
base::scoped_nsobject<NSData> tiff_image( NSData* tiff_image = LoadImage(base::FilePath("test_small.tiff"));
LoadImage(base::FilePath("test_small.tiff")));
ASSERT_TRUE(tiff_image != nil); ASSERT_TRUE(tiff_image != nil);
// Convert to TIFF. // Convert to TIFF.
EXPECT_CALL(*delegate_, OnFinishedDecoding(true)).Times(1); EXPECT_CALL(*delegate_, OnFinishedDecoding(true)).Times(1);
...@@ -226,12 +219,10 @@ TEST_F(WebpDecoderTest, DecodeToTiff) { ...@@ -226,12 +219,10 @@ TEST_F(WebpDecoderTest, DecodeToTiff) {
TEST_F(WebpDecoderTest, StreamedDecode) { TEST_F(WebpDecoderTest, StreamedDecode) {
// Load a WebP image from disk. // Load a WebP image from disk.
base::scoped_nsobject<NSData> webp_image( NSData* webp_image = LoadImage(base::FilePath("test.webp"));
LoadImage(base::FilePath("test.webp")));
ASSERT_TRUE(webp_image != nil); ASSERT_TRUE(webp_image != nil);
// Load reference image. // Load reference image.
base::scoped_nsobject<NSData> jpg_image( NSData* jpg_image = LoadImage(base::FilePath("test.jpg"));
LoadImage(base::FilePath("test.jpg")));
ASSERT_TRUE(jpg_image != nil); ASSERT_TRUE(jpg_image != nil);
// Convert to JPEG in chunks. // Convert to JPEG in chunks.
EXPECT_CALL(*delegate_, OnFinishedDecoding(true)).Times(1); EXPECT_CALL(*delegate_, OnFinishedDecoding(true)).Times(1);
...@@ -240,12 +231,11 @@ TEST_F(WebpDecoderTest, StreamedDecode) { ...@@ -240,12 +231,11 @@ TEST_F(WebpDecoderTest, StreamedDecode) {
const size_t kChunkSize = 10; const size_t kChunkSize = 10;
unsigned int num_chunks = 0; unsigned int num_chunks = 0;
while ([webp_image length] > kChunkSize) { while ([webp_image length] > kChunkSize) {
base::scoped_nsobject<NSData> chunk( NSData* chunk = [webp_image subdataWithRange:NSMakeRange(0, kChunkSize)];
[webp_image subdataWithRange:NSMakeRange(0, kChunkSize)]);
decoder_->OnDataReceived(chunk); decoder_->OnDataReceived(chunk);
webp_image.reset([webp_image webp_image = [webp_image
subdataWithRange:NSMakeRange(kChunkSize, subdataWithRange:NSMakeRange(kChunkSize,
[webp_image length] - kChunkSize)]); [webp_image length] - kChunkSize)];
++num_chunks; ++num_chunks;
} }
if ([webp_image length] > 0u) { if ([webp_image length] > 0u) {
...@@ -261,9 +251,8 @@ TEST_F(WebpDecoderTest, StreamedDecode) { ...@@ -261,9 +251,8 @@ TEST_F(WebpDecoderTest, StreamedDecode) {
TEST_F(WebpDecoderTest, InvalidFormat) { TEST_F(WebpDecoderTest, InvalidFormat) {
EXPECT_CALL(*delegate_, OnFinishedDecoding(false)).Times(1); EXPECT_CALL(*delegate_, OnFinishedDecoding(false)).Times(1);
const char dummy_image[] = "(>'-')> <('-'<) ^('-')^ <('-'<) (>'-')>"; const char dummy_image[] = "(>'-')> <('-'<) ^('-')^ <('-'<) (>'-')>";
base::scoped_nsobject<NSData> data([[NSData alloc] NSData* data = [[NSData alloc] initWithBytes:dummy_image
initWithBytes:dummy_image length:base::size(dummy_image)];
length:base::size(dummy_image)]);
decoder_->OnDataReceived(data); decoder_->OnDataReceived(data);
EXPECT_EQ(0u, [delegate_->GetImage() length]); EXPECT_EQ(0u, [delegate_->GetImage() length]);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment