| 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 "sync/internal_api/public/attachments/in_memory_attachment_store.h" | 5 #include "sync/internal_api/public/attachments/in_memory_attachment_store.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/callback.h" | 8 #include "base/callback.h" |
| 9 #include "base/location.h" | 9 #include "base/location.h" |
| 10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 59 } | 59 } |
| 60 } | 60 } |
| 61 if (!unavailable_attachments->empty()) { | 61 if (!unavailable_attachments->empty()) { |
| 62 result_code = AttachmentStore::UNSPECIFIED_ERROR; | 62 result_code = AttachmentStore::UNSPECIFIED_ERROR; |
| 63 } | 63 } |
| 64 PostCallback(base::Bind(callback, result_code, base::Passed(&result_map), | 64 PostCallback(base::Bind(callback, result_code, base::Passed(&result_map), |
| 65 base::Passed(&unavailable_attachments))); | 65 base::Passed(&unavailable_attachments))); |
| 66 } | 66 } |
| 67 | 67 |
| 68 void InMemoryAttachmentStore::Write( | 68 void InMemoryAttachmentStore::Write( |
| 69 AttachmentStore::AttachmentReferrer referrer, | 69 AttachmentStore::Component component, |
| 70 const AttachmentList& attachments, | 70 const AttachmentList& attachments, |
| 71 const AttachmentStore::WriteCallback& callback) { | 71 const AttachmentStore::WriteCallback& callback) { |
| 72 DCHECK(CalledOnValidThread()); | 72 DCHECK(CalledOnValidThread()); |
| 73 AttachmentList::const_iterator iter = attachments.begin(); | 73 AttachmentList::const_iterator iter = attachments.begin(); |
| 74 AttachmentList::const_iterator end = attachments.end(); | 74 AttachmentList::const_iterator end = attachments.end(); |
| 75 for (; iter != end; ++iter) { | 75 for (; iter != end; ++iter) { |
| 76 attachments_.insert(std::make_pair(iter->GetId(), *iter)); | 76 attachments_.insert(std::make_pair(iter->GetId(), *iter)); |
| 77 } | 77 } |
| 78 PostCallback(base::Bind(callback, AttachmentStore::SUCCESS)); | 78 PostCallback(base::Bind(callback, AttachmentStore::SUCCESS)); |
| 79 } | 79 } |
| 80 | 80 |
| 81 void InMemoryAttachmentStore::Drop( | 81 void InMemoryAttachmentStore::SetReference(AttachmentStore::Component component, |
| 82 AttachmentStore::AttachmentReferrer referrer, | 82 const AttachmentIdList& ids) { |
| 83 DCHECK(CalledOnValidThread()); |
| 84 DCHECK_EQ(AttachmentStore::SYNC, component); |
| 85 } |
| 86 |
| 87 void InMemoryAttachmentStore::DropReference( |
| 88 AttachmentStore::Component component, |
| 83 const AttachmentIdList& ids, | 89 const AttachmentIdList& ids, |
| 84 const AttachmentStore::DropCallback& callback) { | 90 const AttachmentStore::DropCallback& callback) { |
| 85 DCHECK(CalledOnValidThread()); | 91 DCHECK(CalledOnValidThread()); |
| 86 AttachmentStore::Result result = AttachmentStore::SUCCESS; | 92 AttachmentStore::Result result = AttachmentStore::SUCCESS; |
| 93 if (component == AttachmentStore::SYNC) { |
| 94 // TODO(pavely): There is no reference handling implementation yet. All |
| 95 // calls to AddReferrer are ignored. Calls to Drop coming from sync should |
| 96 // be ignored too. |
| 97 PostCallback(base::Bind(callback, AttachmentStore::SUCCESS)); |
| 98 return; |
| 99 } |
| 87 AttachmentIdList::const_iterator ids_iter = ids.begin(); | 100 AttachmentIdList::const_iterator ids_iter = ids.begin(); |
| 88 AttachmentIdList::const_iterator ids_end = ids.end(); | 101 AttachmentIdList::const_iterator ids_end = ids.end(); |
| 89 for (; ids_iter != ids_end; ++ids_iter) { | 102 for (; ids_iter != ids_end; ++ids_iter) { |
| 90 AttachmentMap::iterator attachments_iter = attachments_.find(*ids_iter); | 103 AttachmentMap::iterator attachments_iter = attachments_.find(*ids_iter); |
| 91 if (attachments_iter != attachments_.end()) { | 104 if (attachments_iter != attachments_.end()) { |
| 92 attachments_.erase(attachments_iter); | 105 attachments_.erase(attachments_iter); |
| 93 } | 106 } |
| 94 } | 107 } |
| 95 PostCallback(base::Bind(callback, result)); | 108 PostCallback(base::Bind(callback, result)); |
| 96 } | 109 } |
| (...skipping 13 matching lines...) Expand all Loading... |
| 110 if (attachments_iter != attachments_.end()) { | 123 if (attachments_iter != attachments_.end()) { |
| 111 AppendMetadata(metadata_list.get(), attachments_iter->second); | 124 AppendMetadata(metadata_list.get(), attachments_iter->second); |
| 112 } else { | 125 } else { |
| 113 result_code = AttachmentStore::UNSPECIFIED_ERROR; | 126 result_code = AttachmentStore::UNSPECIFIED_ERROR; |
| 114 } | 127 } |
| 115 } | 128 } |
| 116 PostCallback(base::Bind(callback, result_code, base::Passed(&metadata_list))); | 129 PostCallback(base::Bind(callback, result_code, base::Passed(&metadata_list))); |
| 117 } | 130 } |
| 118 | 131 |
| 119 void InMemoryAttachmentStore::ReadAllMetadata( | 132 void InMemoryAttachmentStore::ReadAllMetadata( |
| 120 AttachmentStore::AttachmentReferrer referrer, | 133 AttachmentStore::Component component, |
| 121 const AttachmentStore::ReadMetadataCallback& callback) { | 134 const AttachmentStore::ReadMetadataCallback& callback) { |
| 122 DCHECK(CalledOnValidThread()); | 135 DCHECK(CalledOnValidThread()); |
| 123 AttachmentStore::Result result_code = AttachmentStore::SUCCESS; | 136 AttachmentStore::Result result_code = AttachmentStore::SUCCESS; |
| 124 scoped_ptr<AttachmentMetadataList> metadata_list( | 137 scoped_ptr<AttachmentMetadataList> metadata_list( |
| 125 new AttachmentMetadataList()); | 138 new AttachmentMetadataList()); |
| 126 | 139 |
| 127 for (AttachmentMap::const_iterator iter = attachments_.begin(); | 140 for (AttachmentMap::const_iterator iter = attachments_.begin(); |
| 128 iter != attachments_.end(); ++iter) { | 141 iter != attachments_.end(); ++iter) { |
| 129 AppendMetadata(metadata_list.get(), iter->second); | 142 AppendMetadata(metadata_list.get(), iter->second); |
| 130 } | 143 } |
| 131 PostCallback(base::Bind(callback, result_code, base::Passed(&metadata_list))); | 144 PostCallback(base::Bind(callback, result_code, base::Passed(&metadata_list))); |
| 132 } | 145 } |
| 133 | 146 |
| 134 } // namespace syncer | 147 } // namespace syncer |
| OLD | NEW |