OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "chrome/browser/chromeos/contacts/contact_database.h" | 5 #include "chrome/browser/chromeos/contacts/contact_database.h" |
6 | 6 |
7 #include <set> | 7 #include <set> |
8 | 8 |
9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
10 #include "base/sequenced_task_runner.h" | 10 #include "base/sequenced_task_runner.h" |
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
207 | 207 |
208 // TODO(derat): Serializing all of the contacts and so we can write them in a | 208 // TODO(derat): Serializing all of the contacts and so we can write them in a |
209 // single batch may be expensive, memory-wise. Consider writing them in | 209 // single batch may be expensive, memory-wise. Consider writing them in |
210 // several batches instead. (To avoid using partial writes in the event of a | 210 // several batches instead. (To avoid using partial writes in the event of a |
211 // crash, maybe add a dummy "write completed" contact that's removed in the | 211 // crash, maybe add a dummy "write completed" contact that's removed in the |
212 // first batch and added in the last.) | 212 // first batch and added in the last.) |
213 leveldb::WriteBatch updates; | 213 leveldb::WriteBatch updates; |
214 for (ContactPointers::const_iterator it = contacts->begin(); | 214 for (ContactPointers::const_iterator it = contacts->begin(); |
215 it != contacts->end(); ++it) { | 215 it != contacts->end(); ++it) { |
216 const contacts::Contact& contact = **it; | 216 const contacts::Contact& contact = **it; |
217 if (contact.provider_id() == kUpdateMetadataKey) { | 217 if (contact.contact_id() == kUpdateMetadataKey) { |
218 LOG(WARNING) << "Skipping contact with reserved ID " | 218 LOG(WARNING) << "Skipping contact with reserved ID " |
219 << contact.provider_id(); | 219 << contact.contact_id(); |
220 continue; | 220 continue; |
221 } | 221 } |
222 updates.Put(leveldb::Slice(contact.provider_id()), | 222 updates.Put(leveldb::Slice(contact.contact_id()), |
223 leveldb::Slice(contact.SerializeAsString())); | 223 leveldb::Slice(contact.SerializeAsString())); |
224 if (is_full_update) | 224 if (is_full_update) |
225 keys_to_delete.erase(contact.provider_id()); | 225 keys_to_delete.erase(contact.contact_id()); |
226 } | 226 } |
227 | 227 |
228 for (std::set<std::string>::const_iterator it = keys_to_delete.begin(); | 228 for (std::set<std::string>::const_iterator it = keys_to_delete.begin(); |
229 it != keys_to_delete.end(); ++it) { | 229 it != keys_to_delete.end(); ++it) { |
230 updates.Delete(leveldb::Slice(*it)); | 230 updates.Delete(leveldb::Slice(*it)); |
231 } | 231 } |
232 | 232 |
233 updates.Put(leveldb::Slice(kUpdateMetadataKey), | 233 updates.Put(leveldb::Slice(kUpdateMetadataKey), |
234 leveldb::Slice(metadata->SerializeAsString())); | 234 leveldb::Slice(metadata->SerializeAsString())); |
235 | 235 |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
275 } | 275 } |
276 contacts->push_back(contact.release()); | 276 contacts->push_back(contact.release()); |
277 } | 277 } |
278 db_iterator->Next(); | 278 db_iterator->Next(); |
279 } | 279 } |
280 | 280 |
281 *success = true; | 281 *success = true; |
282 } | 282 } |
283 | 283 |
284 } // namespace contacts | 284 } // namespace contacts |
OLD | NEW |