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

Side by Side Diff: chrome/browser/chromeos/contacts/contact_map.cc

Issue 10905033: contacts: Add ContactMap class. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: apply review feedback Created 8 years, 3 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 | Annotate | Revision Log
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "chrome/browser/chromeos/contacts/contact_map.h"
6
7 #include "chrome/browser/chromeos/contacts/contact.pb.h"
8
9 namespace contacts {
10
11 ContactMap::ContactMap() : contacts_deleter_(&contacts_) {}
12
13 ContactMap::~ContactMap() {}
14
15 const Contact* ContactMap::Find(const std::string& contact_id) const {
16 Map::const_iterator it = contacts_.find(contact_id);
17 return (it != contacts_.end()) ? it->second : NULL;
18 }
19
20 void ContactMap::Clear() {
21 STLDeleteValues(&contacts_);
22 contacts_.clear();
tfarina 2012/09/09 19:20:49 STLDeleteValues already does this for you, no?
Daniel Erat 2012/09/10 15:01:44 Thanks, this was unexpected to me. Done.
23 }
24
25 void ContactMap::Merge(scoped_ptr<ScopedVector<Contact> > updated_contacts,
26 DeletedContactPolicy policy) {
27 for (ScopedVector<Contact>::iterator it = updated_contacts->begin();
28 it != updated_contacts->end(); ++it) {
29 Contact* contact = *it;
30 Map::iterator map_it = contacts_.find(contact->contact_id());
31
32 if (contact->deleted() && policy == DROP_DELETED_CONTACTS) {
33 // Also delete the previous version of the contact, if any.
34 if (map_it != contacts_.end()) {
35 delete map_it->second;
36 contacts_.erase(map_it);
37 }
38 delete contact;
39 } else {
40 if (map_it != contacts_.end()) {
41 delete map_it->second;
42 map_it->second = contact;
43 } else {
44 contacts_[contact->contact_id()] = contact;
45 }
46 }
47 }
48
49 // Make sure that the Contact objects that we just saved to the map won't be
50 // destroyed when |updated_contacts| is destroyed.
51 updated_contacts->weak_clear();
52 }
53
54 base::Time ContactMap::GetMaxUpdateTime() const {
55 base::Time max_update_time;
56 for (const_iterator it = begin(); it != end(); ++it) {
57 const Contact* contact = it->second;
58 const base::Time update_time =
59 base::Time::FromInternalValue(contact->update_time());
60 if (!update_time.is_null() &&
61 (max_update_time.is_null() || max_update_time < update_time)) {
62 max_update_time = update_time;
63 }
64 }
65 return max_update_time;
66 }
67
68 } // namespace contacts
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698