summaryrefslogtreecommitdiffstats
path: root/components/enhanced_bookmarks/image_store_unittest.cc
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_unittest.cc
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_unittest.cc')
-rw-r--r--components/enhanced_bookmarks/image_store_unittest.cc93
1 files changed, 54 insertions, 39 deletions
diff --git a/components/enhanced_bookmarks/image_store_unittest.cc b/components/enhanced_bookmarks/image_store_unittest.cc
index e0d5ace..043c5f2 100644
--- a/components/enhanced_bookmarks/image_store_unittest.cc
+++ b/components/enhanced_bookmarks/image_store_unittest.cc
@@ -19,29 +19,31 @@
namespace {
-gfx::Image CreateImage(int width, int height, int a, int r, int g, int b) {
+scoped_ptr<gfx::Image> CreateImage(
+ int width, int height, int a, int r, int g, int b) {
SkBitmap bitmap;
bitmap.allocN32Pixels(width, height);
bitmap.eraseARGB(a, r, g, b);
- gfx::Image image(gfx::Image::CreateFrom1xBitmap(bitmap));
+ scoped_ptr<gfx::Image> image(
+ new gfx::Image(gfx::Image::CreateFrom1xBitmap(bitmap)));
#if defined(OS_IOS)
// Make sure the image has a kImageRepCocoaTouch.
- image.ToUIImage();
+ image->ToUIImage();
#endif // defined(OS_IOS)
return image;
}
-gfx::Image GenerateWhiteImage() {
+scoped_ptr<gfx::Image> GenerateWhiteImage() {
return CreateImage(42, 24, 255, 255, 255, 255);
}
-gfx::Image GenerateBlackImage(int width, int height) {
+scoped_ptr<gfx::Image> GenerateBlackImage(int width, int height) {
return CreateImage(width, height, 255, 0, 0, 0);
}
-gfx::Image GenerateBlackImage() {
+scoped_ptr<gfx::Image> GenerateBlackImage() {
return GenerateBlackImage(42, 24);
}
@@ -97,7 +99,7 @@ bool CreateV1PersistentImageStoreDB(const base::FilePath& path) {
statement.BindString(0, "foo://bar");
statement.BindString(1, "http://a.jpg");
scoped_refptr<base::RefCountedMemory> image_bytes =
- enhanced_bookmarks::BytesForImage(GenerateWhiteImage());
+ enhanced_bookmarks::BytesForImage(*GenerateWhiteImage());
statement.BindBlob(2, image_bytes->front(), (int)image_bytes->size());
statement.BindInt(3, 42);
statement.BindInt(4, 24);
@@ -170,8 +172,9 @@ TYPED_TEST(ImageStoreUnitTest, StartsEmpty) {
}
TYPED_TEST(ImageStoreUnitTest, StoreOne) {
- const enhanced_bookmarks::ImageRecord image(
- GenerateBlackImage(), GURL("http://a.jpg"), SK_ColorBLACK);
+ scoped_refptr<enhanced_bookmarks::ImageRecord> image(
+ new enhanced_bookmarks::ImageRecord(
+ GenerateBlackImage(), GURL("http://a.jpg"), SK_ColorBLACK));
this->store_->Insert(GURL("foo://bar"), image);
std::set<GURL> all_urls;
@@ -183,24 +186,27 @@ TYPED_TEST(ImageStoreUnitTest, StoreOne) {
TYPED_TEST(ImageStoreUnitTest, Retrieve) {
const GURL url("foo://bar");
- const enhanced_bookmarks::ImageRecord image_in(
- CreateImage(42, 24, 1, 0, 0, 1), GURL("http://a.jpg"), SK_ColorBLUE);
+ scoped_refptr<enhanced_bookmarks::ImageRecord> image_in(
+ new enhanced_bookmarks::ImageRecord(
+ CreateImage(42, 24, 1, 0, 0, 1), GURL("http://a.jpg"), SK_ColorBLUE));
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);
const gfx::Size size = this->store_->GetSize(url);
EXPECT_EQ(42, size.width());
EXPECT_EQ(24, size.height());
- EXPECT_EQ(image_in.url, image_out.url);
- EXPECT_TRUE(CompareImages(image_in.image, image_out.image));
- EXPECT_EQ(SK_ColorBLUE, image_out.dominant_color);
+ EXPECT_EQ(image_in->url, image_out->url);
+ EXPECT_TRUE(CompareImages(*image_in->image, *image_out->image));
+ EXPECT_EQ(SK_ColorBLUE, image_out->dominant_color);
}
TYPED_TEST(ImageStoreUnitTest, Erase) {
const GURL url("foo://bar");
- const enhanced_bookmarks::ImageRecord image(
- GenerateBlackImage(), GURL("http://a.jpg"), SK_ColorBLACK);
+ scoped_refptr<enhanced_bookmarks::ImageRecord> image(
+ new enhanced_bookmarks::ImageRecord(
+ GenerateBlackImage(), GURL("http://a.jpg"), SK_ColorBLACK));
this->store_->Insert(url, image);
this->store_->Erase(url);
@@ -212,12 +218,14 @@ TYPED_TEST(ImageStoreUnitTest, Erase) {
TYPED_TEST(ImageStoreUnitTest, ClearAll) {
const GURL url_foo("http://foo");
- const enhanced_bookmarks::ImageRecord black_image(
- GenerateBlackImage(), GURL("http://a.jpg"), SK_ColorBLACK);
+ scoped_refptr<enhanced_bookmarks::ImageRecord> black_image(
+ new enhanced_bookmarks::ImageRecord(
+ GenerateBlackImage(), GURL("http://a.jpg"), SK_ColorBLACK));
this->store_->Insert(url_foo, black_image);
const GURL url_bar("http://bar");
- const enhanced_bookmarks::ImageRecord white_image(
- GenerateWhiteImage(), GURL("http://a.jpg"), SK_ColorWHITE);
+ scoped_refptr<enhanced_bookmarks::ImageRecord> white_image(
+ new enhanced_bookmarks::ImageRecord(
+ GenerateWhiteImage(), GURL("http://a.jpg"), SK_ColorWHITE));
this->store_->Insert(url_bar, white_image);
this->store_->ClearAll();
@@ -231,29 +239,34 @@ TYPED_TEST(ImageStoreUnitTest, ClearAll) {
TYPED_TEST(ImageStoreUnitTest, Update) {
const GURL url("foo://bar");
- const enhanced_bookmarks::ImageRecord image1(GenerateWhiteImage(),
- GURL("1.jpg"), SK_ColorWHITE);
+
+ scoped_refptr<enhanced_bookmarks::ImageRecord> image1(
+ new enhanced_bookmarks::ImageRecord(
+ GenerateWhiteImage(), GURL("1.jpg"), SK_ColorWHITE));
this->store_->Insert(url, image1);
- const enhanced_bookmarks::ImageRecord image2(GenerateBlackImage(),
- GURL("2.jpg"), SK_ColorBLACK);
+ scoped_refptr<enhanced_bookmarks::ImageRecord> image2(
+ new enhanced_bookmarks::ImageRecord(
+ GenerateBlackImage(), GURL("2.jpg"), SK_ColorBLACK));
this->store_->Insert(url, image2);
- const enhanced_bookmarks::ImageRecord image_out = this->store_->Get(url);
+ scoped_refptr<enhanced_bookmarks::ImageRecord> image_out =
+ this->store_->Get(url);
EXPECT_TRUE(this->store_->HasKey(url));
std::set<GURL> all_urls;
this->store_->GetAllPageUrls(&all_urls);
EXPECT_EQ(1u, all_urls.size());
- EXPECT_EQ(image2.url, image_out.url);
- EXPECT_TRUE(CompareImages(image2.image, image_out.image));
- EXPECT_EQ(SK_ColorBLACK, image_out.dominant_color);
+ EXPECT_EQ(image2->url, image_out->url);
+ EXPECT_TRUE(CompareImages(*image2->image, *image_out->image));
+ EXPECT_EQ(SK_ColorBLACK, image_out->dominant_color);
}
TYPED_TEST(ImageStoreUnitTest, Persistence) {
const GURL url("foo://bar");
- const enhanced_bookmarks::ImageRecord image_in(
- GenerateBlackImage(), GURL("http://a.jpg"), SK_ColorBLACK);
+ scoped_refptr<enhanced_bookmarks::ImageRecord> image_in(
+ new enhanced_bookmarks::ImageRecord(
+ GenerateBlackImage(), GURL("http://a.jpg"), SK_ColorBLACK));
this->store_->Insert(url, image_in);
this->ResetStore();
@@ -263,11 +276,12 @@ TYPED_TEST(ImageStoreUnitTest, Persistence) {
EXPECT_EQ(1u, all_urls.size());
EXPECT_EQ(url, *all_urls.begin());
EXPECT_TRUE(this->store_->HasKey(url));
- 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);
} else {
std::set<GURL> all_urls;
this->store_->GetAllPageUrls(&all_urls);
@@ -285,15 +299,16 @@ TYPED_TEST(ImageStoreUnitTest, MigrationToV2) {
EXPECT_TRUE(CreateV1PersistentImageStoreDB(this->tempDir_.path().Append(
base::FilePath::FromUTF8Unsafe("BookmarkImageAndUrlStore.db"))));
- const enhanced_bookmarks::ImageRecord image_out =
+ scoped_refptr<enhanced_bookmarks::ImageRecord> image_out =
this->store_->Get(GURL("foo://bar"));
- EXPECT_EQ(SK_ColorWHITE, image_out.dominant_color);
+ EXPECT_EQ(SK_ColorWHITE, image_out->dominant_color);
}
TYPED_TEST(ImageStoreUnitTest, GetSize) {
const GURL url("foo://bar");
- const enhanced_bookmarks::ImageRecord image_in(
- GenerateBlackImage(), GURL("http://a.jpg"), SK_ColorBLACK);
+ scoped_refptr<enhanced_bookmarks::ImageRecord> image_in(
+ new enhanced_bookmarks::ImageRecord(
+ GenerateBlackImage(), GURL("http://a.jpg"), SK_ColorBLACK));
int64 size = 0;
if (this->use_persistent_store()) {