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

Unified Diff: chrome/browser/chromeos/contacts/fake_contact_database.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_database.cc
diff --git a/chrome/browser/chromeos/contacts/fake_contact_database.cc b/chrome/browser/chromeos/contacts/fake_contact_database.cc
index 1dab542658e58cab2541f1ea246de20b79bdf83a..a6e8b52d8db3913d1579d6b72d2b67efaee77c80 100644
--- a/chrome/browser/chromeos/contacts/fake_contact_database.cc
+++ b/chrome/browser/chromeos/contacts/fake_contact_database.cc
@@ -15,7 +15,8 @@ namespace contacts {
FakeContactDatabase::FakeContactDatabase()
: init_success_(true),
save_success_(true),
- load_success_(true) {
+ load_success_(true),
+ num_saved_contacts_(0) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
}
@@ -42,7 +43,11 @@ void FakeContactDatabase::SaveContacts(scoped_ptr<ContactPointers> contacts,
SaveCallback callback) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
if (save_success_) {
- test::CopyContacts(*contacts, &contacts_);
Daniel Erat 2012/08/03 20:00:23 This bug was hidden by the bug in GoogleContactSto
+ num_saved_contacts_ += contacts->size();
+ if (is_full_update)
+ test::CopyContacts(*contacts, &contacts_);
+ else
+ MergeContacts(*contacts);
metadata_ = *metadata;
}
callback.Run(save_success_);
@@ -62,4 +67,24 @@ void FakeContactDatabase::LoadContacts(LoadCallback callback) {
FakeContactDatabase::~FakeContactDatabase() {
}
+void FakeContactDatabase::MergeContacts(
+ const ContactPointers& updated_contacts) {
+ for (ContactPointers::const_iterator updated_it = updated_contacts.begin();
+ updated_it != updated_contacts.end(); ++updated_it) {
+ const Contact& updated_contact = **updated_it;
+ bool found = false;
+ for (ScopedVector<Contact>::const_iterator existing_it = contacts_.begin();
Daniel Erat 2012/08/03 20:00:23 This is ugly and inefficient, but I'm not sure how
satorux1 2012/08/03 20:08:14 Shouldn't matter for tests
+ existing_it != contacts_.end(); ++existing_it) {
+ Contact* existing_contact = *existing_it;
+ if (existing_contact->provider_id() == updated_contact.provider_id()) {
+ *existing_contact = updated_contact;
+ found = true;
+ break;
+ }
+ }
+ if (!found)
+ contacts_.push_back(new Contact(updated_contact));
+ }
+}
+
} // namespace contacts

Powered by Google App Engine
This is Rietveld 408576698