Index: chrome/browser/chromeos/contacts/fake_contact_store.cc |
diff --git a/chrome/browser/chromeos/contacts/fake_contact_store.cc b/chrome/browser/chromeos/contacts/fake_contact_store.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..e492d11e8cfd32d961402db411d5170092f0d5fa |
--- /dev/null |
+++ b/chrome/browser/chromeos/contacts/fake_contact_store.cc |
@@ -0,0 +1,104 @@ |
+// 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/fake_contact_store.h" |
+ |
+#include <utility> |
+ |
+#include "chrome/browser/chromeos/contacts/contact.pb.h" |
+#include "chrome/browser/chromeos/contacts/contact_store_observer.h" |
+#include "chrome/browser/profiles/profile.h" |
+#include "content/public/browser/browser_thread.h" |
+ |
+using content::BrowserThread; |
+ |
+namespace contacts { |
+ |
+FakeContactStore::FakeContactStore(FakeContactStoreFactory* factory) |
+ : factory_(factory), |
+ contacts_deleter_(&contacts_) { |
+} |
+ |
+FakeContactStore::~FakeContactStore() { |
+ factory_->OnFakeContactStoreDestroyed(this); |
+} |
+ |
+void FakeContactStore::SetContacts(const ContactPointers& contacts) { |
+ STLDeleteValues(&contacts_); |
+ contacts_.clear(); |
+ for (ContactPointers::const_iterator it = contacts.begin(); |
+ it != contacts.end(); ++it) { |
+ contacts_[(*it)->provider_id()] = new Contact(**it); |
+ } |
+} |
+ |
+void FakeContactStore::NotifyObserversAboutContactsUpdate() { |
+ FOR_EACH_OBSERVER(ContactStoreObserver, |
+ observers_, |
+ OnContactsUpdated(this)); |
+} |
+ |
+void FakeContactStore::Init() { |
+} |
+ |
+void FakeContactStore::AppendContacts(ContactPointers* contacts_out) { |
+ DCHECK(contacts_out); |
+ for (ContactMap::const_iterator it = contacts_.begin(); |
+ it != contacts_.end(); ++it) { |
+ if (!it->second->deleted()) |
+ contacts_out->push_back(it->second); |
+ } |
+} |
+ |
+const Contact* FakeContactStore::GetContactByProviderId( |
+ const std::string& provider_id) { |
+ ContactMap::const_iterator it = contacts_.find(provider_id); |
+ return (it != contacts_.end() && !it->second->deleted()) ? it->second : NULL; |
+} |
+ |
+void FakeContactStore::AddObserver(ContactStoreObserver* observer) { |
+ DCHECK(observer); |
+ observers_.AddObserver(observer); |
+} |
+ |
+void FakeContactStore::RemoveObserver(ContactStoreObserver* observer) { |
+ DCHECK(observer); |
+ observers_.RemoveObserver(observer); |
+} |
+ |
+FakeContactStoreFactory::FakeContactStoreFactory() { |
+} |
+ |
+FakeContactStoreFactory::~FakeContactStoreFactory() { |
+ CHECK(stores_.empty()); |
+} |
+ |
+FakeContactStore* FakeContactStoreFactory::GetContactStoreForProfile( |
+ Profile* profile) { |
+ CHECK(profile); |
+ return stores_[profile]; |
+} |
+ |
+void FakeContactStoreFactory::OnFakeContactStoreDestroyed( |
+ FakeContactStore* store) { |
+ CHECK(store); |
+ for (ProfileStoreMap::iterator it = stores_.begin(); |
+ it != stores_.end(); ++it) { |
+ if (it->second == store) { |
+ stores_.erase(it); |
+ return; |
+ } |
+ } |
+ NOTREACHED() << "No record of destroyed FakeContactStore " << store; |
+} |
+ |
+ContactStore* FakeContactStoreFactory::CreateContactStore(Profile* profile) { |
+ FakeContactStore* store = new FakeContactStore(this); |
+ CHECK(stores_.insert(std::make_pair(profile, store)).second) |
+ << "Got request to create second FakeContactStore for profile " |
+ << profile << " (" << profile->GetProfileName() << ")"; |
+ return store; |
+} |
+ |
+} // namespace contacts |