| Index: chrome/browser/chromeos/contacts/google_contact_store.cc
|
| diff --git a/chrome/browser/chromeos/contacts/google_contact_store.cc b/chrome/browser/chromeos/contacts/google_contact_store.cc
|
| index a0ff97aef5bd7658100615d02759f26aa1de769c..ac4b41a89e3e46e189952a07496599e6491f83a8 100644
|
| --- a/chrome/browser/chromeos/contacts/google_contact_store.cc
|
| +++ b/chrome/browser/chromeos/contacts/google_contact_store.cc
|
| @@ -81,6 +81,15 @@ void GoogleContactStore::TestAPI::NotifyAboutNetworkStateChange(bool online) {
|
| store_->OnConnectionTypeChanged(type);
|
| }
|
|
|
| +scoped_ptr<ContactPointers> GoogleContactStore::TestAPI::GetLoadedContacts() {
|
| + scoped_ptr<ContactPointers> contacts(new ContactPointers);
|
| + for (ContactMap::const_iterator it = store_->contacts_.begin();
|
| + it != store_->contacts_.end(); ++it) {
|
| + contacts->push_back(it->second);
|
| + }
|
| + return contacts.Pass();
|
| +}
|
| +
|
| GoogleContactStore::GoogleContactStore(Profile* profile)
|
| : profile_(profile),
|
| db_(new ContactDatabase),
|
| @@ -131,8 +140,7 @@ void GoogleContactStore::AppendContacts(ContactPointers* contacts_out) {
|
| const Contact* GoogleContactStore::GetContactById(
|
| const std::string& contact_id) {
|
| DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
|
| - const Contact* contact = contacts_.Find(contact_id);
|
| - return (contact && !contact->deleted()) ? contact : NULL;
|
| + return contacts_.Find(contact_id);
|
| }
|
|
|
| void GoogleContactStore::AddObserver(ContactStoreObserver* observer) {
|
| @@ -240,17 +248,26 @@ void GoogleContactStore::MergeContacts(
|
| bool is_full_update,
|
| scoped_ptr<ScopedVector<Contact> > updated_contacts) {
|
| DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
|
| - if (is_full_update)
|
| +
|
| + if (is_full_update) {
|
| contacts_.Clear();
|
| - size_t num_updated_contacts = updated_contacts->size();
|
| - contacts_.Merge(updated_contacts.Pass(), ContactMap::KEEP_DELETED_CONTACTS);
|
| + last_contact_update_time_ = base::Time();
|
| + }
|
|
|
| - if (is_full_update || num_updated_contacts > 0)
|
| - last_contact_update_time_ = contacts_.GetMaxUpdateTime();
|
| + // Find the maximum update time from |updated_contacts| since contacts whose
|
| + // |deleted| flags are set won't be saved to |contacts_|.
|
| + for (ScopedVector<Contact>::iterator it = updated_contacts->begin();
|
| + it != updated_contacts->end(); ++it) {
|
| + last_contact_update_time_ =
|
| + std::max(last_contact_update_time_,
|
| + base::Time::FromInternalValue((*it)->update_time()));
|
| + }
|
| VLOG(1) << "Last contact update time is "
|
| << (last_contact_update_time_.is_null() ?
|
| std::string("null") :
|
| gdata::util::FormatTimeAsString(last_contact_update_time_));
|
| +
|
| + contacts_.Merge(updated_contacts.Pass(), ContactMap::DROP_DELETED_CONTACTS);
|
| }
|
|
|
| void GoogleContactStore::OnDownloadSuccess(
|
| @@ -263,9 +280,16 @@ void GoogleContactStore::OnDownloadSuccess(
|
|
|
| // Copy the pointers so we can update just these contacts in the database.
|
| scoped_ptr<ContactPointers> contacts_to_save_to_db(new ContactPointers);
|
| + scoped_ptr<ContactDatabaseInterface::ContactIds>
|
| + contact_ids_to_delete_from_db(new ContactDatabaseInterface::ContactIds);
|
| if (db_) {
|
| - for (size_t i = 0; i < updated_contacts->size(); ++i)
|
| - contacts_to_save_to_db->push_back((*updated_contacts)[i]);
|
| + for (size_t i = 0; i < updated_contacts->size(); ++i) {
|
| + Contact* contact = (*updated_contacts)[i];
|
| + if (contact->deleted())
|
| + contact_ids_to_delete_from_db->push_back(contact->contact_id());
|
| + else
|
| + contacts_to_save_to_db->push_back(contact);
|
| + }
|
| }
|
| bool got_updates = !updated_contacts->empty();
|
|
|
| @@ -283,12 +307,17 @@ void GoogleContactStore::OnDownloadSuccess(
|
| // contacts, we still want to write updated metadata containing
|
| // |update_start_time|.
|
| VLOG(1) << "Saving " << contacts_to_save_to_db->size() << " contact(s) to "
|
| - << "database as " << (is_full_update ? "full" : "incremental")
|
| - << " update";
|
| + << "database and deleting " << contact_ids_to_delete_from_db->size()
|
| + << " as " << (is_full_update ? "full" : "incremental") << " update";
|
| +
|
| scoped_ptr<UpdateMetadata> metadata(new UpdateMetadata);
|
| metadata->set_last_update_start_time(update_start_time.ToInternalValue());
|
| + metadata->set_last_contact_update_time(
|
| + last_contact_update_time_.ToInternalValue());
|
| +
|
| db_->SaveContacts(
|
| contacts_to_save_to_db.Pass(),
|
| + contact_ids_to_delete_from_db.Pass(),
|
| metadata.Pass(),
|
| is_full_update,
|
| base::Bind(&GoogleContactStore::OnDatabaseContactsSaved,
|
| @@ -335,6 +364,9 @@ void GoogleContactStore::OnDatabaseContactsLoaded(
|
| MergeContacts(true, contacts.Pass());
|
| last_successful_update_start_time_ =
|
| base::Time::FromInternalValue(metadata->last_update_start_time());
|
| + last_contact_update_time_ = std::max(
|
| + last_contact_update_time_,
|
| + base::Time::FromInternalValue(metadata->last_contact_update_time()));
|
|
|
| if (!contacts_.empty()) {
|
| FOR_EACH_OBSERVER(ContactStoreObserver,
|
|
|