| 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 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 181 | 181 |
| 182 void BookmarkChangeProcessor::BookmarkNodeRemoved(BookmarkModel* model, | 182 void BookmarkChangeProcessor::BookmarkNodeRemoved(BookmarkModel* model, |
| 183 const BookmarkNode* parent, | 183 const BookmarkNode* parent, |
| 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 (model->is_permanent_node(node)) { |
| 195 NOTREACHED() << "Saw update to permanent node!"; | 195 NOTREACHED() << "Saw update to permanent node!"; |
| 196 return; | 196 return; |
| 197 } | 197 } |
| 198 | 198 |
| 199 // Acquire a scoped write lock via a transaction. | 199 // Acquire a scoped write lock via a transaction. |
| 200 sync_api::WriteTransaction trans(share_handle()); | 200 sync_api::WriteTransaction trans(share_handle()); |
| 201 | 201 |
| 202 // Lookup the sync node that's associated with |node|. | 202 // Lookup the sync node that's associated with |node|. |
| 203 sync_api::WriteNode sync_node(&trans); | 203 sync_api::WriteNode sync_node(&trans); |
| 204 if (!model_associator_->InitSyncNodeFromChromeId(node->id(), &sync_node)) { | 204 if (!model_associator_->InitSyncNodeFromChromeId(node->id(), &sync_node)) { |
| (...skipping 13 matching lines...) Expand all Loading... |
| 218 &sync_node)); | 218 &sync_node)); |
| 219 } | 219 } |
| 220 | 220 |
| 221 | 221 |
| 222 void BookmarkChangeProcessor::BookmarkNodeMoved(BookmarkModel* model, | 222 void BookmarkChangeProcessor::BookmarkNodeMoved(BookmarkModel* model, |
| 223 const BookmarkNode* old_parent, int old_index, | 223 const BookmarkNode* old_parent, int old_index, |
| 224 const BookmarkNode* new_parent, int new_index) { | 224 const BookmarkNode* new_parent, int new_index) { |
| 225 DCHECK(running()); | 225 DCHECK(running()); |
| 226 const BookmarkNode* child = new_parent->GetChild(new_index); | 226 const BookmarkNode* child = new_parent->GetChild(new_index); |
| 227 // We shouldn't see changes to the top-level nodes. | 227 // We shouldn't see changes to the top-level nodes. |
| 228 if (child == model->GetBookmarkBarNode() || child == model->other_node()) { | 228 if (model->is_permanent_node(child)) { |
| 229 NOTREACHED() << "Saw update to permanent node!"; | 229 NOTREACHED() << "Saw update to permanent node!"; |
| 230 return; | 230 return; |
| 231 } | 231 } |
| 232 | 232 |
| 233 // Acquire a scoped write lock via a transaction. | 233 // Acquire a scoped write lock via a transaction. |
| 234 sync_api::WriteTransaction trans(share_handle()); | 234 sync_api::WriteTransaction trans(share_handle()); |
| 235 | 235 |
| 236 // Lookup the sync node that's associated with |child|. | 236 // Lookup the sync node that's associated with |child|. |
| 237 sync_api::WriteNode sync_node(&trans); | 237 sync_api::WriteNode sync_node(&trans); |
| 238 if (!model_associator_->InitSyncNodeFromChromeId(child->id(), &sync_node)) { | 238 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); | 377 model->RemoveObserver(this); |
| 378 | 378 |
| 379 // A parent to hold nodes temporarily orphaned by parent deletion. It is | 379 // A parent to hold nodes temporarily orphaned by parent deletion. It is |
| 380 // lazily created inside the loop. | 380 // lazily created inside the loop. |
| 381 const BookmarkNode* foster_parent = NULL; | 381 const BookmarkNode* foster_parent = NULL; |
| 382 for (int i = 0; i < change_count; ++i) { | 382 for (int i = 0; i < change_count; ++i) { |
| 383 const BookmarkNode* dst = | 383 const BookmarkNode* dst = |
| 384 model_associator_->GetChromeNodeFromSyncId(changes[i].id); | 384 model_associator_->GetChromeNodeFromSyncId(changes[i].id); |
| 385 // Ignore changes to the permanent top-level nodes. We only care about | 385 // Ignore changes to the permanent top-level nodes. We only care about |
| 386 // their children. | 386 // their children. |
| 387 if ((dst == model->GetBookmarkBarNode()) || (dst == model->other_node())) | 387 if (model->is_permanent_node(dst)) |
| 388 continue; | 388 continue; |
| 389 if (changes[i].action == | 389 if (changes[i].action == |
| 390 sync_api::SyncManager::ChangeRecord::ACTION_DELETE) { | 390 sync_api::SyncManager::ChangeRecord::ACTION_DELETE) { |
| 391 // Deletions should always be at the front of the list. | 391 // Deletions should always be at the front of the list. |
| 392 DCHECK(i == 0 || changes[i-1].action == changes[i].action); | 392 DCHECK(i == 0 || changes[i-1].action == changes[i].action); |
| 393 // Children of a deleted node should not be deleted; they may be | 393 // 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. | 394 // reparented by a later change record. Move them to a temporary place. |
| 395 DCHECK(dst) << "Could not find node to be deleted"; | |
| 396 if (!dst) // Can't do anything if we can't find the chrome node. | 395 if (!dst) // Can't do anything if we can't find the chrome node. |
| 397 continue; | 396 continue; |
| 398 const BookmarkNode* parent = dst->parent(); | 397 const BookmarkNode* parent = dst->parent(); |
| 399 if (dst->child_count()) { | 398 if (dst->child_count()) { |
| 400 if (!foster_parent) { | 399 if (!foster_parent) { |
| 401 foster_parent = model->AddFolder(model->other_node(), | 400 foster_parent = model->AddFolder(model->other_node(), |
| 402 model->other_node()->child_count(), | 401 model->other_node()->child_count(), |
| 403 string16()); | 402 string16()); |
| 404 } | 403 } |
| 405 for (int i = dst->child_count() - 1; i >= 0; --i) { | 404 for (int i = dst->child_count() - 1; i >= 0; --i) { |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 550 const BookmarkNode* bookmark_node, | 549 const BookmarkNode* bookmark_node, |
| 551 BookmarkModel* model, | 550 BookmarkModel* model, |
| 552 sync_api::WriteNode* sync_node) { | 551 sync_api::WriteNode* sync_node) { |
| 553 std::vector<unsigned char> favicon_bytes; | 552 std::vector<unsigned char> favicon_bytes; |
| 554 EncodeFavicon(bookmark_node, model, &favicon_bytes); | 553 EncodeFavicon(bookmark_node, model, &favicon_bytes); |
| 555 if (!favicon_bytes.empty()) | 554 if (!favicon_bytes.empty()) |
| 556 sync_node->SetFaviconBytes(favicon_bytes); | 555 sync_node->SetFaviconBytes(favicon_bytes); |
| 557 } | 556 } |
| 558 | 557 |
| 559 } // namespace browser_sync | 558 } // namespace browser_sync |
| OLD | NEW |