summaryrefslogtreecommitdiffstats
path: root/chrome/browser/chromeos/contacts/contact_manager_stub.cc
blob: 0ce8248a0ccc54bd2c99c4730715036f4de1fd3a (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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
// 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.

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

#include "base/logging.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/chromeos/contacts/contact.pb.h"
#include "chrome/browser/chromeos/contacts/contact_manager_observer.h"
#include "chrome/browser/chromeos/contacts/contact_test_util.h"
#include "chrome/browser/profiles/profile.h"
#include "content/public/browser/browser_thread.h"

using content::BrowserThread;

namespace contacts {

ContactManagerStub::ContactManagerStub(Profile* profile)
    : profile_(profile),
      weak_ptr_factory_(this) {
}

ContactManagerStub::~ContactManagerStub() {}

void ContactManagerStub::NotifyObserversAboutUpdatedContacts() {
  FOR_EACH_OBSERVER(ContactManagerObserver,
                    observers_,
                    OnContactsUpdated(profile_));
}

void ContactManagerStub::SetContacts(const ContactPointers& contacts) {
  test::CopyContacts(contacts, &contacts_);
}

base::WeakPtr<ContactManagerInterface> ContactManagerStub::GetWeakPtr() {
  CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
  return weak_ptr_factory_.GetWeakPtr();
}

void ContactManagerStub::AddObserver(ContactManagerObserver* observer,
                                     Profile* profile) {
  CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
  CHECK(observer);
  CHECK_EQ(profile, profile_);
  CHECK(!observers_.HasObserver(observer));
  observers_.AddObserver(observer);
}

void ContactManagerStub::RemoveObserver(ContactManagerObserver* observer,
                                        Profile* profile) {
  CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
  CHECK(observer);
  CHECK_EQ(profile, profile_);
  CHECK(observers_.HasObserver(observer));
  observers_.RemoveObserver(observer);
}

scoped_ptr<ContactPointers> ContactManagerStub::GetAllContacts(
    Profile* profile) {
  CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
  CHECK_EQ(profile, profile_);
  scoped_ptr<ContactPointers> contacts(new ContactPointers);
  for (size_t i = 0; i < contacts_.size(); ++i)
    contacts->push_back(contacts_[i]);
  return contacts.Pass();
}

const Contact* ContactManagerStub::GetContactById(
    Profile* profile,
    const std::string& contact_id) {
  CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
  CHECK_EQ(profile, profile_);
  for (size_t i = 0; i < contacts_.size(); ++i) {
    if (contacts_[i]->contact_id() == contact_id)
      return contacts_[i];
  }
  return NULL;
}

}  // namespace contacts