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

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

Issue 986743004: [Sync] Refactor AttachmentStore classes. Introduce concept of referrer. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 5 years, 9 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/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"
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
59 } 59 }
60 } 60 }
61 if (!unavailable_attachments->empty()) { 61 if (!unavailable_attachments->empty()) {
62 result_code = AttachmentStore::UNSPECIFIED_ERROR; 62 result_code = AttachmentStore::UNSPECIFIED_ERROR;
63 } 63 }
64 PostCallback(base::Bind(callback, result_code, base::Passed(&result_map), 64 PostCallback(base::Bind(callback, result_code, base::Passed(&result_map),
65 base::Passed(&unavailable_attachments))); 65 base::Passed(&unavailable_attachments)));
66 } 66 }
67 67
68 void InMemoryAttachmentStore::Write( 68 void InMemoryAttachmentStore::Write(
69 AttachmentStore::AttachmentReferrer referrer,
69 const AttachmentList& attachments, 70 const AttachmentList& attachments,
70 const AttachmentStore::WriteCallback& callback) { 71 const AttachmentStore::WriteCallback& callback) {
71 DCHECK(CalledOnValidThread()); 72 DCHECK(CalledOnValidThread());
72 AttachmentList::const_iterator iter = attachments.begin(); 73 AttachmentList::const_iterator iter = attachments.begin();
73 AttachmentList::const_iterator end = attachments.end(); 74 AttachmentList::const_iterator end = attachments.end();
74 for (; iter != end; ++iter) { 75 for (; iter != end; ++iter) {
75 attachments_.insert(std::make_pair(iter->GetId(), *iter)); 76 attachments_.insert(std::make_pair(iter->GetId(), *iter));
76 } 77 }
77 PostCallback(base::Bind(callback, AttachmentStore::SUCCESS)); 78 PostCallback(base::Bind(callback, AttachmentStore::SUCCESS));
78 } 79 }
79 80
80 void InMemoryAttachmentStore::Drop( 81 void InMemoryAttachmentStore::Drop(
82 AttachmentStore::AttachmentReferrer referrer,
81 const AttachmentIdList& ids, 83 const AttachmentIdList& ids,
82 const AttachmentStore::DropCallback& callback) { 84 const AttachmentStore::DropCallback& callback) {
83 DCHECK(CalledOnValidThread()); 85 DCHECK(CalledOnValidThread());
84 AttachmentStore::Result result = AttachmentStore::SUCCESS; 86 AttachmentStore::Result result = AttachmentStore::SUCCESS;
85 AttachmentIdList::const_iterator ids_iter = ids.begin(); 87 AttachmentIdList::const_iterator ids_iter = ids.begin();
86 AttachmentIdList::const_iterator ids_end = ids.end(); 88 AttachmentIdList::const_iterator ids_end = ids.end();
87 for (; ids_iter != ids_end; ++ids_iter) { 89 for (; ids_iter != ids_end; ++ids_iter) {
88 AttachmentMap::iterator attachments_iter = attachments_.find(*ids_iter); 90 AttachmentMap::iterator attachments_iter = attachments_.find(*ids_iter);
89 if (attachments_iter != attachments_.end()) { 91 if (attachments_iter != attachments_.end()) {
90 attachments_.erase(attachments_iter); 92 attachments_.erase(attachments_iter);
(...skipping 17 matching lines...) Expand all
108 if (attachments_iter != attachments_.end()) { 110 if (attachments_iter != attachments_.end()) {
109 AppendMetadata(metadata_list.get(), attachments_iter->second); 111 AppendMetadata(metadata_list.get(), attachments_iter->second);
110 } else { 112 } else {
111 result_code = AttachmentStore::UNSPECIFIED_ERROR; 113 result_code = AttachmentStore::UNSPECIFIED_ERROR;
112 } 114 }
113 } 115 }
114 PostCallback(base::Bind(callback, result_code, base::Passed(&metadata_list))); 116 PostCallback(base::Bind(callback, result_code, base::Passed(&metadata_list)));
115 } 117 }
116 118
117 void InMemoryAttachmentStore::ReadAllMetadata( 119 void InMemoryAttachmentStore::ReadAllMetadata(
120 AttachmentStore::AttachmentReferrer referrer,
118 const AttachmentStore::ReadMetadataCallback& callback) { 121 const AttachmentStore::ReadMetadataCallback& callback) {
119 DCHECK(CalledOnValidThread()); 122 DCHECK(CalledOnValidThread());
120 AttachmentStore::Result result_code = AttachmentStore::SUCCESS; 123 AttachmentStore::Result result_code = AttachmentStore::SUCCESS;
121 scoped_ptr<AttachmentMetadataList> metadata_list( 124 scoped_ptr<AttachmentMetadataList> metadata_list(
122 new AttachmentMetadataList()); 125 new AttachmentMetadataList());
123 126
124 for (AttachmentMap::const_iterator iter = attachments_.begin(); 127 for (AttachmentMap::const_iterator iter = attachments_.begin();
125 iter != attachments_.end(); ++iter) { 128 iter != attachments_.end(); ++iter) {
126 AppendMetadata(metadata_list.get(), iter->second); 129 AppendMetadata(metadata_list.get(), iter->second);
127 } 130 }
128 PostCallback(base::Bind(callback, result_code, base::Passed(&metadata_list))); 131 PostCallback(base::Bind(callback, result_code, base::Passed(&metadata_list)));
129 } 132 }
130 133
131 } // namespace syncer 134 } // namespace syncer
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698