OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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_driver/generic_change_processor.h" | 5 #include "components/sync_driver/generic_change_processor.h" |
6 | 6 |
7 #include "base/location.h" | 7 #include "base/location.h" |
8 #include "base/strings/string_number_conversions.h" | 8 #include "base/strings/string_number_conversions.h" |
9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
10 #include "components/sync_driver/sync_api_component_factory.h" | 10 #include "components/sync_driver/sync_api_component_factory.h" |
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
216 trans.UpdateEntriesWithAttachmentId(attachment_id); | 216 trans.UpdateEntriesWithAttachmentId(attachment_id); |
217 } | 217 } |
218 | 218 |
219 syncer::SyncError GenericChangeProcessor::GetAllSyncDataReturnError( | 219 syncer::SyncError GenericChangeProcessor::GetAllSyncDataReturnError( |
220 syncer::ModelType type, | 220 syncer::ModelType type, |
221 syncer::SyncDataList* current_sync_data) const { | 221 syncer::SyncDataList* current_sync_data) const { |
222 DCHECK(CalledOnValidThread()); | 222 DCHECK(CalledOnValidThread()); |
223 std::string type_name = syncer::ModelTypeToString(type); | 223 std::string type_name = syncer::ModelTypeToString(type); |
224 syncer::ReadTransaction trans(FROM_HERE, share_handle()); | 224 syncer::ReadTransaction trans(FROM_HERE, share_handle()); |
225 syncer::ReadNode root(&trans); | 225 syncer::ReadNode root(&trans); |
226 if (root.InitByTagLookup(syncer::ModelTypeToRootTag(type)) != | 226 if (root.InitTypeRoot(type) != syncer::BaseNode::INIT_OK) { |
227 syncer::BaseNode::INIT_OK) { | |
228 syncer::SyncError error(FROM_HERE, | 227 syncer::SyncError error(FROM_HERE, |
229 syncer::SyncError::DATATYPE_ERROR, | 228 syncer::SyncError::DATATYPE_ERROR, |
230 "Server did not create the top-level " + type_name + | 229 "Server did not create the top-level " + type_name + |
231 " node. We might be running against an out-of-" | 230 " node. We might be running against an out-of-" |
232 "date server.", | 231 "date server.", |
233 type); | 232 type); |
234 return error; | 233 return error; |
235 } | 234 } |
236 | 235 |
237 // TODO(akalin): We'll have to do a tree traversal for bookmarks. | 236 // TODO(akalin): We'll have to do a tree traversal for bookmarks. |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
269 DCHECK_EQ(type, | 268 DCHECK_EQ(type, |
270 syncer::GetModelTypeFromSpecificsFieldNumber( | 269 syncer::GetModelTypeFromSpecificsFieldNumber( |
271 context_proto.data_type_id())); | 270 context_proto.data_type_id())); |
272 *context = context_proto.context(); | 271 *context = context_proto.context(); |
273 return true; | 272 return true; |
274 } | 273 } |
275 | 274 |
276 int GenericChangeProcessor::GetSyncCountForType(syncer::ModelType type) { | 275 int GenericChangeProcessor::GetSyncCountForType(syncer::ModelType type) { |
277 syncer::ReadTransaction trans(FROM_HERE, share_handle()); | 276 syncer::ReadTransaction trans(FROM_HERE, share_handle()); |
278 syncer::ReadNode root(&trans); | 277 syncer::ReadNode root(&trans); |
279 if (root.InitByTagLookup(syncer::ModelTypeToRootTag(type)) != | 278 if (root.InitTypeRoot(type) != syncer::BaseNode::INIT_OK) |
280 syncer::BaseNode::INIT_OK) | |
281 return 0; | 279 return 0; |
282 | 280 |
283 // Subtract one to account for type's root node. | 281 // Subtract one to account for type's root node. |
284 return root.GetTotalNodeCount() - 1; | 282 return root.GetTotalNodeCount() - 1; |
285 } | 283 } |
286 | 284 |
287 namespace { | 285 namespace { |
288 | 286 |
289 // TODO(isherman): Investigating http://crbug.com/121592 | 287 // TODO(isherman): Investigating http://crbug.com/121592 |
290 // WARNING: this code is sensitive to compiler optimizations. Be careful | 288 // WARNING: this code is sensitive to compiler optimizations. Be careful |
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
488 const syncer::SyncChange& change, | 486 const syncer::SyncChange& change, |
489 const std::string& type_str, | 487 const std::string& type_str, |
490 const syncer::ModelType& type, | 488 const syncer::ModelType& type, |
491 const syncer::WriteTransaction& trans, | 489 const syncer::WriteTransaction& trans, |
492 syncer::WriteNode* sync_node, | 490 syncer::WriteNode* sync_node, |
493 syncer::AttachmentList* new_attachments) { | 491 syncer::AttachmentList* new_attachments) { |
494 // TODO(sync): Handle other types of creation (custom parents, folders, | 492 // TODO(sync): Handle other types of creation (custom parents, folders, |
495 // etc.). | 493 // etc.). |
496 syncer::ReadNode root_node(&trans); | 494 syncer::ReadNode root_node(&trans); |
497 const syncer::SyncDataLocal sync_data_local(change.sync_data()); | 495 const syncer::SyncDataLocal sync_data_local(change.sync_data()); |
498 if (root_node.InitByTagLookup(syncer::ModelTypeToRootTag( | 496 if (root_node.InitTypeRoot(sync_data_local.GetDataType()) != |
499 sync_data_local.GetDataType())) != syncer::BaseNode::INIT_OK) { | 497 syncer::BaseNode::INIT_OK) { |
500 syncer::SyncError error(FROM_HERE, | 498 syncer::SyncError error(FROM_HERE, |
501 syncer::SyncError::DATATYPE_ERROR, | 499 syncer::SyncError::DATATYPE_ERROR, |
502 "Failed to look up root node for type " + type_str, | 500 "Failed to look up root node for type " + type_str, |
503 type); | 501 type); |
504 error_handler()->OnSingleDatatypeUnrecoverableError(FROM_HERE, | 502 error_handler()->OnSingleDatatypeUnrecoverableError(FROM_HERE, |
505 error.message()); | 503 error.message()); |
506 NOTREACHED(); | 504 NOTREACHED(); |
507 LOG(ERROR) << "Create: no root node."; | 505 LOG(ERROR) << "Create: no root node."; |
508 return error; | 506 return error; |
509 } | 507 } |
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
697 bool* has_nodes) { | 695 bool* has_nodes) { |
698 DCHECK(CalledOnValidThread()); | 696 DCHECK(CalledOnValidThread()); |
699 DCHECK(has_nodes); | 697 DCHECK(has_nodes); |
700 DCHECK_NE(type, syncer::UNSPECIFIED); | 698 DCHECK_NE(type, syncer::UNSPECIFIED); |
701 std::string type_name = syncer::ModelTypeToString(type); | 699 std::string type_name = syncer::ModelTypeToString(type); |
702 std::string err_str = "Server did not create the top-level " + type_name + | 700 std::string err_str = "Server did not create the top-level " + type_name + |
703 " node. We might be running against an out-of-date server."; | 701 " node. We might be running against an out-of-date server."; |
704 *has_nodes = false; | 702 *has_nodes = false; |
705 syncer::ReadTransaction trans(FROM_HERE, share_handle()); | 703 syncer::ReadTransaction trans(FROM_HERE, share_handle()); |
706 syncer::ReadNode type_root_node(&trans); | 704 syncer::ReadNode type_root_node(&trans); |
707 if (type_root_node.InitByTagLookup(syncer::ModelTypeToRootTag(type)) != | 705 if (type_root_node.InitTypeRoot(type) != syncer::BaseNode::INIT_OK) { |
708 syncer::BaseNode::INIT_OK) { | |
709 LOG(ERROR) << err_str; | 706 LOG(ERROR) << err_str; |
710 return false; | 707 return false; |
711 } | 708 } |
712 | 709 |
713 // The sync model has user created nodes if the type's root node has any | 710 // The sync model has user created nodes if the type's root node has any |
714 // children. | 711 // children. |
715 *has_nodes = type_root_node.HasChildren(); | 712 *has_nodes = type_root_node.HasChildren(); |
716 return true; | 713 return true; |
717 } | 714 } |
718 | 715 |
719 bool GenericChangeProcessor::CryptoReadyIfNecessary(syncer::ModelType type) { | 716 bool GenericChangeProcessor::CryptoReadyIfNecessary(syncer::ModelType type) { |
720 DCHECK(CalledOnValidThread()); | 717 DCHECK(CalledOnValidThread()); |
721 DCHECK_NE(type, syncer::UNSPECIFIED); | 718 DCHECK_NE(type, syncer::UNSPECIFIED); |
722 // We only access the cryptographer while holding a transaction. | 719 // We only access the cryptographer while holding a transaction. |
723 syncer::ReadTransaction trans(FROM_HERE, share_handle()); | 720 syncer::ReadTransaction trans(FROM_HERE, share_handle()); |
724 const syncer::ModelTypeSet encrypted_types = trans.GetEncryptedTypes(); | 721 const syncer::ModelTypeSet encrypted_types = trans.GetEncryptedTypes(); |
725 return !encrypted_types.Has(type) || | 722 return !encrypted_types.Has(type) || |
726 trans.GetCryptographer()->is_ready(); | 723 trans.GetCryptographer()->is_ready(); |
727 } | 724 } |
728 | 725 |
729 void GenericChangeProcessor::StartImpl() { | 726 void GenericChangeProcessor::StartImpl() { |
730 } | 727 } |
731 | 728 |
732 syncer::UserShare* GenericChangeProcessor::share_handle() const { | 729 syncer::UserShare* GenericChangeProcessor::share_handle() const { |
733 DCHECK(CalledOnValidThread()); | 730 DCHECK(CalledOnValidThread()); |
734 return share_handle_; | 731 return share_handle_; |
735 } | 732 } |
736 | 733 |
737 } // namespace browser_sync | 734 } // namespace browser_sync |
OLD | NEW |