Commit 950b89fb authored by rfevang's avatar rfevang Committed by Commit bot

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}
parent 2c6566f2
......@@ -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,
......
......@@ -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.
......
......@@ -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());
}
......@@ -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 {
......
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