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 "components/sync_bookmarks/bookmark_change_processor.h" | 5 #include "components/sync_bookmarks/bookmark_change_processor.h" |
6 | 6 |
| 7 #include <stddef.h> |
| 8 |
7 #include <map> | 9 #include <map> |
8 #include <stack> | 10 #include <stack> |
9 #include <vector> | 11 #include <vector> |
10 | 12 |
11 #include "base/location.h" | 13 #include "base/location.h" |
12 #include "base/strings/string16.h" | 14 #include "base/strings/string16.h" |
13 #include "base/strings/string_number_conversions.h" | 15 #include "base/strings/string_number_conversions.h" |
14 #include "base/strings/string_util.h" | 16 #include "base/strings/string_util.h" |
15 #include "base/strings/utf_string_conversions.h" | 17 #include "base/strings/utf_string_conversions.h" |
16 #include "components/bookmarks/browser/bookmark_client.h" | 18 #include "components/bookmarks/browser/bookmark_client.h" |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
116 BookmarkModelAssociator* associator) { | 118 BookmarkModelAssociator* associator) { |
117 // Remove children. | 119 // Remove children. |
118 int num_removed = RemoveAllChildNodes(trans, sync_node->GetId(), associator); | 120 int num_removed = RemoveAllChildNodes(trans, sync_node->GetId(), associator); |
119 // Remove the node itself. | 121 // Remove the node itself. |
120 RemoveOneSyncNode(sync_node, associator); | 122 RemoveOneSyncNode(sync_node, associator); |
121 return num_removed + 1; | 123 return num_removed + 1; |
122 } | 124 } |
123 | 125 |
124 void BookmarkChangeProcessor::RemoveSyncNodeHierarchy( | 126 void BookmarkChangeProcessor::RemoveSyncNodeHierarchy( |
125 const BookmarkNode* topmost) { | 127 const BookmarkNode* topmost) { |
126 int64 new_version = syncer::syncable::kInvalidTransactionVersion; | 128 int64_t new_version = syncer::syncable::kInvalidTransactionVersion; |
127 { | 129 { |
128 syncer::WriteTransaction trans(FROM_HERE, share_handle(), &new_version); | 130 syncer::WriteTransaction trans(FROM_HERE, share_handle(), &new_version); |
129 syncer::WriteNode topmost_sync_node(&trans); | 131 syncer::WriteNode topmost_sync_node(&trans); |
130 if (!model_associator_->InitSyncNodeFromChromeId(topmost->id(), | 132 if (!model_associator_->InitSyncNodeFromChromeId(topmost->id(), |
131 &topmost_sync_node)) { | 133 &topmost_sync_node)) { |
132 syncer::SyncError error(FROM_HERE, | 134 syncer::SyncError error(FROM_HERE, |
133 syncer::SyncError::DATATYPE_ERROR, | 135 syncer::SyncError::DATATYPE_ERROR, |
134 "Failed to init sync node from chrome node", | 136 "Failed to init sync node from chrome node", |
135 syncer::BOOKMARKS); | 137 syncer::BOOKMARKS); |
136 error_handler()->OnSingleDataTypeUnrecoverableError(error); | 138 error_handler()->OnSingleDataTypeUnrecoverableError(error); |
137 return; | 139 return; |
138 } | 140 } |
139 RemoveSyncNodeHierarchy(&trans, &topmost_sync_node, model_associator_); | 141 RemoveSyncNodeHierarchy(&trans, &topmost_sync_node, model_associator_); |
140 } | 142 } |
141 | 143 |
142 // Don't need to update versions of deleted nodes. | 144 // Don't need to update versions of deleted nodes. |
143 UpdateTransactionVersion(new_version, bookmark_model_, | 145 UpdateTransactionVersion(new_version, bookmark_model_, |
144 std::vector<const BookmarkNode*>()); | 146 std::vector<const BookmarkNode*>()); |
145 } | 147 } |
146 | 148 |
147 void BookmarkChangeProcessor::RemoveAllSyncNodes() { | 149 void BookmarkChangeProcessor::RemoveAllSyncNodes() { |
148 int64 new_version = syncer::syncable::kInvalidTransactionVersion; | 150 int64_t new_version = syncer::syncable::kInvalidTransactionVersion; |
149 { | 151 { |
150 syncer::WriteTransaction trans(FROM_HERE, share_handle(), &new_version); | 152 syncer::WriteTransaction trans(FROM_HERE, share_handle(), &new_version); |
151 | 153 |
152 int64 bookmark_bar_node_sync_id = model_associator_->GetSyncIdFromChromeId( | 154 int64_t bookmark_bar_node_sync_id = |
153 bookmark_model_->bookmark_bar_node()->id()); | 155 model_associator_->GetSyncIdFromChromeId( |
| 156 bookmark_model_->bookmark_bar_node()->id()); |
154 DCHECK_NE(syncer::kInvalidId, bookmark_bar_node_sync_id); | 157 DCHECK_NE(syncer::kInvalidId, bookmark_bar_node_sync_id); |
155 RemoveAllChildNodes(&trans, bookmark_bar_node_sync_id, model_associator_); | 158 RemoveAllChildNodes(&trans, bookmark_bar_node_sync_id, model_associator_); |
156 | 159 |
157 int64 other_node_sync_id = model_associator_->GetSyncIdFromChromeId( | 160 int64_t other_node_sync_id = model_associator_->GetSyncIdFromChromeId( |
158 bookmark_model_->other_node()->id()); | 161 bookmark_model_->other_node()->id()); |
159 DCHECK_NE(syncer::kInvalidId, other_node_sync_id); | 162 DCHECK_NE(syncer::kInvalidId, other_node_sync_id); |
160 RemoveAllChildNodes(&trans, other_node_sync_id, model_associator_); | 163 RemoveAllChildNodes(&trans, other_node_sync_id, model_associator_); |
161 | 164 |
162 // Remove mobile bookmarks node only if it is present. | 165 // Remove mobile bookmarks node only if it is present. |
163 int64 mobile_node_sync_id = model_associator_->GetSyncIdFromChromeId( | 166 int64_t mobile_node_sync_id = model_associator_->GetSyncIdFromChromeId( |
164 bookmark_model_->mobile_node()->id()); | 167 bookmark_model_->mobile_node()->id()); |
165 if (mobile_node_sync_id != syncer::kInvalidId) { | 168 if (mobile_node_sync_id != syncer::kInvalidId) { |
166 RemoveAllChildNodes(&trans, mobile_node_sync_id, model_associator_); | 169 RemoveAllChildNodes(&trans, mobile_node_sync_id, model_associator_); |
167 } | 170 } |
168 | 171 |
169 // Note: the root node may have additional extra nodes. Currently none of | 172 // Note: the root node may have additional extra nodes. Currently none of |
170 // them are meant to sync. | 173 // them are meant to sync. |
171 } | 174 } |
172 | 175 |
173 // Don't need to update versions of deleted nodes. | 176 // Don't need to update versions of deleted nodes. |
174 UpdateTransactionVersion(new_version, bookmark_model_, | 177 UpdateTransactionVersion(new_version, bookmark_model_, |
175 std::vector<const BookmarkNode*>()); | 178 std::vector<const BookmarkNode*>()); |
176 } | 179 } |
177 | 180 |
178 // static | 181 // static |
179 int BookmarkChangeProcessor::RemoveAllChildNodes( | 182 int BookmarkChangeProcessor::RemoveAllChildNodes( |
180 syncer::WriteTransaction* trans, | 183 syncer::WriteTransaction* trans, |
181 int64 topmost_sync_id, | 184 int64_t topmost_sync_id, |
182 BookmarkModelAssociator* associator) { | 185 BookmarkModelAssociator* associator) { |
183 // Do a DFS and delete all the child sync nodes, use sync id instead of | 186 // Do a DFS and delete all the child sync nodes, use sync id instead of |
184 // bookmark node ids since the bookmark nodes may already be deleted. | 187 // bookmark node ids since the bookmark nodes may already be deleted. |
185 // The equivalent recursive version of this iterative DFS: | 188 // The equivalent recursive version of this iterative DFS: |
186 // remove_all_children(node_id, topmost_node_id): | 189 // remove_all_children(node_id, topmost_node_id): |
187 // node.initByIdLookup(node_id) | 190 // node.initByIdLookup(node_id) |
188 // while(node.GetFirstChildId() != syncer::kInvalidId) | 191 // while(node.GetFirstChildId() != syncer::kInvalidId) |
189 // remove_all_children(node.GetFirstChildId(), topmost_node_id) | 192 // remove_all_children(node.GetFirstChildId(), topmost_node_id) |
190 // if(node_id != topmost_node_id) | 193 // if(node_id != topmost_node_id) |
191 // delete node | 194 // delete node |
192 | 195 |
193 int num_removed = 0; | 196 int num_removed = 0; |
194 std::stack<int64> dfs_sync_id_stack; | 197 std::stack<int64_t> dfs_sync_id_stack; |
195 // Push the topmost node. | 198 // Push the topmost node. |
196 dfs_sync_id_stack.push(topmost_sync_id); | 199 dfs_sync_id_stack.push(topmost_sync_id); |
197 while (!dfs_sync_id_stack.empty()) { | 200 while (!dfs_sync_id_stack.empty()) { |
198 const int64 sync_node_id = dfs_sync_id_stack.top(); | 201 const int64_t sync_node_id = dfs_sync_id_stack.top(); |
199 syncer::WriteNode node(trans); | 202 syncer::WriteNode node(trans); |
200 node.InitByIdLookup(sync_node_id); | 203 node.InitByIdLookup(sync_node_id); |
201 if (!node.GetIsFolder() || node.GetFirstChildId() == syncer::kInvalidId) { | 204 if (!node.GetIsFolder() || node.GetFirstChildId() == syncer::kInvalidId) { |
202 // All children of the node has been processed, delete the node and | 205 // All children of the node has been processed, delete the node and |
203 // pop it off the stack. | 206 // pop it off the stack. |
204 dfs_sync_id_stack.pop(); | 207 dfs_sync_id_stack.pop(); |
205 // Do not delete the topmost node. | 208 // Do not delete the topmost node. |
206 if (sync_node_id != topmost_sync_id) { | 209 if (sync_node_id != topmost_sync_id) { |
207 RemoveOneSyncNode(&node, associator); | 210 RemoveOneSyncNode(&node, associator); |
208 num_removed++; | 211 num_removed++; |
209 } else { | 212 } else { |
210 // if we are processing topmost node, all other nodes must be processed | 213 // if we are processing topmost node, all other nodes must be processed |
211 // the stack should be empty. | 214 // the stack should be empty. |
212 DCHECK(dfs_sync_id_stack.empty()); | 215 DCHECK(dfs_sync_id_stack.empty()); |
213 } | 216 } |
214 } else { | 217 } else { |
215 int64 child_id = node.GetFirstChildId(); | 218 int64_t child_id = node.GetFirstChildId(); |
216 if (child_id != syncer::kInvalidId) { | 219 if (child_id != syncer::kInvalidId) { |
217 dfs_sync_id_stack.push(child_id); | 220 dfs_sync_id_stack.push(child_id); |
218 } | 221 } |
219 } | 222 } |
220 } | 223 } |
221 return num_removed; | 224 return num_removed; |
222 } | 225 } |
223 | 226 |
224 // static | 227 // static |
225 void BookmarkChangeProcessor::RemoveOneSyncNode( | 228 void BookmarkChangeProcessor::RemoveOneSyncNode( |
226 syncer::WriteNode* sync_node, | 229 syncer::WriteNode* sync_node, |
227 BookmarkModelAssociator* associator) { | 230 BookmarkModelAssociator* associator) { |
228 // This node should have no children. | 231 // This node should have no children. |
229 DCHECK(!sync_node->HasChildren()); | 232 DCHECK(!sync_node->HasChildren()); |
230 // Remove association and delete the sync node. | 233 // Remove association and delete the sync node. |
231 associator->Disassociate(sync_node->GetId()); | 234 associator->Disassociate(sync_node->GetId()); |
232 sync_node->Tombstone(); | 235 sync_node->Tombstone(); |
233 } | 236 } |
234 | 237 |
235 void BookmarkChangeProcessor::CreateOrUpdateSyncNode(const BookmarkNode* node) { | 238 void BookmarkChangeProcessor::CreateOrUpdateSyncNode(const BookmarkNode* node) { |
236 if (!CanSyncNode(node)) { | 239 if (!CanSyncNode(node)) { |
237 NOTREACHED(); | 240 NOTREACHED(); |
238 return; | 241 return; |
239 } | 242 } |
240 | 243 |
241 const BookmarkNode* parent = node->parent(); | 244 const BookmarkNode* parent = node->parent(); |
242 int index = node->parent()->GetIndexOf(node); | 245 int index = node->parent()->GetIndexOf(node); |
243 | 246 |
244 int64 new_version = syncer::syncable::kInvalidTransactionVersion; | 247 int64_t new_version = syncer::syncable::kInvalidTransactionVersion; |
245 int64 sync_id = syncer::kInvalidId; | 248 int64_t sync_id = syncer::kInvalidId; |
246 { | 249 { |
247 // Acquire a scoped write lock via a transaction. | 250 // Acquire a scoped write lock via a transaction. |
248 syncer::WriteTransaction trans(FROM_HERE, share_handle(), &new_version); | 251 syncer::WriteTransaction trans(FROM_HERE, share_handle(), &new_version); |
249 sync_id = model_associator_->GetSyncIdFromChromeId(node->id()); | 252 sync_id = model_associator_->GetSyncIdFromChromeId(node->id()); |
250 if (sync_id != syncer::kInvalidId) { | 253 if (sync_id != syncer::kInvalidId) { |
251 UpdateSyncNode( | 254 UpdateSyncNode( |
252 node, bookmark_model_, &trans, model_associator_, error_handler()); | 255 node, bookmark_model_, &trans, model_associator_, error_handler()); |
253 } else { | 256 } else { |
254 sync_id = CreateSyncNode(parent, | 257 sync_id = CreateSyncNode(parent, |
255 bookmark_model_, | 258 bookmark_model_, |
(...skipping 29 matching lines...) Expand all Loading... |
285 void BookmarkChangeProcessor::BookmarkNodeAdded(BookmarkModel* model, | 288 void BookmarkChangeProcessor::BookmarkNodeAdded(BookmarkModel* model, |
286 const BookmarkNode* parent, | 289 const BookmarkNode* parent, |
287 int index) { | 290 int index) { |
288 DCHECK(share_handle()); | 291 DCHECK(share_handle()); |
289 const BookmarkNode* node = parent->GetChild(index); | 292 const BookmarkNode* node = parent->GetChild(index); |
290 if (CanSyncNode(node)) | 293 if (CanSyncNode(node)) |
291 CreateOrUpdateSyncNode(node); | 294 CreateOrUpdateSyncNode(node); |
292 } | 295 } |
293 | 296 |
294 // static | 297 // static |
295 int64 BookmarkChangeProcessor::CreateSyncNode(const BookmarkNode* parent, | 298 int64_t BookmarkChangeProcessor::CreateSyncNode( |
296 BookmarkModel* model, int index, syncer::WriteTransaction* trans, | 299 const BookmarkNode* parent, |
| 300 BookmarkModel* model, |
| 301 int index, |
| 302 syncer::WriteTransaction* trans, |
297 BookmarkModelAssociator* associator, | 303 BookmarkModelAssociator* associator, |
298 sync_driver::DataTypeErrorHandler* error_handler) { | 304 sync_driver::DataTypeErrorHandler* error_handler) { |
299 const BookmarkNode* child = parent->GetChild(index); | 305 const BookmarkNode* child = parent->GetChild(index); |
300 DCHECK(child); | 306 DCHECK(child); |
301 | 307 |
302 // Create a WriteNode container to hold the new node. | 308 // Create a WriteNode container to hold the new node. |
303 syncer::WriteNode sync_child(trans); | 309 syncer::WriteNode sync_child(trans); |
304 | 310 |
305 // Actually create the node with the appropriate initial position. | 311 // Actually create the node with the appropriate initial position. |
306 if (!PlaceSyncNode(CREATE, parent, index, trans, &sync_child, associator)) { | 312 if (!PlaceSyncNode(CREATE, parent, index, trans, &sync_child, associator)) { |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
350 return; | 356 return; |
351 // We shouldn't see changes to the top-level nodes. | 357 // We shouldn't see changes to the top-level nodes. |
352 if (model->is_permanent_node(node)) { | 358 if (model->is_permanent_node(node)) { |
353 NOTREACHED() << "Saw update to permanent node!"; | 359 NOTREACHED() << "Saw update to permanent node!"; |
354 return; | 360 return; |
355 } | 361 } |
356 CreateOrUpdateSyncNode(node); | 362 CreateOrUpdateSyncNode(node); |
357 } | 363 } |
358 | 364 |
359 // Static. | 365 // Static. |
360 int64 BookmarkChangeProcessor::UpdateSyncNode( | 366 int64_t BookmarkChangeProcessor::UpdateSyncNode( |
361 const BookmarkNode* node, | 367 const BookmarkNode* node, |
362 BookmarkModel* model, | 368 BookmarkModel* model, |
363 syncer::WriteTransaction* trans, | 369 syncer::WriteTransaction* trans, |
364 BookmarkModelAssociator* associator, | 370 BookmarkModelAssociator* associator, |
365 sync_driver::DataTypeErrorHandler* error_handler) { | 371 sync_driver::DataTypeErrorHandler* error_handler) { |
366 // Lookup the sync node that's associated with |node|. | 372 // Lookup the sync node that's associated with |node|. |
367 syncer::WriteNode sync_node(trans); | 373 syncer::WriteNode sync_node(trans); |
368 if (!associator->InitSyncNodeFromChromeId(node->id(), &sync_node)) { | 374 if (!associator->InitSyncNodeFromChromeId(node->id(), &sync_node)) { |
369 syncer::SyncError error(FROM_HERE, | 375 syncer::SyncError error(FROM_HERE, |
370 syncer::SyncError::DATATYPE_ERROR, | 376 syncer::SyncError::DATATYPE_ERROR, |
(...skipping 22 matching lines...) Expand all Loading... |
393 | 399 |
394 if (!CanSyncNode(child)) | 400 if (!CanSyncNode(child)) |
395 return; | 401 return; |
396 | 402 |
397 // We shouldn't see changes to the top-level nodes. | 403 // We shouldn't see changes to the top-level nodes. |
398 if (model->is_permanent_node(child)) { | 404 if (model->is_permanent_node(child)) { |
399 NOTREACHED() << "Saw update to permanent node!"; | 405 NOTREACHED() << "Saw update to permanent node!"; |
400 return; | 406 return; |
401 } | 407 } |
402 | 408 |
403 int64 new_version = syncer::syncable::kInvalidTransactionVersion; | 409 int64_t new_version = syncer::syncable::kInvalidTransactionVersion; |
404 { | 410 { |
405 // Acquire a scoped write lock via a transaction. | 411 // Acquire a scoped write lock via a transaction. |
406 syncer::WriteTransaction trans(FROM_HERE, share_handle(), &new_version); | 412 syncer::WriteTransaction trans(FROM_HERE, share_handle(), &new_version); |
407 | 413 |
408 // Lookup the sync node that's associated with |child|. | 414 // Lookup the sync node that's associated with |child|. |
409 syncer::WriteNode sync_node(&trans); | 415 syncer::WriteNode sync_node(&trans); |
410 if (!model_associator_->InitSyncNodeFromChromeId(child->id(), &sync_node)) { | 416 if (!model_associator_->InitSyncNodeFromChromeId(child->id(), &sync_node)) { |
411 syncer::SyncError error(FROM_HERE, | 417 syncer::SyncError error(FROM_HERE, |
412 syncer::SyncError::DATATYPE_ERROR, | 418 syncer::SyncError::DATATYPE_ERROR, |
413 "Failed to init sync node from chrome node", | 419 "Failed to init sync node from chrome node", |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
451 return; | 457 return; |
452 } | 458 } |
453 | 459 |
454 BookmarkNodeChanged(model, node); | 460 BookmarkNodeChanged(model, node); |
455 } | 461 } |
456 | 462 |
457 void BookmarkChangeProcessor::BookmarkNodeChildrenReordered( | 463 void BookmarkChangeProcessor::BookmarkNodeChildrenReordered( |
458 BookmarkModel* model, const BookmarkNode* node) { | 464 BookmarkModel* model, const BookmarkNode* node) { |
459 if (!CanSyncNode(node)) | 465 if (!CanSyncNode(node)) |
460 return; | 466 return; |
461 int64 new_version = syncer::syncable::kInvalidTransactionVersion; | 467 int64_t new_version = syncer::syncable::kInvalidTransactionVersion; |
462 std::vector<const BookmarkNode*> children; | 468 std::vector<const BookmarkNode*> children; |
463 { | 469 { |
464 // Acquire a scoped write lock via a transaction. | 470 // Acquire a scoped write lock via a transaction. |
465 syncer::WriteTransaction trans(FROM_HERE, share_handle(), &new_version); | 471 syncer::WriteTransaction trans(FROM_HERE, share_handle(), &new_version); |
466 | 472 |
467 // The given node's children got reordered. We need to reorder all the | 473 // The given node's children got reordered. We need to reorder all the |
468 // children of the corresponding sync node. | 474 // children of the corresponding sync node. |
469 for (int i = 0; i < node->child_count(); ++i) { | 475 for (int i = 0; i < node->child_count(); ++i) { |
470 const BookmarkNode* child = node->GetChild(i); | 476 const BookmarkNode* child = node->GetChild(i); |
471 children.push_back(child); | 477 children.push_back(child); |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
538 } | 544 } |
539 } | 545 } |
540 return success; | 546 return success; |
541 } | 547 } |
542 | 548 |
543 // ApplyModelChanges is called by the sync backend after changes have been made | 549 // ApplyModelChanges is called by the sync backend after changes have been made |
544 // to the sync engine's model. Apply these changes to the browser bookmark | 550 // to the sync engine's model. Apply these changes to the browser bookmark |
545 // model. | 551 // model. |
546 void BookmarkChangeProcessor::ApplyChangesFromSyncModel( | 552 void BookmarkChangeProcessor::ApplyChangesFromSyncModel( |
547 const syncer::BaseTransaction* trans, | 553 const syncer::BaseTransaction* trans, |
548 int64 model_version, | 554 int64_t model_version, |
549 const syncer::ImmutableChangeRecordList& changes) { | 555 const syncer::ImmutableChangeRecordList& changes) { |
550 DCHECK(thread_checker_.CalledOnValidThread()); | 556 DCHECK(thread_checker_.CalledOnValidThread()); |
551 // A note about ordering. Sync backend is responsible for ordering the change | 557 // A note about ordering. Sync backend is responsible for ordering the change |
552 // records in the following order: | 558 // records in the following order: |
553 // | 559 // |
554 // 1. Deletions, from leaves up to parents. | 560 // 1. Deletions, from leaves up to parents. |
555 // 2. Existing items with synced parents & predecessors. | 561 // 2. Existing items with synced parents & predecessors. |
556 // 3. New items with synced parents & predecessors. | 562 // 3. New items with synced parents & predecessors. |
557 // 4. Items with parents & predecessors in the list. | 563 // 4. Items with parents & predecessors in the list. |
558 // 5. Repeat #4 until all items are in the list. | 564 // 5. Repeat #4 until all items are in the list. |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
630 const BookmarkNode* parent = dst->parent(); | 636 const BookmarkNode* parent = dst->parent(); |
631 int index = parent->GetIndexOf(dst); | 637 int index = parent->GetIndexOf(dst); |
632 if (index > -1) | 638 if (index > -1) |
633 model->Remove(parent->GetChild(index)); | 639 model->Remove(parent->GetChild(index)); |
634 } | 640 } |
635 | 641 |
636 // A map to keep track of some reordering work we defer until later. | 642 // A map to keep track of some reordering work we defer until later. |
637 std::multimap<int, const BookmarkNode*> to_reposition; | 643 std::multimap<int, const BookmarkNode*> to_reposition; |
638 | 644 |
639 syncer::ReadNode synced_bookmarks(trans); | 645 syncer::ReadNode synced_bookmarks(trans); |
640 int64 synced_bookmarks_id = syncer::kInvalidId; | 646 int64_t synced_bookmarks_id = syncer::kInvalidId; |
641 if (synced_bookmarks.InitByTagLookupForBookmarks(kMobileBookmarksTag) == | 647 if (synced_bookmarks.InitByTagLookupForBookmarks(kMobileBookmarksTag) == |
642 syncer::BaseNode::INIT_OK) { | 648 syncer::BaseNode::INIT_OK) { |
643 synced_bookmarks_id = synced_bookmarks.GetId(); | 649 synced_bookmarks_id = synced_bookmarks.GetId(); |
644 } | 650 } |
645 | 651 |
646 // Continue iterating where the previous loop left off. | 652 // Continue iterating where the previous loop left off. |
647 for ( ; it != changes.Get().end(); ++it) { | 653 for ( ; it != changes.Get().end(); ++it) { |
648 const BookmarkNode* dst = | 654 const BookmarkNode* dst = |
649 model_associator_->GetChromeNodeFromSyncId(it->id); | 655 model_associator_->GetChromeNodeFromSyncId(it->id); |
650 | 656 |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
764 model->SetDateAdded( | 770 model->SetDateAdded( |
765 node, | 771 node, |
766 base::Time::FromInternalValue(specifics.creation_time_us())); | 772 base::Time::FromInternalValue(specifics.creation_time_us())); |
767 } | 773 } |
768 SetBookmarkFavicon(&sync_node, node, model, sync_client); | 774 SetBookmarkFavicon(&sync_node, node, model, sync_client); |
769 model->SetNodeMetaInfoMap(node, *GetBookmarkMetaInfo(&sync_node)); | 775 model->SetNodeMetaInfoMap(node, *GetBookmarkMetaInfo(&sync_node)); |
770 } | 776 } |
771 | 777 |
772 // static | 778 // static |
773 void BookmarkChangeProcessor::UpdateTransactionVersion( | 779 void BookmarkChangeProcessor::UpdateTransactionVersion( |
774 int64 new_version, | 780 int64_t new_version, |
775 BookmarkModel* model, | 781 BookmarkModel* model, |
776 const std::vector<const BookmarkNode*>& nodes) { | 782 const std::vector<const BookmarkNode*>& nodes) { |
777 if (new_version != syncer::syncable::kInvalidTransactionVersion) { | 783 if (new_version != syncer::syncable::kInvalidTransactionVersion) { |
778 model->SetNodeSyncTransactionVersion(model->root_node(), new_version); | 784 model->SetNodeSyncTransactionVersion(model->root_node(), new_version); |
779 for (size_t i = 0; i < nodes.size(); ++i) { | 785 for (size_t i = 0; i < nodes.size(); ++i) { |
780 model->SetNodeSyncTransactionVersion(nodes[i], new_version); | 786 model->SetNodeSyncTransactionVersion(nodes[i], new_version); |
781 } | 787 } |
782 } | 788 } |
783 } | 789 } |
784 | 790 |
(...skipping 25 matching lines...) Expand all Loading... |
810 DCHECK(parent); | 816 DCHECK(parent); |
811 | 817 |
812 const BookmarkNode* node; | 818 const BookmarkNode* node; |
813 if (sync_node->GetIsFolder()) { | 819 if (sync_node->GetIsFolder()) { |
814 node = model->AddFolderWithMetaInfo(parent, index, title, | 820 node = model->AddFolderWithMetaInfo(parent, index, title, |
815 GetBookmarkMetaInfo(sync_node).get()); | 821 GetBookmarkMetaInfo(sync_node).get()); |
816 } else { | 822 } else { |
817 // 'creation_time_us' was added in m24. Assume a time of 0 means now. | 823 // 'creation_time_us' was added in m24. Assume a time of 0 means now. |
818 const sync_pb::BookmarkSpecifics& specifics = | 824 const sync_pb::BookmarkSpecifics& specifics = |
819 sync_node->GetBookmarkSpecifics(); | 825 sync_node->GetBookmarkSpecifics(); |
820 const int64 create_time_internal = specifics.creation_time_us(); | 826 const int64_t create_time_internal = specifics.creation_time_us(); |
821 base::Time create_time = (create_time_internal == 0) ? | 827 base::Time create_time = (create_time_internal == 0) ? |
822 base::Time::Now() : base::Time::FromInternalValue(create_time_internal); | 828 base::Time::Now() : base::Time::FromInternalValue(create_time_internal); |
823 node = model->AddURLWithCreationTimeAndMetaInfo( | 829 node = model->AddURLWithCreationTimeAndMetaInfo( |
824 parent, index, title, url, create_time, | 830 parent, index, title, url, create_time, |
825 GetBookmarkMetaInfo(sync_node).get()); | 831 GetBookmarkMetaInfo(sync_node).get()); |
826 if (node) | 832 if (node) |
827 SetBookmarkFavicon(sync_node, node, model, sync_client); | 833 SetBookmarkFavicon(sync_node, node, model, sync_client); |
828 } | 834 } |
829 | 835 |
830 return node; | 836 return node; |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
960 updated_specifics.set_icon_url(bookmark_node->icon_url().spec()); | 966 updated_specifics.set_icon_url(bookmark_node->icon_url().spec()); |
961 sync_node->SetBookmarkSpecifics(updated_specifics); | 967 sync_node->SetBookmarkSpecifics(updated_specifics); |
962 } | 968 } |
963 } | 969 } |
964 | 970 |
965 bool BookmarkChangeProcessor::CanSyncNode(const BookmarkNode* node) { | 971 bool BookmarkChangeProcessor::CanSyncNode(const BookmarkNode* node) { |
966 return bookmark_model_->client()->CanSyncNode(node); | 972 return bookmark_model_->client()->CanSyncNode(node); |
967 } | 973 } |
968 | 974 |
969 } // namespace browser_sync | 975 } // namespace browser_sync |
OLD | NEW |