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

Side by Side Diff: chrome/browser/chromeos/contacts/fake_contact_store.h

Issue 10850033: contacts: Add ContactStoreFactory and FakeContactStore. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: add missing clear() call in FakeContactStore Created 8 years, 4 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 #ifndef CHROME_BROWSER_CHROMEOS_CONTACTS_FAKE_CONTACT_STORE_H_
6 #define CHROME_BROWSER_CHROMEOS_CONTACTS_FAKE_CONTACT_STORE_H_
7
8 #include "chrome/browser/chromeos/contacts/contact_store.h"
9
10 #include <map>
11 #include <string>
12 #include <vector>
13
14 #include "base/basictypes.h"
15 #include "base/compiler_specific.h"
16 #include "base/observer_list.h"
17 #include "base/stl_util.h"
18
19 class Profile;
20
21 namespace contacts {
22
23 class Contact;
24 class FakeContactStoreFactory;
25 typedef std::vector<const Contact*> ContactPointers;
26
27 // A "fake" in-memory implementation of ContactStore used for testing.
28 class FakeContactStore : public ContactStore {
29 public:
30 explicit FakeContactStore(FakeContactStoreFactory* factory);
31 virtual ~FakeContactStore();
32
33 // Makes an internal copy of |contacts| so they can be returned by
34 // AppendContacts() and GetContactByProviderId().
35 void SetContacts(const ContactPointers& contacts);
36
37 // Invokes observers' OnContactsUpdated() methods.
38 void NotifyObserversAboutContactsUpdate();
39
40 // ContactStore implementation:
41 virtual void Init() OVERRIDE;
42 virtual void AppendContacts(ContactPointers* contacts_out) OVERRIDE;
43 virtual const Contact* GetContactByProviderId(
44 const std::string& provider_id) OVERRIDE;
45 virtual void AddObserver(ContactStoreObserver* observer) OVERRIDE;
46 virtual void RemoveObserver(ContactStoreObserver* observer) OVERRIDE;
47
48 private:
49 // Map from a contact's provider ID to the contact itself.
50 typedef std::map<std::string, Contact*> ContactMap;
51
52 // Factory that created this store. Not owned.
53 FakeContactStoreFactory* factory_;
54
55 ObserverList<ContactStoreObserver> observers_;
56
57 // Owns the pointed-to Contact values.
58 ContactMap contacts_;
59
60 // Deletes values in |contacts_|.
61 STLValueDeleter<ContactMap> contacts_deleter_;
62
63 DISALLOW_COPY_AND_ASSIGN(FakeContactStore);
64 };
65
66 // ContactStoreFactory implementation that returns FakeContactStores.
67 class FakeContactStoreFactory : public ContactStoreFactory {
68 public:
69 FakeContactStoreFactory();
70 virtual ~FakeContactStoreFactory();
71
72 // Returns the FakeContactStore previously created for |profile|.
73 FakeContactStore* GetContactStoreForProfile(Profile* profile);
74
75 // Updates |stores_| after being called by a FakeContactStore's d'tor.
76 void OnFakeContactStoreDestroyed(FakeContactStore* store);
satorux1 2012/08/03 18:16:52 I think the function name comes from the fact that
Daniel Erat 2012/08/03 20:00:23 Done.
77
78 // ContactStoreFactory implementation:
79 virtual ContactStore* CreateContactStore(Profile* profile) OVERRIDE;
80
81 private:
82 typedef std::map<Profile*, FakeContactStore*> ProfileStoreMap;
83
84 // Live FakeContactStore objects that we've handed out. We don't retain
85 // ownership of these, but we hang on to the pointers so that tests can
86 // manipulate the stores while they're in use.
87 ProfileStoreMap stores_;
88
89 DISALLOW_COPY_AND_ASSIGN(FakeContactStoreFactory);
90 };
91
92 } // namespace contacts
93
94 #endif // CHROME_BROWSER_CHROMEOS_CONTACTS_FAKE_CONTACT_STORE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698