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/fake_attachment_store.h" | 5 #include "sync/internal_api/public/attachments/fake_attachment_store.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/location.h" | 8 #include "base/location.h" |
9 #include "base/memory/ref_counted_memory.h" | 9 #include "base/memory/ref_counted_memory.h" |
10 #include "base/message_loop/message_loop_proxy.h" | 10 #include "base/message_loop/message_loop_proxy.h" |
(...skipping 29 matching lines...) Expand all Loading... |
40 : frontend_task_runner_(frontend_task_runner) {} | 40 : frontend_task_runner_(frontend_task_runner) {} |
41 | 41 |
42 FakeAttachmentStore::Backend::~Backend() {} | 42 FakeAttachmentStore::Backend::~Backend() {} |
43 | 43 |
44 void FakeAttachmentStore::Backend::Read(const AttachmentIdList& ids, | 44 void FakeAttachmentStore::Backend::Read(const AttachmentIdList& ids, |
45 const ReadCallback& callback) { | 45 const ReadCallback& callback) { |
46 Result result_code = SUCCESS; | 46 Result result_code = SUCCESS; |
47 AttachmentIdList::const_iterator id_iter = ids.begin(); | 47 AttachmentIdList::const_iterator id_iter = ids.begin(); |
48 AttachmentIdList::const_iterator id_end = ids.end(); | 48 AttachmentIdList::const_iterator id_end = ids.end(); |
49 scoped_ptr<AttachmentMap> result_map(new AttachmentMap); | 49 scoped_ptr<AttachmentMap> result_map(new AttachmentMap); |
| 50 scoped_ptr<AttachmentIdList> unavailable_attachments(new AttachmentIdList); |
50 for (; id_iter != id_end; ++id_iter) { | 51 for (; id_iter != id_end; ++id_iter) { |
51 const AttachmentId& id = *id_iter; | 52 const AttachmentId& id = *id_iter; |
52 syncer::AttachmentMap::iterator attachment_iter = | 53 syncer::AttachmentMap::iterator attachment_iter = |
53 attachments_.find(*id_iter); | 54 attachments_.find(*id_iter); |
54 if (attachment_iter != attachments_.end()) { | 55 if (attachment_iter != attachments_.end()) { |
55 const Attachment& attachment = attachment_iter->second; | 56 const Attachment& attachment = attachment_iter->second; |
56 result_map->insert(std::make_pair(id, attachment)); | 57 result_map->insert(std::make_pair(id, attachment)); |
57 } else { | 58 } else { |
58 result_code = UNSPECIFIED_ERROR; | 59 unavailable_attachments->push_back(id); |
59 break; | |
60 } | 60 } |
61 } | 61 } |
| 62 if (!unavailable_attachments->empty()) { |
| 63 result_code = UNSPECIFIED_ERROR; |
| 64 } |
62 frontend_task_runner_->PostTask( | 65 frontend_task_runner_->PostTask( |
63 FROM_HERE, base::Bind(callback, result_code, base::Passed(&result_map))); | 66 FROM_HERE, |
| 67 base::Bind(callback, |
| 68 result_code, |
| 69 base::Passed(&result_map), |
| 70 base::Passed(&unavailable_attachments))); |
64 } | 71 } |
65 | 72 |
66 void FakeAttachmentStore::Backend::Write(const AttachmentList& attachments, | 73 void FakeAttachmentStore::Backend::Write(const AttachmentList& attachments, |
67 const WriteCallback& callback) { | 74 const WriteCallback& callback) { |
68 AttachmentList::const_iterator iter = attachments.begin(); | 75 AttachmentList::const_iterator iter = attachments.begin(); |
69 AttachmentList::const_iterator end = attachments.end(); | 76 AttachmentList::const_iterator end = attachments.end(); |
70 for (; iter != end; ++iter) { | 77 for (; iter != end; ++iter) { |
71 attachments_.insert(std::make_pair(iter->GetId(), *iter)); | 78 attachments_.insert(std::make_pair(iter->GetId(), *iter)); |
72 } | 79 } |
73 frontend_task_runner_->PostTask(FROM_HERE, base::Bind(callback, SUCCESS)); | 80 frontend_task_runner_->PostTask(FROM_HERE, base::Bind(callback, SUCCESS)); |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
112 } | 119 } |
113 | 120 |
114 void FakeAttachmentStore::Drop(const AttachmentIdList& ids, | 121 void FakeAttachmentStore::Drop(const AttachmentIdList& ids, |
115 const DropCallback& callback) { | 122 const DropCallback& callback) { |
116 backend_task_runner_->PostTask( | 123 backend_task_runner_->PostTask( |
117 FROM_HERE, | 124 FROM_HERE, |
118 base::Bind(&FakeAttachmentStore::Backend::Drop, backend_, ids, callback)); | 125 base::Bind(&FakeAttachmentStore::Backend::Drop, backend_, ids, callback)); |
119 } | 126 } |
120 | 127 |
121 } // namespace syncer | 128 } // namespace syncer |
OLD | NEW |