Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(551)

Side by Side Diff: sync/internal_api/attachments/fake_attachment_store.cc

Issue 293143002: Add AttachmentDownloader interface, change signature of AttachmentStore::Read (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixes after feedback from Nick Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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
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
OLDNEW
« no previous file with comments | « sync/api/attachments/attachment_uploader.h ('k') | sync/internal_api/attachments/fake_attachment_store_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698