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

Side by Side Diff: chrome/browser/chromeos/gdata/gdata_contacts_service.cc

Issue 10837044: Correct const accessors in base/values.(h|cc), Part II (ListValue) (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: David's comments 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 unified diff | Download patch
OLDNEW
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/gdata/gdata_contacts_service.h" 5 #include "chrome/browser/chromeos/gdata/gdata_contacts_service.h"
6 6
7 #include <cstring> 7 #include <cstring>
8 #include <string> 8 #include <string>
9 #include <map> 9 #include <map>
10 #include <utility> 10 #include <utility>
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
173 } 173 }
174 174
175 // Gets the photo URL from a contact's dictionary (within the "entry" list). 175 // Gets the photo URL from a contact's dictionary (within the "entry" list).
176 // Returns an empty string if no photo was found. 176 // Returns an empty string if no photo was found.
177 std::string GetPhotoUrl(const DictionaryValue& dict) { 177 std::string GetPhotoUrl(const DictionaryValue& dict) {
178 const ListValue* link_list = NULL; 178 const ListValue* link_list = NULL;
179 if (!dict.GetList(kLinkField, &link_list)) 179 if (!dict.GetList(kLinkField, &link_list))
180 return std::string(); 180 return std::string();
181 181
182 for (size_t i = 0; i < link_list->GetSize(); ++i) { 182 for (size_t i = 0; i < link_list->GetSize(); ++i) {
183 DictionaryValue* link_dict = NULL; 183 const DictionaryValue* link_dict = NULL;
184 if (!link_list->GetDictionary(i, &link_dict)) 184 if (!link_list->GetDictionary(i, &link_dict))
185 continue; 185 continue;
186 186
187 std::string rel; 187 std::string rel;
188 if (!link_dict->GetString(kLinkRelField, &rel)) 188 if (!link_dict->GetString(kLinkRelField, &rel))
189 continue; 189 continue;
190 if (rel != kLinkRelPhotoValue) 190 if (rel != kLinkRelPhotoValue)
191 continue; 191 continue;
192 192
193 // From https://goo.gl/7T6Od: "If a contact does not have a photo, then the 193 // From https://goo.gl/7T6Od: "If a contact does not have a photo, then the
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
230 dict.GetString(kFullNameField, contact->mutable_full_name()); 230 dict.GetString(kFullNameField, contact->mutable_full_name());
231 dict.GetString(kGivenNameField, contact->mutable_given_name()); 231 dict.GetString(kGivenNameField, contact->mutable_given_name());
232 dict.GetString(kAdditionalNameField, contact->mutable_additional_name()); 232 dict.GetString(kAdditionalNameField, contact->mutable_additional_name());
233 dict.GetString(kFamilyNameField, contact->mutable_family_name()); 233 dict.GetString(kFamilyNameField, contact->mutable_family_name());
234 dict.GetString(kNamePrefixField, contact->mutable_name_prefix()); 234 dict.GetString(kNamePrefixField, contact->mutable_name_prefix());
235 dict.GetString(kNameSuffixField, contact->mutable_name_suffix()); 235 dict.GetString(kNameSuffixField, contact->mutable_name_suffix());
236 236
237 const ListValue* email_list = NULL; 237 const ListValue* email_list = NULL;
238 if (dict.GetList(kEmailField, &email_list)) { 238 if (dict.GetList(kEmailField, &email_list)) {
239 for (size_t i = 0; i < email_list->GetSize(); ++i) { 239 for (size_t i = 0; i < email_list->GetSize(); ++i) {
240 DictionaryValue* email_dict = NULL; 240 const DictionaryValue* email_dict = NULL;
241 if (!email_list->GetDictionary(i, &email_dict)) 241 if (!email_list->GetDictionary(i, &email_dict))
242 return false; 242 return false;
243 243
244 contacts::Contact_EmailAddress* email = contact->add_email_addresses(); 244 contacts::Contact_EmailAddress* email = contact->add_email_addresses();
245 if (!email_dict->GetString(kEmailAddressField, email->mutable_address())) 245 if (!email_dict->GetString(kEmailAddressField, email->mutable_address()))
246 return false; 246 return false;
247 email->set_primary(IsAddressPrimary(*email_dict)); 247 email->set_primary(IsAddressPrimary(*email_dict));
248 InitAddressType(*email_dict, email->mutable_type()); 248 InitAddressType(*email_dict, email->mutable_type());
249 } 249 }
250 } 250 }
251 251
252 const ListValue* phone_list = NULL; 252 const ListValue* phone_list = NULL;
253 if (dict.GetList(kPhoneField, &phone_list)) { 253 if (dict.GetList(kPhoneField, &phone_list)) {
254 for (size_t i = 0; i < phone_list->GetSize(); ++i) { 254 for (size_t i = 0; i < phone_list->GetSize(); ++i) {
255 DictionaryValue* phone_dict = NULL; 255 const DictionaryValue* phone_dict = NULL;
256 if (!phone_list->GetDictionary(i, &phone_dict)) 256 if (!phone_list->GetDictionary(i, &phone_dict))
257 return false; 257 return false;
258 258
259 contacts::Contact_PhoneNumber* phone = contact->add_phone_numbers(); 259 contacts::Contact_PhoneNumber* phone = contact->add_phone_numbers();
260 if (!phone_dict->GetString(kPhoneNumberField, phone->mutable_number())) 260 if (!phone_dict->GetString(kPhoneNumberField, phone->mutable_number()))
261 return false; 261 return false;
262 phone->set_primary(IsAddressPrimary(*phone_dict)); 262 phone->set_primary(IsAddressPrimary(*phone_dict));
263 InitAddressType(*phone_dict, phone->mutable_type()); 263 InitAddressType(*phone_dict, phone->mutable_type());
264 } 264 }
265 } 265 }
266 266
267 const ListValue* address_list = NULL; 267 const ListValue* address_list = NULL;
268 if (dict.GetList(kPostalAddressField, &address_list)) { 268 if (dict.GetList(kPostalAddressField, &address_list)) {
269 for (size_t i = 0; i < address_list->GetSize(); ++i) { 269 for (size_t i = 0; i < address_list->GetSize(); ++i) {
270 DictionaryValue* address_dict = NULL; 270 const DictionaryValue* address_dict = NULL;
271 if (!address_list->GetDictionary(i, &address_dict)) 271 if (!address_list->GetDictionary(i, &address_dict))
272 return false; 272 return false;
273 273
274 contacts::Contact_PostalAddress* address = 274 contacts::Contact_PostalAddress* address =
275 contact->add_postal_addresses(); 275 contact->add_postal_addresses();
276 if (!address_dict->GetString(kPostalAddressFormattedField, 276 if (!address_dict->GetString(kPostalAddressFormattedField,
277 address->mutable_address())) { 277 address->mutable_address())) {
278 return false; 278 return false;
279 } 279 }
280 address->set_primary(IsAddressPrimary(*address_dict)); 280 address->set_primary(IsAddressPrimary(*address_dict));
281 InitAddressType(*address_dict, address->mutable_type()); 281 InitAddressType(*address_dict, address->mutable_type());
282 } 282 }
283 } 283 }
284 284
285 const ListValue* im_list = NULL; 285 const ListValue* im_list = NULL;
286 if (dict.GetList(kInstantMessagingField, &im_list)) { 286 if (dict.GetList(kInstantMessagingField, &im_list)) {
287 for (size_t i = 0; i < im_list->GetSize(); ++i) { 287 for (size_t i = 0; i < im_list->GetSize(); ++i) {
288 DictionaryValue* im_dict = NULL; 288 const DictionaryValue* im_dict = NULL;
289 if (!im_list->GetDictionary(i, &im_dict)) 289 if (!im_list->GetDictionary(i, &im_dict))
290 return false; 290 return false;
291 291
292 contacts::Contact_InstantMessagingAddress* im = 292 contacts::Contact_InstantMessagingAddress* im =
293 contact->add_instant_messaging_addresses(); 293 contact->add_instant_messaging_addresses();
294 if (!im_dict->GetString(kInstantMessagingAddressField, 294 if (!im_dict->GetString(kInstantMessagingAddressField,
295 im->mutable_address())) { 295 im->mutable_address())) {
296 return false; 296 return false;
297 } 297 }
298 im->set_primary(IsAddressPrimary(*im_dict)); 298 im->set_primary(IsAddressPrimary(*im_dict));
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
397 LOG(WARNING) << "Feed dictionary missing"; 397 LOG(WARNING) << "Feed dictionary missing";
398 return false; 398 return false;
399 } 399 }
400 400
401 // Check the category field to confirm that this is actually a contact feed. 401 // Check the category field to confirm that this is actually a contact feed.
402 const ListValue* category_list = NULL; 402 const ListValue* category_list = NULL;
403 if (!feed_dict->GetList(kCategoryField, &category_list)) { 403 if (!feed_dict->GetList(kCategoryField, &category_list)) {
404 LOG(WARNING) << "Category list missing"; 404 LOG(WARNING) << "Category list missing";
405 return false; 405 return false;
406 } 406 }
407 DictionaryValue* category_dict = NULL; 407 const DictionaryValue* category_dict = NULL;
408 if (!category_list->GetSize() == 1 || 408 if (!category_list->GetSize() == 1 ||
409 !category_list->GetDictionary(0, &category_dict)) { 409 !category_list->GetDictionary(0, &category_dict)) {
410 LOG(WARNING) << "Unable to get dictionary from category list of size " 410 LOG(WARNING) << "Unable to get dictionary from category list of size "
411 << category_list->GetSize(); 411 << category_list->GetSize();
412 return false; 412 return false;
413 } 413 }
414 std::string category_scheme, category_term; 414 std::string category_scheme, category_term;
415 if (!category_dict->GetString(kCategorySchemeField, &category_scheme) || 415 if (!category_dict->GetString(kCategorySchemeField, &category_scheme) ||
416 !category_dict->GetString(kCategoryTermField, &category_term) || 416 !category_dict->GetString(kCategoryTermField, &category_term) ||
417 category_scheme != kCategorySchemeValue || 417 category_scheme != kCategorySchemeValue ||
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after
604 604
605 void GDataContactsService::OnRequestComplete(DownloadContactsRequest* request) { 605 void GDataContactsService::OnRequestComplete(DownloadContactsRequest* request) {
606 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 606 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
607 DCHECK(request); 607 DCHECK(request);
608 VLOG(1) << "Download request " << request << " complete"; 608 VLOG(1) << "Download request " << request << " complete";
609 requests_.erase(request); 609 requests_.erase(request);
610 delete request; 610 delete request;
611 } 611 }
612 612
613 } // namespace contacts 613 } // namespace contacts
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/cros/sms_watcher.cc ('k') | chrome/browser/custom_handlers/protocol_handler_registry.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698