| 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" |
| 11 | 11 |
| 12 namespace syncer { | 12 namespace syncer { |
| 13 | 13 |
| 14 InMemoryAttachmentStore::InMemoryAttachmentStore( | 14 InMemoryAttachmentStore::InMemoryAttachmentStore( |
| 15 const scoped_refptr<base::SingleThreadTaskRunner>& callback_task_runner) | 15 const scoped_refptr<base::SingleThreadTaskRunner>& callback_task_runner) |
| 16 : callback_task_runner_(callback_task_runner) { | 16 : callback_task_runner_(callback_task_runner) { |
| 17 // Object is created on one thread but used on another. | 17 // Object is created on one thread but used on another. |
| 18 DetachFromThread(); | 18 DetachFromThread(); |
| 19 } | 19 } |
| 20 | 20 |
| 21 InMemoryAttachmentStore::~InMemoryAttachmentStore() { | 21 InMemoryAttachmentStore::~InMemoryAttachmentStore() { |
| 22 } | 22 } |
| 23 | 23 |
| 24 void InMemoryAttachmentStore::Load(const LoadCallback& callback) { |
| 25 DCHECK(CalledOnValidThread()); |
| 26 Result result_code = SUCCESS; |
| 27 callback_task_runner_->PostTask(FROM_HERE, base::Bind(callback, result_code)); |
| 28 } |
| 29 |
| 24 void InMemoryAttachmentStore::Read(const AttachmentIdList& ids, | 30 void InMemoryAttachmentStore::Read(const AttachmentIdList& ids, |
| 25 const ReadCallback& callback) { | 31 const ReadCallback& callback) { |
| 26 DCHECK(CalledOnValidThread()); | 32 DCHECK(CalledOnValidThread()); |
| 27 Result result_code = SUCCESS; | 33 Result result_code = SUCCESS; |
| 28 AttachmentIdList::const_iterator id_iter = ids.begin(); | 34 AttachmentIdList::const_iterator id_iter = ids.begin(); |
| 29 AttachmentIdList::const_iterator id_end = ids.end(); | 35 AttachmentIdList::const_iterator id_end = ids.end(); |
| 30 scoped_ptr<AttachmentMap> result_map(new AttachmentMap); | 36 scoped_ptr<AttachmentMap> result_map(new AttachmentMap); |
| 31 scoped_ptr<AttachmentIdList> unavailable_attachments(new AttachmentIdList); | 37 scoped_ptr<AttachmentIdList> unavailable_attachments(new AttachmentIdList); |
| 32 for (; id_iter != id_end; ++id_iter) { | 38 for (; id_iter != id_end; ++id_iter) { |
| 33 const AttachmentId& id = *id_iter; | 39 const AttachmentId& id = *id_iter; |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 71 for (; ids_iter != ids_end; ++ids_iter) { | 77 for (; ids_iter != ids_end; ++ids_iter) { |
| 72 AttachmentMap::iterator attachments_iter = attachments_.find(*ids_iter); | 78 AttachmentMap::iterator attachments_iter = attachments_.find(*ids_iter); |
| 73 if (attachments_iter != attachments_.end()) { | 79 if (attachments_iter != attachments_.end()) { |
| 74 attachments_.erase(attachments_iter); | 80 attachments_.erase(attachments_iter); |
| 75 } | 81 } |
| 76 } | 82 } |
| 77 callback_task_runner_->PostTask(FROM_HERE, base::Bind(callback, result)); | 83 callback_task_runner_->PostTask(FROM_HERE, base::Bind(callback, result)); |
| 78 } | 84 } |
| 79 | 85 |
| 80 } // namespace syncer | 86 } // namespace syncer |
| OLD | NEW |