diff options
author | rfevang <rfevang@chromium.org> | 2015-02-04 12:05:42 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-02-04 20:08:02 +0000 |
commit | 950b89fb23bce3b60e02bcdcccfa7e75c345dc31 (patch) | |
tree | c5f7402765c459bf4955d9bea516cde196a04fc9 /components/enhanced_bookmarks | |
parent | 2c6566f22ede274f109ac166dadd851812a5003c (diff) | |
download | chromium_src-950b89fb23bce3b60e02bcdcccfa7e75c345dc31.zip chromium_src-950b89fb23bce3b60e02bcdcccfa7e75c345dc31.tar.gz chromium_src-950b89fb23bce3b60e02bcdcccfa7e75c345dc31.tar.bz2 |
Add method for removing bookmark image data.
Removes all image data associated with the bookmark, and sets the
user_removed_image flag so the server won't attempt to set a new image
for the bookmark.
BUG=434436
Review URL: https://codereview.chromium.org/891873002
Cr-Commit-Position: refs/heads/master@{#314613}
Diffstat (limited to 'components/enhanced_bookmarks')
4 files changed, 47 insertions, 0 deletions
diff --git a/components/enhanced_bookmarks/enhanced_bookmark_model.cc b/components/enhanced_bookmarks/enhanced_bookmark_model.cc index f9d3478..f114c5a 100644 --- a/components/enhanced_bookmarks/enhanced_bookmark_model.cc +++ b/components/enhanced_bookmarks/enhanced_bookmark_model.cc @@ -226,6 +226,16 @@ bool EnhancedBookmarkModel::SetOriginalImage(const BookmarkNode* node, return true; } +void EnhancedBookmarkModel::RemoveImageData(const BookmarkNode* node) { + DCHECK(node->is_url()); + image::collections::ImageData data; + data.set_user_removed_image(true); + + std::string encoded_data; + base::Base64Encode(data.SerializeAsString(), &encoded_data); + SetMetaInfo(node, kImageDataKey, encoded_data); +} + bool EnhancedBookmarkModel::GetOriginalImage(const BookmarkNode* node, GURL* url, int* width, diff --git a/components/enhanced_bookmarks/enhanced_bookmark_model.h b/components/enhanced_bookmarks/enhanced_bookmark_model.h index 7eab266..1660237 100644 --- a/components/enhanced_bookmarks/enhanced_bookmark_model.h +++ b/components/enhanced_bookmarks/enhanced_bookmark_model.h @@ -86,6 +86,10 @@ class EnhancedBookmarkModel : public KeyedService, int width, int height); + // Removes all image data for the node and sets the user_removed_image flag + // so the server won't try to fetch a new image for the node. + void RemoveImageData(const BookmarkNode* node); + // Returns the url and dimensions of the original scraped image of a // bookmark |node|. // Returns true if the out variables are populated, false otherwise. diff --git a/components/enhanced_bookmarks/enhanced_bookmark_model_unittest.cc b/components/enhanced_bookmarks/enhanced_bookmark_model_unittest.cc index db2c54f..f760d0c 100644 --- a/components/enhanced_bookmarks/enhanced_bookmark_model_unittest.cc +++ b/components/enhanced_bookmarks/enhanced_bookmark_model_unittest.cc @@ -25,6 +25,7 @@ using enhanced_bookmarks::EnhancedBookmarkModel; namespace { const std::string BOOKMARK_URL("http://example.com/index.html"); +const std::string IMAGE_URL("http://example.com/image.jpg"); } // namespace class EnhancedBookmarkModelTest @@ -773,3 +774,24 @@ TEST_F(EnhancedBookmarkModelTest, AddsRemoteIdToNonClonedKeys) { bookmark_model_->non_cloned_keys(); EXPECT_TRUE(non_cloned_keys.find("stars.id") != non_cloned_keys.end()); } + +TEST_F(EnhancedBookmarkModelTest, RemoveImageData) { + const BookmarkNode* node = AddBookmark(); + model_->SetAllImages(node, GURL(IMAGE_URL), 64, 64, GURL(IMAGE_URL), 16, 16); + + GURL url; + int width, height; + EXPECT_TRUE(model_->GetOriginalImage(node, &url, &width, &height)); + EXPECT_TRUE(model_->GetThumbnailImage(node, &url, &width, &height)); + + model_->RemoveImageData(node); + EXPECT_FALSE(model_->GetOriginalImage(node, &url, &width, &height)); + EXPECT_FALSE(model_->GetThumbnailImage(node, &url, &width, &height)); + + std::string meta_info = GetMetaInfoField(node, "stars.imageData"); + std::string decoded; + ASSERT_TRUE(base::Base64Decode(meta_info, &decoded)); + image::collections::ImageData data; + ASSERT_TRUE(data.ParseFromString(decoded)); + EXPECT_TRUE(data.user_removed_image()); +} diff --git a/components/enhanced_bookmarks/proto/metadata.proto b/components/enhanced_bookmarks/proto/metadata.proto index bf4f18c..4a5f2ec 100644 --- a/components/enhanced_bookmarks/proto/metadata.proto +++ b/components/enhanced_bookmarks/proto/metadata.proto @@ -26,6 +26,17 @@ message ImageData { // Information about the server hosted thumbnail. optional ImageInfo thumbnail_info = 3; + + // The expiration timestamp of the served thumbnail, in microseconds since + // epoch. The thumbnail is only guaranteed until this time, afterwards the + // URL may be broken. + // If expiration_timestamp is not present, then whoever set the thumbnail_info + // should guarantee that the thumbnail will not expire. + optional int64 expiration_timestamp = 5; + + // Represents an explicit user action to remove an image. This will prevent + // any additional backfilling once this is set. + optional bool user_removed_image = 6; } message PageData { |