Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2429)

Unified Diff: chrome/browser/sync/glue/bookmark_change_processor.cc

Issue 661883002: Sync: Optimize FavIcon callbacks from bookmark model. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/sync/glue/bookmark_change_processor.cc
diff --git a/chrome/browser/sync/glue/bookmark_change_processor.cc b/chrome/browser/sync/glue/bookmark_change_processor.cc
index ae0e854ab6b1481d461a8162089cf931aa7765a1..ba174c4a05798f7dcc7789ca43d0fecbcb9b791a 100644
--- a/chrome/browser/sync/glue/bookmark_change_processor.cc
+++ b/chrome/browser/sync/glue/bookmark_change_processor.cc
@@ -409,7 +409,49 @@ void BookmarkChangeProcessor::BookmarkNodeMoved(BookmarkModel* model,
void BookmarkChangeProcessor::BookmarkNodeFaviconChanged(
BookmarkModel* model,
const BookmarkNode* node) {
- BookmarkNodeChanged(model, node);
+ if (!CanSyncNode(node)) {
+ return;
+ }
+
+ // We shouldn't see changes to the top-level nodes.
+ if (model->is_permanent_node(node)) {
+ NOTREACHED() << "Saw Favicon update to permanent node!";
+ return;
+ }
+
+ // Ignore changes with empty images. This can happen if the favicon is
+ // still being loaded.
+ const gfx::Image& favicon = model->GetFavicon(node);
Nicolas Zea 2014/10/20 18:04:46 it seems like all of this logic, with the exceptio
stanisc 2014/10/20 18:39:21 Not exactly. BookmarkNodeChanges updates everythin
+ if (favicon.IsEmpty()) {
+ return;
+ }
+
+ int64 new_version = syncer::syncable::kInvalidTransactionVersion;
+ int64 sync_id = syncer::kInvalidId;
+ {
+ // Acquire a scoped write lock via a transaction.
+ syncer::WriteTransaction trans(FROM_HERE, share_handle(), &new_version);
+ sync_id = model_associator_->GetSyncIdFromChromeId(node->id());
+ if (sync_id != syncer::kInvalidId) {
+ // Lookup the sync node that's associated with |node|.
+ syncer::WriteNode sync_node(&trans);
+ if (!model_associator_->InitSyncNodeFromChromeId(node->id(),
+ &sync_node)) {
+ syncer::SyncError error(FROM_HERE,
+ syncer::SyncError::DATATYPE_ERROR,
+ "Failed to init sync node from chrome node",
+ syncer::BOOKMARKS);
+ error_handler()->OnSingleDataTypeUnrecoverableError(error);
+ }
+ SetSyncNodeFavicon(node, model, &sync_node);
+ } else {
+ NOTREACHED() << "Saw Favicon update to a node unknown to Sync!";
+ return;
+ }
+ }
+
+ UpdateTransactionVersion(
+ new_version, model, std::vector<const BookmarkNode*>(1, node));
}
void BookmarkChangeProcessor::BookmarkNodeChildrenReordered(
@@ -880,12 +922,24 @@ void BookmarkChangeProcessor::SetSyncNodeFavicon(
scoped_refptr<base::RefCountedMemory> favicon_bytes(NULL);
EncodeFavicon(bookmark_node, model, &favicon_bytes);
if (favicon_bytes.get() && favicon_bytes->size()) {
- sync_pb::BookmarkSpecifics updated_specifics(
- sync_node->GetBookmarkSpecifics());
- updated_specifics.set_favicon(favicon_bytes->front(),
- favicon_bytes->size());
- updated_specifics.set_icon_url(bookmark_node->icon_url().spec());
- sync_node->SetBookmarkSpecifics(updated_specifics);
+ const sync_pb::BookmarkSpecifics& specifics =
+ sync_node->GetBookmarkSpecifics();
+ // Check for changes before updating. When an favicon is initially set by
Nicolas Zea 2014/10/20 18:04:46 nit: "When an favicon" -> "When a favicon"
stanisc 2014/11/03 23:35:35 Removed this code.
+ // sync for a newly synced bookmark, its favicon comes back to Sync via
+ // BookmarkNodeFaviconChanged notification. This allows to avoid unnecessary
Nicolas Zea 2014/10/20 18:04:46 nit: "This allows to" -> "This allows us to" and "
stanisc 2014/11/03 23:35:35 Removed this code for now.
+ // writing to the directory and the syncer cycle.
+ if (!specifics.has_favicon() || !specifics.has_icon_url() ||
+ specifics.icon_url() != bookmark_node->icon_url().spec() ||
+ specifics.favicon().size() != favicon_bytes->size() ||
+ memcmp(specifics.favicon().c_str(),
+ favicon_bytes->front(),
+ favicon_bytes->size()) != 0) {
Nicolas Zea 2014/10/20 18:04:46 I find it strange that this would result in saving
stanisc 2014/10/20 18:39:21 It results in savings because it avoids getting a
+ sync_pb::BookmarkSpecifics updated_specifics(specifics);
+ updated_specifics.set_favicon(favicon_bytes->front(),
+ favicon_bytes->size());
+ updated_specifics.set_icon_url(bookmark_node->icon_url().spec());
+ sync_node->SetBookmarkSpecifics(updated_specifics);
+ }
}
}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698