Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(75)

Side by Side Diff: chrome/browser/chromeos/contacts/fake_contact_store.cc

Issue 10850033: contacts: Add ContactStoreFactory and FakeContactStore. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: add missing clear() call in FakeContactStore Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(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 #include "chrome/browser/chromeos/contacts/fake_contact_store.h"
6
7 #include <utility>
8
9 #include "chrome/browser/chromeos/contacts/contact.pb.h"
10 #include "chrome/browser/chromeos/contacts/contact_store_observer.h"
11 #include "chrome/browser/profiles/profile.h"
12 #include "content/public/browser/browser_thread.h"
13
14 using content::BrowserThread;
15
16 namespace contacts {
17
18 FakeContactStore::FakeContactStore(FakeContactStoreFactory* factory)
19 : factory_(factory),
20 contacts_deleter_(&contacts_) {
21 }
22
23 FakeContactStore::~FakeContactStore() {
24 factory_->OnFakeContactStoreDestroyed(this);
25 }
26
27 void FakeContactStore::SetContacts(const ContactPointers& contacts) {
28 STLDeleteValues(&contacts_);
29 contacts_.clear();
30 for (ContactPointers::const_iterator it = contacts.begin();
31 it != contacts.end(); ++it) {
32 contacts_[(*it)->provider_id()] = new Contact(**it);
33 }
34 }
35
36 void FakeContactStore::NotifyObserversAboutContactsUpdate() {
37 FOR_EACH_OBSERVER(ContactStoreObserver,
38 observers_,
39 OnContactsUpdated(this));
40 }
41
42 void FakeContactStore::Init() {
43 }
44
45 void FakeContactStore::AppendContacts(ContactPointers* contacts_out) {
46 DCHECK(contacts_out);
47 for (ContactMap::const_iterator it = contacts_.begin();
48 it != contacts_.end(); ++it) {
49 if (!it->second->deleted())
50 contacts_out->push_back(it->second);
51 }
52 }
53
54 const Contact* FakeContactStore::GetContactByProviderId(
55 const std::string& provider_id) {
56 ContactMap::const_iterator it = contacts_.find(provider_id);
57 return (it != contacts_.end() && !it->second->deleted()) ? it->second : NULL;
58 }
59
60 void FakeContactStore::AddObserver(ContactStoreObserver* observer) {
61 DCHECK(observer);
62 observers_.AddObserver(observer);
63 }
64
65 void FakeContactStore::RemoveObserver(ContactStoreObserver* observer) {
66 DCHECK(observer);
67 observers_.RemoveObserver(observer);
68 }
69
70 FakeContactStoreFactory::FakeContactStoreFactory() {
71 }
72
73 FakeContactStoreFactory::~FakeContactStoreFactory() {
74 CHECK(stores_.empty());
75 }
76
77 FakeContactStore* FakeContactStoreFactory::GetContactStoreForProfile(
78 Profile* profile) {
79 CHECK(profile);
80 return stores_[profile];
81 }
82
83 void FakeContactStoreFactory::OnFakeContactStoreDestroyed(
84 FakeContactStore* store) {
85 CHECK(store);
86 for (ProfileStoreMap::iterator it = stores_.begin();
87 it != stores_.end(); ++it) {
88 if (it->second == store) {
89 stores_.erase(it);
90 return;
91 }
92 }
93 NOTREACHED() << "No record of destroyed FakeContactStore " << store;
94 }
95
96 ContactStore* FakeContactStoreFactory::CreateContactStore(Profile* profile) {
97 FakeContactStore* store = new FakeContactStore(this);
98 CHECK(stores_.insert(std::make_pair(profile, store)).second)
99 << "Got request to create second FakeContactStore for profile "
100 << profile << " (" << profile->GetProfileName() << ")";
101 return store;
102 }
103
104 } // namespace contacts
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698