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

Unified 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: fix GoogleContactStore db-saving bug and FakeContactDatabase partial-update bug and apply review fe… 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 side-by-side diff with in-line comments
Download patch
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..f61f6bd9a2428288218744d71d6f01bd77cd1fb2
--- /dev/null
+++ b/chrome/browser/chromeos/contacts/fake_contact_store.cc
@@ -0,0 +1,112 @@
+// 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_->RemoveStore(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) {
+ CHECK(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) {
+ CHECK(observer);
+ observers_.AddObserver(observer);
+}
+
+void FakeContactStore::RemoveObserver(ContactStoreObserver* observer) {
+ CHECK(observer);
+ observers_.RemoveObserver(observer);
+}
+
+FakeContactStoreFactory::FakeContactStoreFactory()
+ : permit_store_creation_(true) {
+}
+
+FakeContactStoreFactory::~FakeContactStoreFactory() {
+ CHECK(stores_.empty());
+}
+
+FakeContactStore* FakeContactStoreFactory::GetContactStoreForProfile(
+ Profile* profile) {
+ CHECK(profile);
+ return stores_[profile];
+}
+
+void FakeContactStoreFactory::RemoveStore(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;
+}
+
+bool FakeContactStoreFactory::CanCreateContactStoreForProfile(
+ Profile* profile) {
+ CHECK(profile);
+ return permit_store_creation_;
+}
+
+ContactStore* FakeContactStoreFactory::CreateContactStore(Profile* profile) {
+ CHECK(profile);
+ CHECK(CanCreateContactStoreForProfile(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

Powered by Google App Engine
This is Rietveld 408576698