| 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 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 78 sync_pb::EntitySpecifics password_holder; | 78 sync_pb::EntitySpecifics password_holder; |
| 79 password_holder.mutable_password()->mutable_client_only_encrypted_data()-> | 79 password_holder.mutable_password()->mutable_client_only_encrypted_data()-> |
| 80 CopyFrom(read_node.GetPasswordSpecifics()); | 80 CopyFrom(read_node.GetPasswordSpecifics()); |
| 81 return syncer::SyncData::CreateRemoteData(sync_id, | 81 return syncer::SyncData::CreateRemoteData(sync_id, |
| 82 password_holder, | 82 password_holder, |
| 83 read_node.GetModificationTime(), | 83 read_node.GetModificationTime(), |
| 84 attachment_ids, | 84 attachment_ids, |
| 85 attachment_service_proxy); | 85 attachment_service_proxy); |
| 86 } | 86 } |
| 87 | 87 |
| 88 const syncer::AttachmentId& AttachmentToAttachmentId( |
| 89 const syncer::Attachment& attachment) { |
| 90 return attachment.GetId(); |
| 91 } |
| 92 |
| 88 } // namespace | 93 } // namespace |
| 89 | 94 |
| 90 GenericChangeProcessor::GenericChangeProcessor( | 95 GenericChangeProcessor::GenericChangeProcessor( |
| 91 DataTypeErrorHandler* error_handler, | 96 DataTypeErrorHandler* error_handler, |
| 92 const base::WeakPtr<syncer::SyncableService>& local_service, | 97 const base::WeakPtr<syncer::SyncableService>& local_service, |
| 93 const base::WeakPtr<syncer::SyncMergeResult>& merge_result, | 98 const base::WeakPtr<syncer::SyncMergeResult>& merge_result, |
| 94 syncer::UserShare* user_share, | 99 syncer::UserShare* user_share, |
| 95 SyncApiComponentFactory* sync_factory) | 100 SyncApiComponentFactory* sync_factory) |
| 96 : ChangeProcessor(error_handler), | 101 : ChangeProcessor(error_handler), |
| 97 local_service_(local_service), | 102 local_service_(local_service), |
| 98 merge_result_(merge_result), | 103 merge_result_(merge_result), |
| 99 share_handle_(user_share), | 104 share_handle_(user_share), |
| 100 attachment_service_( | 105 attachment_service_( |
| 101 sync_factory->CreateAttachmentService(*user_share, this)), | 106 sync_factory->CreateAttachmentService(*user_share, this)), |
| 102 attachment_service_weak_ptr_factory_(attachment_service_.get()), | 107 attachment_service_weak_ptr_factory_(attachment_service_.get()), |
| 103 attachment_service_proxy_( | 108 attachment_service_proxy_( |
| 104 base::MessageLoopProxy::current(), | 109 base::MessageLoopProxy::current(), |
| 105 attachment_service_weak_ptr_factory_.GetWeakPtr()) { | 110 attachment_service_weak_ptr_factory_.GetWeakPtr()), |
| 111 weak_ptr_factory_(this) { |
| 106 DCHECK(CalledOnValidThread()); | 112 DCHECK(CalledOnValidThread()); |
| 107 DCHECK(attachment_service_); | 113 DCHECK(attachment_service_); |
| 108 } | 114 } |
| 109 | 115 |
| 110 GenericChangeProcessor::~GenericChangeProcessor() { | 116 GenericChangeProcessor::~GenericChangeProcessor() { |
| 111 DCHECK(CalledOnValidThread()); | 117 DCHECK(CalledOnValidThread()); |
| 112 } | 118 } |
| 113 | 119 |
| 114 void GenericChangeProcessor::ApplyChangesFromSyncModel( | 120 void GenericChangeProcessor::ApplyChangesFromSyncModel( |
| 115 const syncer::BaseTransaction* trans, | 121 const syncer::BaseTransaction* trans, |
| (...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 380 type, error_handler); | 386 type, error_handler); |
| 381 } | 387 } |
| 382 } | 388 } |
| 383 if (IsActOnceDataType(type)) | 389 if (IsActOnceDataType(type)) |
| 384 node->Drop(); | 390 node->Drop(); |
| 385 else | 391 else |
| 386 node->Tombstone(); | 392 node->Tombstone(); |
| 387 return syncer::SyncError(); | 393 return syncer::SyncError(); |
| 388 } | 394 } |
| 389 | 395 |
| 390 // A callback invoked on completion of AttachmentService::StoreAttachment. | |
| 391 void IgnoreStoreResult(const syncer::AttachmentService::StoreResult&) { | |
| 392 // TODO(maniscalco): Here is where we're going to update the in-directory | |
| 393 // entry to indicate that the attachments have been successfully stored on | |
| 394 // disk. Why do we care? Because we might crash after persisting the | |
| 395 // directory to disk, but before we have persisted its attachments, leaving us | |
| 396 // with danging attachment ids. Having a flag that indicates we've stored the | |
| 397 // entry will allow us to detect and filter entries with dangling attachment | |
| 398 // ids (bug 368353). | |
| 399 } | |
| 400 | |
| 401 void StoreAttachments(syncer::AttachmentService* attachment_service, | |
| 402 const syncer::AttachmentList& attachments) { | |
| 403 DCHECK(attachment_service); | |
| 404 syncer::AttachmentService::StoreCallback ignore_store_result = | |
| 405 base::Bind(&IgnoreStoreResult); | |
| 406 attachment_service->StoreAttachments(attachments, ignore_store_result); | |
| 407 } | |
| 408 | |
| 409 } // namespace | 396 } // namespace |
| 410 | 397 |
| 411 syncer::SyncError GenericChangeProcessor::ProcessSyncChanges( | 398 syncer::SyncError GenericChangeProcessor::ProcessSyncChanges( |
| 412 const tracked_objects::Location& from_here, | 399 const tracked_objects::Location& from_here, |
| 413 const syncer::SyncChangeList& list_of_changes) { | 400 const syncer::SyncChangeList& list_of_changes) { |
| 414 DCHECK(CalledOnValidThread()); | 401 DCHECK(CalledOnValidThread()); |
| 415 | 402 |
| 416 // Keep track of brand new attachments so we can persist them on this device | 403 // Keep track of brand new attachments so we can persist them on this device |
| 417 // and upload them to the server. | 404 // and upload them to the server. |
| 418 syncer::AttachmentList new_attachments; | 405 syncer::AttachmentList new_attachments; |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 458 change.location().ToString(), | 445 change.location().ToString(), |
| 459 type); | 446 type); |
| 460 error_handler()->OnSingleDataTypeUnrecoverableError(error); | 447 error_handler()->OnSingleDataTypeUnrecoverableError(error); |
| 461 NOTREACHED(); | 448 NOTREACHED(); |
| 462 LOG(ERROR) << "Unset sync change."; | 449 LOG(ERROR) << "Unset sync change."; |
| 463 return error; | 450 return error; |
| 464 } | 451 } |
| 465 } | 452 } |
| 466 | 453 |
| 467 if (!new_attachments.empty()) { | 454 if (!new_attachments.empty()) { |
| 468 StoreAttachments(attachment_service_.get(), new_attachments); | 455 StoreAndUploadAttachments(new_attachments); |
| 469 } | 456 } |
| 470 | 457 |
| 471 return syncer::SyncError(); | 458 return syncer::SyncError(); |
| 472 } | 459 } |
| 473 | 460 |
| 474 // WARNING: this code is sensitive to compiler optimizations. Be careful | 461 // WARNING: this code is sensitive to compiler optimizations. Be careful |
| 475 // modifying any code around an OnSingleDataTypeUnrecoverableError call, else | 462 // modifying any code around an OnSingleDataTypeUnrecoverableError call, else |
| 476 // the compiler attempts to merge it with other calls, losing useful information | 463 // the compiler attempts to merge it with other calls, losing useful information |
| 477 // in breakpad uploads. | 464 // in breakpad uploads. |
| 478 syncer::SyncError GenericChangeProcessor::HandleActionAdd( | 465 syncer::SyncError GenericChangeProcessor::HandleActionAdd( |
| (...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 704 } | 691 } |
| 705 | 692 |
| 706 void GenericChangeProcessor::StartImpl() { | 693 void GenericChangeProcessor::StartImpl() { |
| 707 } | 694 } |
| 708 | 695 |
| 709 syncer::UserShare* GenericChangeProcessor::share_handle() const { | 696 syncer::UserShare* GenericChangeProcessor::share_handle() const { |
| 710 DCHECK(CalledOnValidThread()); | 697 DCHECK(CalledOnValidThread()); |
| 711 return share_handle_; | 698 return share_handle_; |
| 712 } | 699 } |
| 713 | 700 |
| 701 void GenericChangeProcessor::StoreAndUploadAttachments( |
| 702 const syncer::AttachmentList& attachments) { |
| 703 DCHECK(CalledOnValidThread()); |
| 704 attachment_service_->GetStore()->Write( |
| 705 attachments, |
| 706 base::Bind(&GenericChangeProcessor::WriteAttachmentsDone, |
| 707 weak_ptr_factory_.GetWeakPtr(), |
| 708 attachments)); |
| 709 } |
| 710 |
| 711 void GenericChangeProcessor::WriteAttachmentsDone( |
| 712 const syncer::AttachmentList& attachments, |
| 713 const syncer::AttachmentStore::Result& result) { |
| 714 DCHECK(CalledOnValidThread()); |
| 715 if (result != syncer::AttachmentStore::SUCCESS) { |
| 716 // TODO(maniscalco): Deal with case where an error occurred (bug 361251). |
| 717 return; |
| 718 } |
| 719 |
| 720 // TODO(maniscalco): Here is where we're going to update the in-directory |
| 721 // entry to indicate that the attachments have been successfully stored on |
| 722 // disk. Why do we care? Because we might crash after persisting the |
| 723 // directory to disk, but before we have persisted its attachments, leaving us |
| 724 // with danging attachment ids. Having a flag that indicates we've stored the |
| 725 // entry will allow us to detect and filter entries with dangling attachment |
| 726 // ids (bug 368353). |
| 727 |
| 728 // Begin uploading the attachments now that they are safe on disk. |
| 729 syncer::AttachmentIdSet attachment_ids; |
| 730 std::transform(attachments.begin(), |
| 731 attachments.end(), |
| 732 std::inserter(attachment_ids, attachment_ids.end()), |
| 733 AttachmentToAttachmentId); |
| 734 attachment_service_->UploadAttachments(attachment_ids); |
| 735 } |
| 736 |
| 714 } // namespace sync_driver | 737 } // namespace sync_driver |
| OLD | NEW |