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.
5 #ifndef CHROME_BROWSER_CHROMEOS_CONTACTS_CONTACT_MAP_H_
6 #define CHROME_BROWSER_CHROMEOS_CONTACTS_CONTACT_MAP_H_
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.h"
21 // Stores Contact objects indexed by their IDs.
24 typedef std::map
<std::string
, Contact
*> Map
;
25 typedef Map::const_iterator const_iterator
;
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
,
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
35 DROP_DELETED_CONTACTS
,
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(); }
46 // Returns the contact with ID |contact_id|. NULL is returned if the contact
48 const Contact
* Find(const std::string
& contact_id
) const;
50 // Deletes the contact with ID |contact_id|.
51 void Erase(const std::string
& contact_id
);
53 // Deletes all contacts.
56 // Merges |updated_contacts| into |contacts_|.
57 void Merge(scoped_ptr
<ScopedVector
<Contact
> > updated_contacts
,
58 DeletedContactPolicy policy
);
63 // Deletes values in |contacts_|.
64 STLValueDeleter
<Map
> contacts_deleter_
;
66 DISALLOW_COPY_AND_ASSIGN(ContactMap
);
69 } // namespace contacts
71 #endif // CHROME_BROWSER_CHROMEOS_CONTACTS_CONTACT_MAP_H_