Revert 168224 - Update V8 to version 3.15.4.
[chromium-blink-merge.git] / chrome / browser / chromeos / contacts / fake_contact_store.cc
blob453391744684661180e049c364429286e7316911
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.
5 #include "chrome/browser/chromeos/contacts/fake_contact_store.h"
7 #include <utility>
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"
14 using content::BrowserThread;
16 namespace contacts {
18 FakeContactStore::FakeContactStore(FakeContactStoreFactory* factory)
19 : factory_(factory),
20 contacts_deleter_(&contacts_) {
23 FakeContactStore::~FakeContactStore() {
24 factory_->RemoveStore(this);
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)->contact_id()] = new Contact(**it);
36 void FakeContactStore::NotifyObserversAboutContactsUpdate() {
37 FOR_EACH_OBSERVER(ContactStoreObserver,
38 observers_,
39 OnContactsUpdated(this));
42 void FakeContactStore::Init() {
45 void FakeContactStore::AppendContacts(ContactPointers* contacts_out) {
46 CHECK(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);
54 const Contact* FakeContactStore::GetContactById(const std::string& contact_id) {
55 ContactMap::const_iterator it = contacts_.find(contact_id);
56 return (it != contacts_.end() && !it->second->deleted()) ? it->second : NULL;
59 void FakeContactStore::AddObserver(ContactStoreObserver* observer) {
60 CHECK(observer);
61 observers_.AddObserver(observer);
64 void FakeContactStore::RemoveObserver(ContactStoreObserver* observer) {
65 CHECK(observer);
66 observers_.RemoveObserver(observer);
69 FakeContactStoreFactory::FakeContactStoreFactory()
70 : permit_store_creation_(true) {
73 FakeContactStoreFactory::~FakeContactStoreFactory() {
74 CHECK(stores_.empty());
77 FakeContactStore* FakeContactStoreFactory::GetContactStoreForProfile(
78 Profile* profile) {
79 CHECK(profile);
80 ProfileStoreMap::const_iterator it = stores_.find(profile);
81 return it != stores_.end() ? it->second : NULL;
84 void FakeContactStoreFactory::RemoveStore(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;
93 NOTREACHED() << "No record of destroyed FakeContactStore " << store;
96 bool FakeContactStoreFactory::CanCreateContactStoreForProfile(
97 Profile* profile) {
98 CHECK(profile);
99 return permit_store_creation_;
102 ContactStore* FakeContactStoreFactory::CreateContactStore(Profile* profile) {
103 CHECK(profile);
104 CHECK(CanCreateContactStoreForProfile(profile));
105 FakeContactStore* store = new FakeContactStore(this);
106 CHECK(stores_.insert(std::make_pair(profile, store)).second)
107 << "Got request to create second FakeContactStore for profile "
108 << profile << " (" << profile->GetProfileName() << ")";
109 return store;
112 } // namespace contacts