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_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 void set_permit_store_creation(bool permit) { |
| 73 permit_store_creation_ = permit; |
| 74 } |
| 75 |
| 76 // Returns the FakeContactStore previously created for |profile|. |
| 77 FakeContactStore* GetContactStoreForProfile(Profile* profile); |
| 78 |
| 79 // Removes |store| from |stores_| after being called by a FakeContactStore's |
| 80 // d'tor. |
| 81 void RemoveStore(FakeContactStore* store); |
| 82 |
| 83 // ContactStoreFactory implementation: |
| 84 virtual bool CanCreateContactStoreForProfile(Profile* profile) OVERRIDE; |
| 85 virtual ContactStore* CreateContactStore(Profile* profile) OVERRIDE; |
| 86 |
| 87 private: |
| 88 typedef std::map<Profile*, FakeContactStore*> ProfileStoreMap; |
| 89 |
| 90 // Live FakeContactStore objects that we've handed out. We don't retain |
| 91 // ownership of these, but we hang on to the pointers so that tests can |
| 92 // manipulate the stores while they're in use. |
| 93 ProfileStoreMap stores_; |
| 94 |
| 95 // Should CanCreateContactStoreForProfile() return true? |
| 96 bool permit_store_creation_; |
| 97 |
| 98 DISALLOW_COPY_AND_ASSIGN(FakeContactStoreFactory); |
| 99 }; |
| 100 |
| 101 } // namespace contacts |
| 102 |
| 103 #endif // CHROME_BROWSER_CHROMEOS_CONTACTS_FAKE_CONTACT_STORE_H_ |
OLD | NEW |