summaryrefslogtreecommitdiffstats
path: root/components/enhanced_bookmarks/image_store_ios_unittest.mm
diff options
context:
space:
mode:
authorkkimlabs <kkimlabs@chromium.org>2015-04-03 03:08:09 -0700
committerCommit bot <commit-bot@chromium.org>2015-04-03 10:08:37 +0000
commit16a0d2a22d17e3932432dab4559e63c5134aaccc (patch)
treecb3602e115c8dc531195283d2c417825005f00ad /components/enhanced_bookmarks/image_store_ios_unittest.mm
parenta4c00a7ec01b3308c98cfad88b4bf3af1b4fde2b (diff)
downloadchromium_src-16a0d2a22d17e3932432dab4559e63c5134aaccc.zip
chromium_src-16a0d2a22d17e3932432dab4559e63c5134aaccc.tar.gz
chromium_src-16a0d2a22d17e3932432dab4559e63c5134aaccc.tar.bz2
Fix crashes due to gfx::Image unsafe thread passing
gfx::Image has |storage_| member which is base::RefCounted, not thread safe. Thus passing around gfx::Image to other threads by copying is incorrect. Workaround by using scoped_ptr and making ImageRecord class RefCountedThreadSafe. Related discussion: https://groups.google.com/a/chromium.org/forum/#!topic/chromium-dev/8LqVoXQ_2bo BUG=471800 Review URL: https://codereview.chromium.org/1031293002 Cr-Commit-Position: refs/heads/master@{#323720}
Diffstat (limited to 'components/enhanced_bookmarks/image_store_ios_unittest.mm')
-rw-r--r--components/enhanced_bookmarks/image_store_ios_unittest.mm22
1 files changed, 13 insertions, 9 deletions
diff --git a/components/enhanced_bookmarks/image_store_ios_unittest.mm b/components/enhanced_bookmarks/image_store_ios_unittest.mm
index 19dd5fa..a22a366 100644
--- a/components/enhanced_bookmarks/image_store_ios_unittest.mm
+++ b/components/enhanced_bookmarks/image_store_ios_unittest.mm
@@ -22,7 +22,8 @@ namespace {
// Generates a gfx::Image with a random UIImage representation. Uses off-center
// circle gradient to make all pixels slightly different in order to detect
// small image alterations.
-gfx::Image GenerateRandomUIImage(const gfx::Size& size, float scale) {
+scoped_ptr<gfx::Image> GenerateRandomUIImage(const gfx::Size& size,
+ float scale) {
UIGraphicsBeginImageContextWithOptions(CGSizeMake(size.width(),
size.height()),
YES, // opaque.
@@ -56,7 +57,7 @@ gfx::Image GenerateRandomUIImage(const gfx::Size& size, float scale) {
kCGGradientDrawsAfterEndLocation);
UIImage* image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
- return gfx::Image([image retain]);
+ return scoped_ptr<gfx::Image>(new gfx::Image([image retain]));
}
// Returns true if the two images are identical.
@@ -141,15 +142,18 @@ TYPED_TEST(ImageStoreUnitTestIOS, StoringImagesPreservesScale) {
const gfx::Size image_size(42, 24);
for (unsigned long i = 0; i < arraysize(scales); i++) {
const GURL url("foo://bar");
- const enhanced_bookmarks::ImageRecord image_in(
- GenerateRandomUIImage(image_size, scales[i]), GURL("http://a.jpg"),
- SK_ColorGREEN);
+ scoped_refptr<enhanced_bookmarks::ImageRecord> image_in(
+ new enhanced_bookmarks::ImageRecord(
+ GenerateRandomUIImage(image_size, scales[i]),
+ GURL("http://a.jpg"),
+ SK_ColorGREEN));
this->store_->Insert(url, image_in);
- const enhanced_bookmarks::ImageRecord image_out = this->store_->Get(url);
+ scoped_refptr<enhanced_bookmarks::ImageRecord> image_out =
+ this->store_->Get(url);
- EXPECT_EQ(image_in.url, image_out.url);
- EXPECT_TRUE(CompareImages(image_in.image, image_out.image));
- EXPECT_EQ(image_in.dominant_color, image_out.dominant_color);
+ EXPECT_EQ(image_in->url, image_out->url);
+ EXPECT_TRUE(CompareImages(*image_in->image, *image_out->image));
+ EXPECT_EQ(image_in->dominant_color, image_out->dominant_color);
}
}