| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <utility> | 10 #include <utility> |
| 11 | 11 |
| 12 #include "base/location.h" | 12 #include "base/location.h" |
| 13 #include "base/memory/ptr_util.h" |
| 13 #include "base/strings/string_number_conversions.h" | 14 #include "base/strings/string_number_conversions.h" |
| 14 #include "base/strings/utf_string_conversions.h" | 15 #include "base/strings/utf_string_conversions.h" |
| 15 #include "base/threading/thread_task_runner_handle.h" | 16 #include "base/threading/thread_task_runner_handle.h" |
| 16 #include "components/sync/base/unrecoverable_error_handler.h" | 17 #include "components/sync/base/unrecoverable_error_handler.h" |
| 17 #include "components/sync/driver/sync_api_component_factory.h" | 18 #include "components/sync/driver/sync_api_component_factory.h" |
| 18 #include "components/sync/driver/sync_client.h" | 19 #include "components/sync/driver/sync_client.h" |
| 19 #include "components/sync/model/local_change_observer.h" | 20 #include "components/sync/model/local_change_observer.h" |
| 20 #include "components/sync/model/sync_change.h" | 21 #include "components/sync/model/sync_change.h" |
| 21 #include "components/sync/model/sync_error.h" | 22 #include "components/sync/model/sync_error.h" |
| 22 #include "components/sync/model/syncable_service.h" | 23 #include "components/sync/model/syncable_service.h" |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 123 if (attachment_store) { | 124 if (attachment_store) { |
| 124 std::string store_birthday; | 125 std::string store_birthday; |
| 125 { | 126 { |
| 126 ReadTransaction trans(FROM_HERE, share_handle()); | 127 ReadTransaction trans(FROM_HERE, share_handle()); |
| 127 store_birthday = trans.GetStoreBirthday(); | 128 store_birthday = trans.GetStoreBirthday(); |
| 128 } | 129 } |
| 129 attachment_service_ = | 130 attachment_service_ = |
| 130 sync_client->GetSyncApiComponentFactory()->CreateAttachmentService( | 131 sync_client->GetSyncApiComponentFactory()->CreateAttachmentService( |
| 131 std::move(attachment_store), *user_share, store_birthday, type, | 132 std::move(attachment_store), *user_share, store_birthday, type, |
| 132 this); | 133 this); |
| 133 attachment_service_weak_ptr_factory_.reset( | 134 attachment_service_weak_ptr_factory_ = |
| 134 new base::WeakPtrFactory<AttachmentService>(attachment_service_.get())); | 135 base::MakeUnique<base::WeakPtrFactory<AttachmentService>>( |
| 136 attachment_service_.get()); |
| 135 attachment_service_proxy_ = AttachmentServiceProxy( | 137 attachment_service_proxy_ = AttachmentServiceProxy( |
| 136 base::ThreadTaskRunnerHandle::Get(), | 138 base::ThreadTaskRunnerHandle::Get(), |
| 137 attachment_service_weak_ptr_factory_->GetWeakPtr()); | 139 attachment_service_weak_ptr_factory_->GetWeakPtr()); |
| 138 UploadAllAttachmentsNotOnServer(); | 140 UploadAllAttachmentsNotOnServer(); |
| 139 } else { | 141 } else { |
| 140 attachment_service_proxy_ = | 142 attachment_service_proxy_ = |
| 141 AttachmentServiceProxy(base::ThreadTaskRunnerHandle::Get(), | 143 AttachmentServiceProxy(base::ThreadTaskRunnerHandle::Get(), |
| 142 base::WeakPtr<AttachmentService>()); | 144 base::WeakPtr<AttachmentService>()); |
| 143 } | 145 } |
| 144 } | 146 } |
| 145 | 147 |
| 146 GenericChangeProcessor::~GenericChangeProcessor() { | 148 GenericChangeProcessor::~GenericChangeProcessor() { |
| 147 DCHECK(CalledOnValidThread()); | 149 DCHECK(CalledOnValidThread()); |
| 148 } | 150 } |
| 149 | 151 |
| 150 void GenericChangeProcessor::ApplyChangesFromSyncModel( | 152 void GenericChangeProcessor::ApplyChangesFromSyncModel( |
| 151 const BaseTransaction* trans, | 153 const BaseTransaction* trans, |
| 152 int64_t model_version, | 154 int64_t model_version, |
| 153 const ImmutableChangeRecordList& changes) { | 155 const ImmutableChangeRecordList& changes) { |
| 154 DCHECK(CalledOnValidThread()); | 156 DCHECK(CalledOnValidThread()); |
| 155 DCHECK(syncer_changes_.empty()); | 157 DCHECK(syncer_changes_.empty()); |
| 156 for (ChangeRecordList::const_iterator it = changes.Get().begin(); | 158 for (ChangeRecordList::const_iterator it = changes.Get().begin(); |
| 157 it != changes.Get().end(); ++it) { | 159 it != changes.Get().end(); ++it) { |
| 158 if (it->action == ChangeRecord::ACTION_DELETE) { | 160 if (it->action == ChangeRecord::ACTION_DELETE) { |
| 159 std::unique_ptr<sync_pb::EntitySpecifics> specifics; | 161 std::unique_ptr<sync_pb::EntitySpecifics> specifics; |
| 160 if (it->specifics.has_password()) { | 162 if (it->specifics.has_password()) { |
| 161 DCHECK(it->extra.get()); | 163 DCHECK(it->extra.get()); |
| 162 specifics.reset(new sync_pb::EntitySpecifics(it->specifics)); | 164 specifics = base::MakeUnique<sync_pb::EntitySpecifics>(it->specifics); |
| 163 specifics->mutable_password() | 165 specifics->mutable_password() |
| 164 ->mutable_client_only_encrypted_data() | 166 ->mutable_client_only_encrypted_data() |
| 165 ->CopyFrom(it->extra->unencrypted()); | 167 ->CopyFrom(it->extra->unencrypted()); |
| 166 } | 168 } |
| 167 const AttachmentIdList empty_list_of_attachment_ids; | 169 const AttachmentIdList empty_list_of_attachment_ids; |
| 168 syncer_changes_.push_back(SyncChange( | 170 syncer_changes_.push_back(SyncChange( |
| 169 FROM_HERE, SyncChange::ACTION_DELETE, | 171 FROM_HERE, SyncChange::ACTION_DELETE, |
| 170 SyncData::CreateRemoteData( | 172 SyncData::CreateRemoteData( |
| 171 it->id, specifics ? *specifics : it->specifics, base::Time(), | 173 it->id, specifics ? *specifics : it->specifics, base::Time(), |
| 172 empty_list_of_attachment_ids, attachment_service_proxy_))); | 174 empty_list_of_attachment_ids, attachment_service_proxy_))); |
| (...skipping 524 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 697 OnLocalChange(current_entry, change)); | 699 OnLocalChange(current_entry, change)); |
| 698 } | 700 } |
| 699 | 701 |
| 700 std::unique_ptr<AttachmentService> | 702 std::unique_ptr<AttachmentService> |
| 701 GenericChangeProcessor::GetAttachmentService() const { | 703 GenericChangeProcessor::GetAttachmentService() const { |
| 702 return std::unique_ptr<AttachmentService>( | 704 return std::unique_ptr<AttachmentService>( |
| 703 new AttachmentServiceProxy(attachment_service_proxy_)); | 705 new AttachmentServiceProxy(attachment_service_proxy_)); |
| 704 } | 706 } |
| 705 | 707 |
| 706 } // namespace syncer | 708 } // namespace syncer |
| OLD | NEW |