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_MANAGER_STUB_H_ | |
6 #define CHROME_BROWSER_CHROMEOS_CONTACTS_CONTACT_MANAGER_STUB_H_ | |
7 | |
8 #include "chrome/browser/chromeos/contacts/contact_manager.h" | |
9 | |
10 #include "base/memory/scoped_vector.h" | |
11 | |
12 namespace contacts { | |
13 | |
14 // ContactManagerInterface implementation that returns a fixed set of contacts. | |
15 // Used for testing. | |
16 class ContactManagerStub : public ContactManagerInterface { | |
17 public: | |
18 explicit ContactManagerStub(Profile* profile); | |
19 virtual ~ContactManagerStub(); | |
20 | |
21 // Updates |contacts_|. | |
22 void SetContacts(const ContactPointers& contacts); | |
23 | |
24 // Invokes OnContactsUpdated() on |observers_|. | |
25 void NotifyObserversAboutUpdatedContacts(); | |
26 | |
27 // ContactManagerInterface overrides: | |
28 virtual base::WeakPtr<ContactManagerInterface> GetWeakPtr() OVERRIDE; | |
29 virtual void AddObserver(ContactManagerObserver* observer, Profile* profile) | |
30 OVERRIDE; | |
31 virtual void RemoveObserver(ContactManagerObserver* observer, | |
32 Profile* profile) OVERRIDE; | |
33 virtual scoped_ptr<ContactPointers> GetAllContacts(Profile* profile) OVERRIDE; | |
34 virtual const Contact* GetContactById(Profile* profile, | |
35 const std::string& contact_id) OVERRIDE; | |
36 | |
37 private: | |
38 // Profile expected to be passed to ContactManagerInterface methods. | |
39 // Passing any other profile will result in a crash. | |
40 Profile* profile_; // not owned | |
41 | |
42 // Observers registered for |profile_|. | |
43 ObserverList<ContactManagerObserver> observers_; | |
44 | |
45 // Contacts that will be returned by GetAllContacts() and GetContactById(). | |
46 ScopedVector<Contact> contacts_; | |
47 | |
48 // Note: This should remain the last member so it'll be destroyed and | |
49 // invalidate its weak pointers before any other members are destroyed. | |
50 base::WeakPtrFactory<ContactManagerInterface> weak_ptr_factory_; | |
51 | |
52 DISALLOW_COPY_AND_ASSIGN(ContactManagerStub); | |
53 }; | |
54 | |
55 } // namespace contacts | |
56 | |
57 #endif // CHROME_BROWSER_CHROMEOS_CONTACTS_CONTACT_MANAGER_STUB_H_ | |
OLD | NEW |