OLD | NEW |
---|---|
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/sync/glue/bookmark_change_processor.h" | 5 #include "chrome/browser/sync/glue/bookmark_change_processor.h" |
6 | 6 |
7 #include <map> | 7 #include <map> |
8 #include <stack> | 8 #include <stack> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 391 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
402 } | 402 } |
403 } | 403 } |
404 | 404 |
405 UpdateTransactionVersion(new_version, model, | 405 UpdateTransactionVersion(new_version, model, |
406 std::vector<const BookmarkNode*>(1, child)); | 406 std::vector<const BookmarkNode*>(1, child)); |
407 } | 407 } |
408 | 408 |
409 void BookmarkChangeProcessor::BookmarkNodeFaviconChanged( | 409 void BookmarkChangeProcessor::BookmarkNodeFaviconChanged( |
410 BookmarkModel* model, | 410 BookmarkModel* model, |
411 const BookmarkNode* node) { | 411 const BookmarkNode* node) { |
412 BookmarkNodeChanged(model, node); | 412 if (!CanSyncNode(node)) { |
413 return; | |
414 } | |
415 | |
416 // We shouldn't see changes to the top-level nodes. | |
417 if (model->is_permanent_node(node)) { | |
418 NOTREACHED() << "Saw Favicon update to permanent node!"; | |
419 return; | |
420 } | |
421 | |
422 // Ignore changes with empty images. This can happen if the favicon is | |
423 // still being loaded. | |
424 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
| |
425 if (favicon.IsEmpty()) { | |
426 return; | |
427 } | |
428 | |
429 int64 new_version = syncer::syncable::kInvalidTransactionVersion; | |
430 int64 sync_id = syncer::kInvalidId; | |
431 { | |
432 // Acquire a scoped write lock via a transaction. | |
433 syncer::WriteTransaction trans(FROM_HERE, share_handle(), &new_version); | |
434 sync_id = model_associator_->GetSyncIdFromChromeId(node->id()); | |
435 if (sync_id != syncer::kInvalidId) { | |
436 // Lookup the sync node that's associated with |node|. | |
437 syncer::WriteNode sync_node(&trans); | |
438 if (!model_associator_->InitSyncNodeFromChromeId(node->id(), | |
439 &sync_node)) { | |
440 syncer::SyncError error(FROM_HERE, | |
441 syncer::SyncError::DATATYPE_ERROR, | |
442 "Failed to init sync node from chrome node", | |
443 syncer::BOOKMARKS); | |
444 error_handler()->OnSingleDataTypeUnrecoverableError(error); | |
445 } | |
446 SetSyncNodeFavicon(node, model, &sync_node); | |
447 } else { | |
448 NOTREACHED() << "Saw Favicon update to a node unknown to Sync!"; | |
449 return; | |
450 } | |
451 } | |
452 | |
453 UpdateTransactionVersion( | |
454 new_version, model, std::vector<const BookmarkNode*>(1, node)); | |
413 } | 455 } |
414 | 456 |
415 void BookmarkChangeProcessor::BookmarkNodeChildrenReordered( | 457 void BookmarkChangeProcessor::BookmarkNodeChildrenReordered( |
416 BookmarkModel* model, const BookmarkNode* node) { | 458 BookmarkModel* model, const BookmarkNode* node) { |
417 if (!CanSyncNode(node)) | 459 if (!CanSyncNode(node)) |
418 return; | 460 return; |
419 int64 new_version = syncer::syncable::kInvalidTransactionVersion; | 461 int64 new_version = syncer::syncable::kInvalidTransactionVersion; |
420 std::vector<const BookmarkNode*> children; | 462 std::vector<const BookmarkNode*> children; |
421 { | 463 { |
422 // Acquire a scoped write lock via a transaction. | 464 // Acquire a scoped write lock via a transaction. |
(...skipping 450 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
873 } | 915 } |
874 | 916 |
875 // static | 917 // static |
876 void BookmarkChangeProcessor::SetSyncNodeFavicon( | 918 void BookmarkChangeProcessor::SetSyncNodeFavicon( |
877 const BookmarkNode* bookmark_node, | 919 const BookmarkNode* bookmark_node, |
878 BookmarkModel* model, | 920 BookmarkModel* model, |
879 syncer::WriteNode* sync_node) { | 921 syncer::WriteNode* sync_node) { |
880 scoped_refptr<base::RefCountedMemory> favicon_bytes(NULL); | 922 scoped_refptr<base::RefCountedMemory> favicon_bytes(NULL); |
881 EncodeFavicon(bookmark_node, model, &favicon_bytes); | 923 EncodeFavicon(bookmark_node, model, &favicon_bytes); |
882 if (favicon_bytes.get() && favicon_bytes->size()) { | 924 if (favicon_bytes.get() && favicon_bytes->size()) { |
883 sync_pb::BookmarkSpecifics updated_specifics( | 925 const sync_pb::BookmarkSpecifics& specifics = |
884 sync_node->GetBookmarkSpecifics()); | 926 sync_node->GetBookmarkSpecifics(); |
885 updated_specifics.set_favicon(favicon_bytes->front(), | 927 // 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.
| |
886 favicon_bytes->size()); | 928 // sync for a newly synced bookmark, its favicon comes back to Sync via |
887 updated_specifics.set_icon_url(bookmark_node->icon_url().spec()); | 929 // 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.
| |
888 sync_node->SetBookmarkSpecifics(updated_specifics); | 930 // writing to the directory and the syncer cycle. |
931 if (!specifics.has_favicon() || !specifics.has_icon_url() || | |
932 specifics.icon_url() != bookmark_node->icon_url().spec() || | |
933 specifics.favicon().size() != favicon_bytes->size() || | |
934 memcmp(specifics.favicon().c_str(), | |
935 favicon_bytes->front(), | |
936 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
| |
937 sync_pb::BookmarkSpecifics updated_specifics(specifics); | |
938 updated_specifics.set_favicon(favicon_bytes->front(), | |
939 favicon_bytes->size()); | |
940 updated_specifics.set_icon_url(bookmark_node->icon_url().spec()); | |
941 sync_node->SetBookmarkSpecifics(updated_specifics); | |
942 } | |
889 } | 943 } |
890 } | 944 } |
891 | 945 |
892 bool BookmarkChangeProcessor::CanSyncNode(const BookmarkNode* node) { | 946 bool BookmarkChangeProcessor::CanSyncNode(const BookmarkNode* node) { |
893 return bookmark_model_->client()->CanSyncNode(node); | 947 return bookmark_model_->client()->CanSyncNode(node); |
894 } | 948 } |
895 | 949 |
896 } // namespace browser_sync | 950 } // namespace browser_sync |
OLD | NEW |