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" | |
11 #include "base/sequenced_task_runner.h" | 10 #include "base/sequenced_task_runner.h" |
12 #include "base/single_thread_task_runner.h" | 11 #include "base/single_thread_task_runner.h" |
| 12 #include "base/thread_task_runner_handle.h" |
13 #include "sync/api/attachments/attachment.h" | 13 #include "sync/api/attachments/attachment.h" |
14 | 14 |
15 namespace syncer { | 15 namespace syncer { |
16 | 16 |
17 // Backend is where all the work happens. | 17 // Backend is where all the work happens. |
18 class FakeAttachmentStore::Backend | 18 class FakeAttachmentStore::Backend |
19 : public base::RefCountedThreadSafe<FakeAttachmentStore::Backend> { | 19 : public base::RefCountedThreadSafe<FakeAttachmentStore::Backend> { |
20 public: | 20 public: |
21 // Construct a Backend that posts its results to |frontend_task_runner|. | 21 // Construct a Backend that posts its results to |frontend_task_runner|. |
22 Backend( | 22 Backend( |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
89 AttachmentMap::iterator attachments_iter = attachments_.find(*ids_iter); | 89 AttachmentMap::iterator attachments_iter = attachments_.find(*ids_iter); |
90 if (attachments_iter != attachments_.end()) { | 90 if (attachments_iter != attachments_.end()) { |
91 attachments_.erase(attachments_iter); | 91 attachments_.erase(attachments_iter); |
92 } | 92 } |
93 } | 93 } |
94 frontend_task_runner_->PostTask(FROM_HERE, base::Bind(callback, result)); | 94 frontend_task_runner_->PostTask(FROM_HERE, base::Bind(callback, result)); |
95 } | 95 } |
96 | 96 |
97 FakeAttachmentStore::FakeAttachmentStore( | 97 FakeAttachmentStore::FakeAttachmentStore( |
98 const scoped_refptr<base::SequencedTaskRunner>& backend_task_runner) | 98 const scoped_refptr<base::SequencedTaskRunner>& backend_task_runner) |
99 : backend_(new Backend(base::MessageLoopProxy::current())), | 99 : backend_(new Backend(base::ThreadTaskRunnerHandle::Get())), |
100 backend_task_runner_(backend_task_runner) {} | 100 backend_task_runner_(backend_task_runner) {} |
101 | 101 |
102 FakeAttachmentStore::~FakeAttachmentStore() {} | 102 FakeAttachmentStore::~FakeAttachmentStore() {} |
103 | 103 |
104 void FakeAttachmentStore::Read(const AttachmentIdList& ids, | 104 void FakeAttachmentStore::Read(const AttachmentIdList& ids, |
105 const ReadCallback& callback) { | 105 const ReadCallback& callback) { |
106 backend_task_runner_->PostTask( | 106 backend_task_runner_->PostTask( |
107 FROM_HERE, | 107 FROM_HERE, |
108 base::Bind(&FakeAttachmentStore::Backend::Read, backend_, ids, callback)); | 108 base::Bind(&FakeAttachmentStore::Backend::Read, backend_, ids, callback)); |
109 } | 109 } |
110 | 110 |
111 void FakeAttachmentStore::Write(const AttachmentList& attachments, | 111 void FakeAttachmentStore::Write(const AttachmentList& attachments, |
112 const WriteCallback& callback) { | 112 const WriteCallback& callback) { |
113 backend_task_runner_->PostTask( | 113 backend_task_runner_->PostTask( |
114 FROM_HERE, | 114 FROM_HERE, |
115 base::Bind(&FakeAttachmentStore::Backend::Write, | 115 base::Bind(&FakeAttachmentStore::Backend::Write, |
116 backend_, | 116 backend_, |
117 attachments, | 117 attachments, |
118 callback)); | 118 callback)); |
119 } | 119 } |
120 | 120 |
121 void FakeAttachmentStore::Drop(const AttachmentIdList& ids, | 121 void FakeAttachmentStore::Drop(const AttachmentIdList& ids, |
122 const DropCallback& callback) { | 122 const DropCallback& callback) { |
123 backend_task_runner_->PostTask( | 123 backend_task_runner_->PostTask( |
124 FROM_HERE, | 124 FROM_HERE, |
125 base::Bind(&FakeAttachmentStore::Backend::Drop, backend_, ids, callback)); | 125 base::Bind(&FakeAttachmentStore::Backend::Drop, backend_, ids, callback)); |
126 } | 126 } |
127 | 127 |
128 } // namespace syncer | 128 } // namespace syncer |
OLD | NEW |