summaryrefslogtreecommitdiffstats
path: root/chrome/browser/chromeos/contacts/contact_manager_stub.h
blob: 340374073b20be56799c63013f88e5f22bb14bd9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
// 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_CONTACT_MANAGER_STUB_H_
#define CHROME_BROWSER_CHROMEOS_CONTACTS_CONTACT_MANAGER_STUB_H_

#include "chrome/browser/chromeos/contacts/contact_manager.h"

#include "base/memory/scoped_vector.h"

namespace contacts {

// ContactManagerInterface implementation that returns a fixed set of contacts.
// Used for testing.
class ContactManagerStub : public ContactManagerInterface {
 public:
  explicit ContactManagerStub(Profile* profile);
  virtual ~ContactManagerStub();

  // Updates |contacts_|.
  void SetContacts(const ContactPointers& contacts);

  // Invokes OnContactsUpdated() on |observers_|.
  void NotifyObserversAboutUpdatedContacts();

  // ContactManagerInterface overrides:
  virtual base::WeakPtr<ContactManagerInterface> GetWeakPtr() OVERRIDE;
  virtual void AddObserver(ContactManagerObserver* observer, Profile* profile)
      OVERRIDE;
  virtual void RemoveObserver(ContactManagerObserver* observer,
                              Profile* profile) OVERRIDE;
  virtual scoped_ptr<ContactPointers> GetAllContacts(Profile* profile) OVERRIDE;
  virtual const Contact* GetContactById(Profile* profile,
                                        const std::string& contact_id) OVERRIDE;

 private:
  // Profile expected to be passed to ContactManagerInterface methods.
  // Passing any other profile will result in a crash.
  Profile* profile_;  // not owned

  // Observers registered for |profile_|.
  ObserverList<ContactManagerObserver> observers_;

  // Contacts that will be returned by GetAllContacts() and GetContactById().
  ScopedVector<Contact> contacts_;

  // Note: This should remain the last member so it'll be destroyed and
  // invalidate its weak pointers before any other members are destroyed.
  base::WeakPtrFactory<ContactManagerInterface> weak_ptr_factory_;

  DISALLOW_COPY_AND_ASSIGN(ContactManagerStub);
};

}  // namespace contacts

#endif  // CHROME_BROWSER_CHROMEOS_CONTACTS_CONTACT_MANAGER_STUB_H_