| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #include "chrome/browser/sync/glue/bookmark_change_processor.h" | 4 #include "chrome/browser/sync/glue/bookmark_change_processor.h" |
| 5 | 5 |
| 6 #include <stack> | 6 #include <stack> |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/string16.h" | 9 #include "base/string16.h" |
| 10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
| (...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 184 int index, | 184 int index, |
| 185 const BookmarkNode* node) { | 185 const BookmarkNode* node) { |
| 186 DCHECK(running()); | 186 DCHECK(running()); |
| 187 RemoveSyncNodeHierarchy(node); | 187 RemoveSyncNodeHierarchy(node); |
| 188 } | 188 } |
| 189 | 189 |
| 190 void BookmarkChangeProcessor::BookmarkNodeChanged(BookmarkModel* model, | 190 void BookmarkChangeProcessor::BookmarkNodeChanged(BookmarkModel* model, |
| 191 const BookmarkNode* node) { | 191 const BookmarkNode* node) { |
| 192 DCHECK(running()); | 192 DCHECK(running()); |
| 193 // We shouldn't see changes to the top-level nodes. | 193 // We shouldn't see changes to the top-level nodes. |
| 194 if (node == model->GetBookmarkBarNode() || node == model->other_node()) { | 194 if (node == model->GetBookmarkBarNode() || node == model->other_node() || |
| 195 node == model->synced_node()) { |
| 195 NOTREACHED() << "Saw update to permanent node!"; | 196 NOTREACHED() << "Saw update to permanent node!"; |
| 196 return; | 197 return; |
| 197 } | 198 } |
| 198 | 199 |
| 199 // Acquire a scoped write lock via a transaction. | 200 // Acquire a scoped write lock via a transaction. |
| 200 sync_api::WriteTransaction trans(share_handle()); | 201 sync_api::WriteTransaction trans(share_handle()); |
| 201 | 202 |
| 202 // Lookup the sync node that's associated with |node|. | 203 // Lookup the sync node that's associated with |node|. |
| 203 sync_api::WriteNode sync_node(&trans); | 204 sync_api::WriteNode sync_node(&trans); |
| 204 if (!model_associator_->InitSyncNodeFromChromeId(node->id(), &sync_node)) { | 205 if (!model_associator_->InitSyncNodeFromChromeId(node->id(), &sync_node)) { |
| (...skipping 13 matching lines...) Expand all Loading... |
| 218 &sync_node)); | 219 &sync_node)); |
| 219 } | 220 } |
| 220 | 221 |
| 221 | 222 |
| 222 void BookmarkChangeProcessor::BookmarkNodeMoved(BookmarkModel* model, | 223 void BookmarkChangeProcessor::BookmarkNodeMoved(BookmarkModel* model, |
| 223 const BookmarkNode* old_parent, int old_index, | 224 const BookmarkNode* old_parent, int old_index, |
| 224 const BookmarkNode* new_parent, int new_index) { | 225 const BookmarkNode* new_parent, int new_index) { |
| 225 DCHECK(running()); | 226 DCHECK(running()); |
| 226 const BookmarkNode* child = new_parent->GetChild(new_index); | 227 const BookmarkNode* child = new_parent->GetChild(new_index); |
| 227 // We shouldn't see changes to the top-level nodes. | 228 // We shouldn't see changes to the top-level nodes. |
| 228 if (child == model->GetBookmarkBarNode() || child == model->other_node()) { | 229 if (child == model->GetBookmarkBarNode() || child == model->other_node() || |
| 230 child == model->synced_node()) { |
| 229 NOTREACHED() << "Saw update to permanent node!"; | 231 NOTREACHED() << "Saw update to permanent node!"; |
| 230 return; | 232 return; |
| 231 } | 233 } |
| 232 | 234 |
| 233 // Acquire a scoped write lock via a transaction. | 235 // Acquire a scoped write lock via a transaction. |
| 234 sync_api::WriteTransaction trans(share_handle()); | 236 sync_api::WriteTransaction trans(share_handle()); |
| 235 | 237 |
| 236 // Lookup the sync node that's associated with |child|. | 238 // Lookup the sync node that's associated with |child|. |
| 237 sync_api::WriteNode sync_node(&trans); | 239 sync_api::WriteNode sync_node(&trans); |
| 238 if (!model_associator_->InitSyncNodeFromChromeId(child->id(), &sync_node)) { | 240 if (!model_associator_->InitSyncNodeFromChromeId(child->id(), &sync_node)) { |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 377 model->RemoveObserver(this); | 379 model->RemoveObserver(this); |
| 378 | 380 |
| 379 // A parent to hold nodes temporarily orphaned by parent deletion. It is | 381 // A parent to hold nodes temporarily orphaned by parent deletion. It is |
| 380 // lazily created inside the loop. | 382 // lazily created inside the loop. |
| 381 const BookmarkNode* foster_parent = NULL; | 383 const BookmarkNode* foster_parent = NULL; |
| 382 for (int i = 0; i < change_count; ++i) { | 384 for (int i = 0; i < change_count; ++i) { |
| 383 const BookmarkNode* dst = | 385 const BookmarkNode* dst = |
| 384 model_associator_->GetChromeNodeFromSyncId(changes[i].id); | 386 model_associator_->GetChromeNodeFromSyncId(changes[i].id); |
| 385 // Ignore changes to the permanent top-level nodes. We only care about | 387 // Ignore changes to the permanent top-level nodes. We only care about |
| 386 // their children. | 388 // their children. |
| 387 if ((dst == model->GetBookmarkBarNode()) || (dst == model->other_node())) | 389 if ((dst == model->GetBookmarkBarNode()) || (dst==model->other_node()) || |
| 390 (dst == model->synced_node())) |
| 388 continue; | 391 continue; |
| 389 if (changes[i].action == | 392 if (changes[i].action == |
| 390 sync_api::SyncManager::ChangeRecord::ACTION_DELETE) { | 393 sync_api::SyncManager::ChangeRecord::ACTION_DELETE) { |
| 391 // Deletions should always be at the front of the list. | 394 // Deletions should always be at the front of the list. |
| 392 DCHECK(i == 0 || changes[i-1].action == changes[i].action); | 395 DCHECK(i == 0 || changes[i-1].action == changes[i].action); |
| 393 // Children of a deleted node should not be deleted; they may be | 396 // Children of a deleted node should not be deleted; they may be |
| 394 // reparented by a later change record. Move them to a temporary place. | 397 // reparented by a later change record. Move them to a temporary place. |
| 395 DCHECK(dst) << "Could not find node to be deleted"; | 398 DCHECK(dst) << "Could not find node to be deleted"; |
| 396 if (!dst) // Can't do anything if we can't find the chrome node. | 399 if (!dst) // Can't do anything if we can't find the chrome node. |
| 397 continue; | 400 continue; |
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 550 const BookmarkNode* bookmark_node, | 553 const BookmarkNode* bookmark_node, |
| 551 BookmarkModel* model, | 554 BookmarkModel* model, |
| 552 sync_api::WriteNode* sync_node) { | 555 sync_api::WriteNode* sync_node) { |
| 553 std::vector<unsigned char> favicon_bytes; | 556 std::vector<unsigned char> favicon_bytes; |
| 554 EncodeFavicon(bookmark_node, model, &favicon_bytes); | 557 EncodeFavicon(bookmark_node, model, &favicon_bytes); |
| 555 if (!favicon_bytes.empty()) | 558 if (!favicon_bytes.empty()) |
| 556 sync_node->SetFaviconBytes(favicon_bytes); | 559 sync_node->SetFaviconBytes(favicon_bytes); |
| 557 } | 560 } |
| 558 | 561 |
| 559 } // namespace browser_sync | 562 } // namespace browser_sync |
| OLD | NEW |