OLD | NEW |
| (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 #ifndef CHROME_BROWSER_CHROMEOS_CONTACTS_CONTACT_MAP_H_ | |
6 #define CHROME_BROWSER_CHROMEOS_CONTACTS_CONTACT_MAP_H_ | |
7 | |
8 #include <map> | |
9 #include <string> | |
10 | |
11 #include "base/basictypes.h" | |
12 #include "base/memory/scoped_ptr.h" | |
13 #include "base/memory/scoped_vector.h" | |
14 #include "base/stl_util.h" | |
15 #include "base/time/time.h" | |
16 | |
17 namespace contacts { | |
18 | |
19 class Contact; | |
20 | |
21 // Stores Contact objects indexed by their IDs. | |
22 class ContactMap { | |
23 public: | |
24 typedef std::map<std::string, Contact*> Map; | |
25 typedef Map::const_iterator const_iterator; | |
26 | |
27 // What should Merge() do when passed a deleted contact? | |
28 enum DeletedContactPolicy { | |
29 // The deleted contact will be inserted into the map. | |
30 KEEP_DELETED_CONTACTS, | |
31 | |
32 // The deleted contact will not be deleted from the map, and if there is a | |
33 // previous version of the now-deleted contact already in the map, it will | |
34 // also be removed. | |
35 DROP_DELETED_CONTACTS, | |
36 }; | |
37 | |
38 ContactMap(); | |
39 ~ContactMap(); | |
40 | |
41 bool empty() const { return contacts_.empty(); } | |
42 size_t size() const { return contacts_.size(); } | |
43 const_iterator begin() const { return contacts_.begin(); } | |
44 const_iterator end() const { return contacts_.end(); } | |
45 | |
46 // Returns the contact with ID |contact_id|. NULL is returned if the contact | |
47 // isn't present. | |
48 const Contact* Find(const std::string& contact_id) const; | |
49 | |
50 // Deletes the contact with ID |contact_id|. | |
51 void Erase(const std::string& contact_id); | |
52 | |
53 // Deletes all contacts. | |
54 void Clear(); | |
55 | |
56 // Merges |updated_contacts| into |contacts_|. | |
57 void Merge(scoped_ptr<ScopedVector<Contact> > updated_contacts, | |
58 DeletedContactPolicy policy); | |
59 | |
60 private: | |
61 Map contacts_; | |
62 | |
63 // Deletes values in |contacts_|. | |
64 STLValueDeleter<Map> contacts_deleter_; | |
65 | |
66 DISALLOW_COPY_AND_ASSIGN(ContactMap); | |
67 }; | |
68 | |
69 } // namespace contacts | |
70 | |
71 #endif // CHROME_BROWSER_CHROMEOS_CONTACTS_CONTACT_MAP_H_ | |
OLD | NEW |