Index: chrome/browser/chromeos/contacts/fake_contact_store.h |
diff --git a/chrome/browser/chromeos/contacts/fake_contact_store.h b/chrome/browser/chromeos/contacts/fake_contact_store.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..1c0e7d2b91c1eb31a3c27eb9e6db521030cbde46 |
--- /dev/null |
+++ b/chrome/browser/chromeos/contacts/fake_contact_store.h |
@@ -0,0 +1,94 @@ |
+// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#ifndef CHROME_BROWSER_CHROMEOS_CONTACTS_FAKE_CONTACT_STORE_H_ |
+#define CHROME_BROWSER_CHROMEOS_CONTACTS_FAKE_CONTACT_STORE_H_ |
+ |
+#include "chrome/browser/chromeos/contacts/contact_store.h" |
+ |
+#include <map> |
+#include <string> |
+#include <vector> |
+ |
+#include "base/basictypes.h" |
+#include "base/compiler_specific.h" |
+#include "base/observer_list.h" |
+#include "base/stl_util.h" |
+ |
+class Profile; |
+ |
+namespace contacts { |
+ |
+class Contact; |
+class FakeContactStoreFactory; |
+typedef std::vector<const Contact*> ContactPointers; |
+ |
+// A "fake" in-memory implementation of ContactStore used for testing. |
+class FakeContactStore : public ContactStore { |
+ public: |
+ explicit FakeContactStore(FakeContactStoreFactory* factory); |
+ virtual ~FakeContactStore(); |
+ |
+ // Makes an internal copy of |contacts| so they can be returned by |
+ // AppendContacts() and GetContactByProviderId(). |
+ void SetContacts(const ContactPointers& contacts); |
+ |
+ // Invokes observers' OnContactsUpdated() methods. |
+ void NotifyObserversAboutContactsUpdate(); |
+ |
+ // ContactStore implementation: |
+ virtual void Init() OVERRIDE; |
+ virtual void AppendContacts(ContactPointers* contacts_out) OVERRIDE; |
+ virtual const Contact* GetContactByProviderId( |
+ const std::string& provider_id) OVERRIDE; |
+ virtual void AddObserver(ContactStoreObserver* observer) OVERRIDE; |
+ virtual void RemoveObserver(ContactStoreObserver* observer) OVERRIDE; |
+ |
+ private: |
+ // Map from a contact's provider ID to the contact itself. |
+ typedef std::map<std::string, Contact*> ContactMap; |
+ |
+ // Factory that created this store. Not owned. |
+ FakeContactStoreFactory* factory_; |
+ |
+ ObserverList<ContactStoreObserver> observers_; |
+ |
+ // Owns the pointed-to Contact values. |
+ ContactMap contacts_; |
+ |
+ // Deletes values in |contacts_|. |
+ STLValueDeleter<ContactMap> contacts_deleter_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(FakeContactStore); |
+}; |
+ |
+// ContactStoreFactory implementation that returns FakeContactStores. |
+class FakeContactStoreFactory : public ContactStoreFactory { |
+ public: |
+ FakeContactStoreFactory(); |
+ virtual ~FakeContactStoreFactory(); |
+ |
+ // Returns the FakeContactStore previously created for |profile|. |
+ FakeContactStore* GetContactStoreForProfile(Profile* profile); |
+ |
+ // Updates |stores_| after being called by a FakeContactStore's d'tor. |
+ 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.
|
+ |
+ // ContactStoreFactory implementation: |
+ virtual ContactStore* CreateContactStore(Profile* profile) OVERRIDE; |
+ |
+ private: |
+ typedef std::map<Profile*, FakeContactStore*> ProfileStoreMap; |
+ |
+ // Live FakeContactStore objects that we've handed out. We don't retain |
+ // ownership of these, but we hang on to the pointers so that tests can |
+ // manipulate the stores while they're in use. |
+ ProfileStoreMap stores_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(FakeContactStoreFactory); |
+}; |
+ |
+} // namespace contacts |
+ |
+#endif // CHROME_BROWSER_CHROMEOS_CONTACTS_FAKE_CONTACT_STORE_H_ |