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 <memory> |
| 8 |
7 #include "base/bind.h" | 9 #include "base/bind.h" |
8 #include "base/callback.h" | 10 #include "base/callback.h" |
9 #include "base/location.h" | 11 #include "base/location.h" |
10 #include "base/memory/scoped_ptr.h" | |
11 #include "base/sequenced_task_runner.h" | 12 #include "base/sequenced_task_runner.h" |
12 | 13 |
13 namespace syncer { | 14 namespace syncer { |
14 | 15 |
15 namespace { | 16 namespace { |
16 | 17 |
17 void AppendMetadata(AttachmentMetadataList* list, | 18 void AppendMetadata(AttachmentMetadataList* list, |
18 const Attachment& attachment) { | 19 const Attachment& attachment) { |
19 list->push_back( | 20 list->push_back( |
20 AttachmentMetadata(attachment.GetId(), attachment.GetData()->size())); | 21 AttachmentMetadata(attachment.GetId(), attachment.GetData()->size())); |
(...skipping 16 matching lines...) Expand all Loading... |
37 DCHECK(CalledOnValidThread()); | 38 DCHECK(CalledOnValidThread()); |
38 PostCallback(base::Bind(callback, AttachmentStore::SUCCESS)); | 39 PostCallback(base::Bind(callback, AttachmentStore::SUCCESS)); |
39 } | 40 } |
40 | 41 |
41 void InMemoryAttachmentStore::Read( | 42 void InMemoryAttachmentStore::Read( |
42 AttachmentStore::Component component, | 43 AttachmentStore::Component component, |
43 const AttachmentIdList& ids, | 44 const AttachmentIdList& ids, |
44 const AttachmentStore::ReadCallback& callback) { | 45 const AttachmentStore::ReadCallback& callback) { |
45 DCHECK(CalledOnValidThread()); | 46 DCHECK(CalledOnValidThread()); |
46 AttachmentStore::Result result_code = AttachmentStore::SUCCESS; | 47 AttachmentStore::Result result_code = AttachmentStore::SUCCESS; |
47 scoped_ptr<AttachmentMap> result_map(new AttachmentMap); | 48 std::unique_ptr<AttachmentMap> result_map(new AttachmentMap); |
48 scoped_ptr<AttachmentIdList> unavailable_attachments(new AttachmentIdList); | 49 std::unique_ptr<AttachmentIdList> unavailable_attachments( |
| 50 new AttachmentIdList); |
49 | 51 |
50 for (const auto& id : ids) { | 52 for (const auto& id : ids) { |
51 AttachmentEntryMap::iterator iter = attachments_.find(id); | 53 AttachmentEntryMap::iterator iter = attachments_.find(id); |
52 if (iter != attachments_.end() && | 54 if (iter != attachments_.end() && |
53 iter->second.components.count(component) > 0) { | 55 iter->second.components.count(component) > 0) { |
54 const Attachment& attachment = iter->second.attachment; | 56 const Attachment& attachment = iter->second.attachment; |
55 result_map->insert(std::make_pair(id, attachment)); | 57 result_map->insert(std::make_pair(id, attachment)); |
56 } else { | 58 } else { |
57 unavailable_attachments->push_back(id); | 59 unavailable_attachments->push_back(id); |
58 } | 60 } |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
105 } | 107 } |
106 PostCallback(base::Bind(callback, result)); | 108 PostCallback(base::Bind(callback, result)); |
107 } | 109 } |
108 | 110 |
109 void InMemoryAttachmentStore::ReadMetadataById( | 111 void InMemoryAttachmentStore::ReadMetadataById( |
110 AttachmentStore::Component component, | 112 AttachmentStore::Component component, |
111 const AttachmentIdList& ids, | 113 const AttachmentIdList& ids, |
112 const AttachmentStore::ReadMetadataCallback& callback) { | 114 const AttachmentStore::ReadMetadataCallback& callback) { |
113 DCHECK(CalledOnValidThread()); | 115 DCHECK(CalledOnValidThread()); |
114 AttachmentStore::Result result_code = AttachmentStore::SUCCESS; | 116 AttachmentStore::Result result_code = AttachmentStore::SUCCESS; |
115 scoped_ptr<AttachmentMetadataList> metadata_list( | 117 std::unique_ptr<AttachmentMetadataList> metadata_list( |
116 new AttachmentMetadataList()); | 118 new AttachmentMetadataList()); |
117 | 119 |
118 for (const auto& id : ids) { | 120 for (const auto& id : ids) { |
119 AttachmentEntryMap::iterator iter = attachments_.find(id); | 121 AttachmentEntryMap::iterator iter = attachments_.find(id); |
120 if (iter == attachments_.end()) { | 122 if (iter == attachments_.end()) { |
121 result_code = AttachmentStore::UNSPECIFIED_ERROR; | 123 result_code = AttachmentStore::UNSPECIFIED_ERROR; |
122 continue; | 124 continue; |
123 } | 125 } |
124 DCHECK_GT(iter->second.components.size(), 0u); | 126 DCHECK_GT(iter->second.components.size(), 0u); |
125 if (iter->second.components.count(component) == 0) { | 127 if (iter->second.components.count(component) == 0) { |
126 result_code = AttachmentStore::UNSPECIFIED_ERROR; | 128 result_code = AttachmentStore::UNSPECIFIED_ERROR; |
127 continue; | 129 continue; |
128 } | 130 } |
129 AppendMetadata(metadata_list.get(), iter->second.attachment); | 131 AppendMetadata(metadata_list.get(), iter->second.attachment); |
130 } | 132 } |
131 PostCallback(base::Bind(callback, result_code, base::Passed(&metadata_list))); | 133 PostCallback(base::Bind(callback, result_code, base::Passed(&metadata_list))); |
132 } | 134 } |
133 | 135 |
134 void InMemoryAttachmentStore::ReadMetadata( | 136 void InMemoryAttachmentStore::ReadMetadata( |
135 AttachmentStore::Component component, | 137 AttachmentStore::Component component, |
136 const AttachmentStore::ReadMetadataCallback& callback) { | 138 const AttachmentStore::ReadMetadataCallback& callback) { |
137 DCHECK(CalledOnValidThread()); | 139 DCHECK(CalledOnValidThread()); |
138 AttachmentStore::Result result_code = AttachmentStore::SUCCESS; | 140 AttachmentStore::Result result_code = AttachmentStore::SUCCESS; |
139 scoped_ptr<AttachmentMetadataList> metadata_list( | 141 std::unique_ptr<AttachmentMetadataList> metadata_list( |
140 new AttachmentMetadataList()); | 142 new AttachmentMetadataList()); |
141 | 143 |
142 for (AttachmentEntryMap::const_iterator iter = attachments_.begin(); | 144 for (AttachmentEntryMap::const_iterator iter = attachments_.begin(); |
143 iter != attachments_.end(); ++iter) { | 145 iter != attachments_.end(); ++iter) { |
144 DCHECK_GT(iter->second.components.size(), 0u); | 146 DCHECK_GT(iter->second.components.size(), 0u); |
145 if (iter->second.components.count(component) > 0) { | 147 if (iter->second.components.count(component) > 0) { |
146 AppendMetadata(metadata_list.get(), iter->second.attachment); | 148 AppendMetadata(metadata_list.get(), iter->second.attachment); |
147 } | 149 } |
148 } | 150 } |
149 PostCallback(base::Bind(callback, result_code, base::Passed(&metadata_list))); | 151 PostCallback(base::Bind(callback, result_code, base::Passed(&metadata_list))); |
150 } | 152 } |
151 | 153 |
152 InMemoryAttachmentStore::AttachmentEntry::AttachmentEntry( | 154 InMemoryAttachmentStore::AttachmentEntry::AttachmentEntry( |
153 const Attachment& attachment, | 155 const Attachment& attachment, |
154 AttachmentStore::Component initial_reference_component) | 156 AttachmentStore::Component initial_reference_component) |
155 : attachment(attachment) { | 157 : attachment(attachment) { |
156 components.insert(initial_reference_component); | 158 components.insert(initial_reference_component); |
157 } | 159 } |
158 | 160 |
159 InMemoryAttachmentStore::AttachmentEntry::AttachmentEntry( | 161 InMemoryAttachmentStore::AttachmentEntry::AttachmentEntry( |
160 const AttachmentEntry& other) = default; | 162 const AttachmentEntry& other) = default; |
161 | 163 |
162 InMemoryAttachmentStore::AttachmentEntry::~AttachmentEntry() { | 164 InMemoryAttachmentStore::AttachmentEntry::~AttachmentEntry() { |
163 } | 165 } |
164 | 166 |
165 } // namespace syncer | 167 } // namespace syncer |
OLD | NEW |