OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/chromeos/contacts/google_contact_store.h" | 5 #include "chrome/browser/chromeos/contacts/google_contact_store.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/file_path.h" | 10 #include "base/file_path.h" |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
116 void GoogleContactStore::AppendContacts(ContactPointers* contacts_out) { | 116 void GoogleContactStore::AppendContacts(ContactPointers* contacts_out) { |
117 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 117 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
118 DCHECK(contacts_out); | 118 DCHECK(contacts_out); |
119 for (ContactMap::const_iterator it = contacts_.begin(); | 119 for (ContactMap::const_iterator it = contacts_.begin(); |
120 it != contacts_.end(); ++it) { | 120 it != contacts_.end(); ++it) { |
121 if (!it->second->deleted()) | 121 if (!it->second->deleted()) |
122 contacts_out->push_back(it->second); | 122 contacts_out->push_back(it->second); |
123 } | 123 } |
124 } | 124 } |
125 | 125 |
126 const Contact* GoogleContactStore::GetContactByProviderId( | 126 const Contact* GoogleContactStore::GetContactById( |
127 const std::string& provider_id) { | 127 const std::string& contact_id) { |
128 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 128 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
129 ContactMap::const_iterator it = contacts_.find(provider_id); | 129 ContactMap::const_iterator it = contacts_.find(contact_id); |
130 return (it != contacts_.end() && !it->second->deleted()) ? it->second : NULL; | 130 return (it != contacts_.end() && !it->second->deleted()) ? it->second : NULL; |
131 } | 131 } |
132 | 132 |
133 void GoogleContactStore::AddObserver(ContactStoreObserver* observer) { | 133 void GoogleContactStore::AddObserver(ContactStoreObserver* observer) { |
134 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 134 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
135 DCHECK(observer); | 135 DCHECK(observer); |
136 observers_.AddObserver(observer); | 136 observers_.AddObserver(observer); |
137 } | 137 } |
138 | 138 |
139 void GoogleContactStore::RemoveObserver(ContactStoreObserver* observer) { | 139 void GoogleContactStore::RemoveObserver(ContactStoreObserver* observer) { |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
242 scoped_ptr<ScopedVector<Contact> > updated_contacts) { | 242 scoped_ptr<ScopedVector<Contact> > updated_contacts) { |
243 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 243 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
244 if (is_full_update) { | 244 if (is_full_update) { |
245 STLDeleteValues(&contacts_); | 245 STLDeleteValues(&contacts_); |
246 contacts_.clear(); | 246 contacts_.clear(); |
247 } | 247 } |
248 | 248 |
249 for (ScopedVector<Contact>::iterator it = updated_contacts->begin(); | 249 for (ScopedVector<Contact>::iterator it = updated_contacts->begin(); |
250 it != updated_contacts->end(); ++it) { | 250 it != updated_contacts->end(); ++it) { |
251 Contact* contact = *it; | 251 Contact* contact = *it; |
252 VLOG(1) << "Updating " << contact->provider_id(); | 252 VLOG(1) << "Updating " << contact->contact_id(); |
253 ContactMap::iterator map_it = contacts_.find(contact->provider_id()); | 253 ContactMap::iterator map_it = contacts_.find(contact->contact_id()); |
254 if (map_it == contacts_.end()) { | 254 if (map_it == contacts_.end()) { |
255 contacts_[contact->provider_id()] = contact; | 255 contacts_[contact->contact_id()] = contact; |
256 } else { | 256 } else { |
257 delete map_it->second; | 257 delete map_it->second; |
258 map_it->second = contact; | 258 map_it->second = contact; |
259 } | 259 } |
260 } | 260 } |
261 | 261 |
262 // Make sure that the Contact objects won't be destroyed when | 262 // Make sure that the Contact objects won't be destroyed when |
263 // |updated_contacts| is destroyed. | 263 // |updated_contacts| is destroyed. |
264 size_t num_updated_contacts = updated_contacts->size(); | 264 size_t num_updated_contacts = updated_contacts->size(); |
265 updated_contacts->weak_clear(); | 265 updated_contacts->weak_clear(); |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
400 return gdata::util::IsGDataAvailable(profile); | 400 return gdata::util::IsGDataAvailable(profile); |
401 } | 401 } |
402 | 402 |
403 ContactStore* GoogleContactStoreFactory::CreateContactStore(Profile* profile) { | 403 ContactStore* GoogleContactStoreFactory::CreateContactStore(Profile* profile) { |
404 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 404 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
405 DCHECK(CanCreateContactStoreForProfile(profile)); | 405 DCHECK(CanCreateContactStoreForProfile(profile)); |
406 return new GoogleContactStore(profile); | 406 return new GoogleContactStore(profile); |
407 } | 407 } |
408 | 408 |
409 } // namespace contacts | 409 } // namespace contacts |
OLD | NEW |