| 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_map.h" | 5 #include "chrome/browser/chromeos/contacts/contact_map.h" |
| 6 | 6 |
| 7 #include "chrome/browser/chromeos/contacts/contact.pb.h" | 7 #include "chrome/browser/chromeos/contacts/contact.pb.h" |
| 8 | 8 |
| 9 namespace contacts { | 9 namespace contacts { |
| 10 | 10 |
| 11 ContactMap::ContactMap() : contacts_deleter_(&contacts_) {} | 11 ContactMap::ContactMap() : contacts_deleter_(&contacts_) {} |
| 12 | 12 |
| 13 ContactMap::~ContactMap() {} | 13 ContactMap::~ContactMap() {} |
| 14 | 14 |
| 15 const Contact* ContactMap::Find(const std::string& contact_id) const { | 15 const Contact* ContactMap::Find(const std::string& contact_id) const { |
| 16 Map::const_iterator it = contacts_.find(contact_id); | 16 Map::const_iterator it = contacts_.find(contact_id); |
| 17 return (it != contacts_.end()) ? it->second : NULL; | 17 return (it != contacts_.end()) ? it->second : NULL; |
| 18 } | 18 } |
| 19 | 19 |
| 20 void ContactMap::Erase(const std::string& contact_id) { |
| 21 Map::iterator it = contacts_.find(contact_id); |
| 22 if (it == contacts_.end()) |
| 23 return; |
| 24 |
| 25 delete it->second; |
| 26 contacts_.erase(it); |
| 27 } |
| 28 |
| 20 void ContactMap::Clear() { | 29 void ContactMap::Clear() { |
| 21 STLDeleteValues(&contacts_); | 30 STLDeleteValues(&contacts_); |
| 22 } | 31 } |
| 23 | 32 |
| 24 void ContactMap::Merge(scoped_ptr<ScopedVector<Contact> > updated_contacts, | 33 void ContactMap::Merge(scoped_ptr<ScopedVector<Contact> > updated_contacts, |
| 25 DeletedContactPolicy policy) { | 34 DeletedContactPolicy policy) { |
| 26 for (ScopedVector<Contact>::iterator it = updated_contacts->begin(); | 35 for (ScopedVector<Contact>::iterator it = updated_contacts->begin(); |
| 27 it != updated_contacts->end(); ++it) { | 36 it != updated_contacts->end(); ++it) { |
| 28 Contact* contact = *it; | 37 Contact* contact = *it; |
| 29 Map::iterator map_it = contacts_.find(contact->contact_id()); | 38 Map::iterator map_it = contacts_.find(contact->contact_id()); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 43 contacts_[contact->contact_id()] = contact; | 52 contacts_[contact->contact_id()] = contact; |
| 44 } | 53 } |
| 45 } | 54 } |
| 46 } | 55 } |
| 47 | 56 |
| 48 // Make sure that the Contact objects that we just saved to the map won't be | 57 // Make sure that the Contact objects that we just saved to the map won't be |
| 49 // destroyed when |updated_contacts| is destroyed. | 58 // destroyed when |updated_contacts| is destroyed. |
| 50 updated_contacts->weak_clear(); | 59 updated_contacts->weak_clear(); |
| 51 } | 60 } |
| 52 | 61 |
| 53 base::Time ContactMap::GetMaxUpdateTime() const { | |
| 54 base::Time max_update_time; | |
| 55 for (const_iterator it = begin(); it != end(); ++it) { | |
| 56 const Contact* contact = it->second; | |
| 57 const base::Time update_time = | |
| 58 base::Time::FromInternalValue(contact->update_time()); | |
| 59 if (!update_time.is_null() && | |
| 60 (max_update_time.is_null() || max_update_time < update_time)) { | |
| 61 max_update_time = update_time; | |
| 62 } | |
| 63 } | |
| 64 return max_update_time; | |
| 65 } | |
| 66 | |
| 67 } // namespace contacts | 62 } // namespace contacts |
| OLD | NEW |