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

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

Issue 10827406: contacts: Rename provider_id to contact_id. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: merge 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 | Annotate | Revision Log
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 212 matching lines...) Expand 10 before | Expand all | Expand 10 after
223 } 223 }
224 return std::string(); 224 return std::string();
225 } 225 }
226 226
227 // Fills a Contact's fields using an entry from a GData feed. 227 // Fills a Contact's fields using an entry from a GData feed.
228 bool FillContactFromDictionary(const base::DictionaryValue& dict, 228 bool FillContactFromDictionary(const base::DictionaryValue& dict,
229 contacts::Contact* contact) { 229 contacts::Contact* contact) {
230 DCHECK(contact); 230 DCHECK(contact);
231 contact->Clear(); 231 contact->Clear();
232 232
233 if (!dict.GetString(kIdField, contact->mutable_provider_id())) 233 if (!dict.GetString(kIdField, contact->mutable_contact_id()))
234 return false; 234 return false;
235 235
236 std::string updated; 236 std::string updated;
237 if (dict.GetString(kUpdatedField, &updated)) { 237 if (dict.GetString(kUpdatedField, &updated)) {
238 base::Time update_time; 238 base::Time update_time;
239 if (!util::GetTimeFromString(updated, &update_time)) { 239 if (!util::GetTimeFromString(updated, &update_time)) {
240 LOG(WARNING) << "Unable to parse time \"" << updated << "\""; 240 LOG(WARNING) << "Unable to parse time \"" << updated << "\"";
241 return false; 241 return false;
242 } 242 }
243 contact->set_update_time(update_time.ToInternalValue()); 243 contact->set_update_time(update_time.ToInternalValue());
(...skipping 338 matching lines...) Expand 10 before | Expand all | Expand 10 after
582 return false; 582 return false;
583 } 583 }
584 584
585 scoped_ptr<contacts::Contact> contact(new contacts::Contact); 585 scoped_ptr<contacts::Contact> contact(new contacts::Contact);
586 if (!FillContactFromDictionary(*contact_dict, contact.get())) { 586 if (!FillContactFromDictionary(*contact_dict, contact.get())) {
587 LOG(WARNING) << "Unable to fill entry " << index; 587 LOG(WARNING) << "Unable to fill entry " << index;
588 return false; 588 return false;
589 } 589 }
590 590
591 VLOG(1) << "Got contact " << index << ":" 591 VLOG(1) << "Got contact " << index << ":"
592 << " id=" << contact->provider_id() 592 << " id=" << contact->contact_id()
593 << " full_name=\"" << contact->full_name() << "\"" 593 << " full_name=\"" << contact->full_name() << "\""
594 << " update_time=" << contact->update_time(); 594 << " update_time=" << contact->update_time();
595 595
596 std::string photo_url = GetPhotoUrl(*contact_dict); 596 std::string photo_url = GetPhotoUrl(*contact_dict);
597 if (!photo_url.empty()) { 597 if (!photo_url.empty()) {
598 if (!service_->rewrite_photo_url_callback_for_testing_.is_null()) { 598 if (!service_->rewrite_photo_url_callback_for_testing_.is_null()) {
599 photo_url = 599 photo_url =
600 service_->rewrite_photo_url_callback_for_testing_.Run(photo_url); 600 service_->rewrite_photo_url_callback_for_testing_.Run(photo_url);
601 } 601 }
602 contact_photo_urls_[contact.get()] = photo_url; 602 contact_photo_urls_[contact.get()] = photo_url;
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
634 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 634 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
635 while (!contacts_needing_photo_downloads_.empty() && 635 while (!contacts_needing_photo_downloads_.empty() &&
636 (num_in_progress_photo_downloads_ < 636 (num_in_progress_photo_downloads_ <
637 service_->max_photo_downloads_per_second_)) { 637 service_->max_photo_downloads_per_second_)) {
638 contacts::Contact* contact = contacts_needing_photo_downloads_.back(); 638 contacts::Contact* contact = contacts_needing_photo_downloads_.back();
639 contacts_needing_photo_downloads_.pop_back(); 639 contacts_needing_photo_downloads_.pop_back();
640 DCHECK(contact_photo_urls_.count(contact)); 640 DCHECK(contact_photo_urls_.count(contact));
641 std::string url = contact_photo_urls_[contact]; 641 std::string url = contact_photo_urls_[contact];
642 642
643 VLOG(1) << "Starting download of photo " << url << " for " 643 VLOG(1) << "Starting download of photo " << url << " for "
644 << contact->provider_id(); 644 << contact->contact_id();
645 runner_->StartOperationWithRetry( 645 runner_->StartOperationWithRetry(
646 new GetContactPhotoOperation( 646 new GetContactPhotoOperation(
647 runner_->operation_registry(), 647 runner_->operation_registry(),
648 GURL(url), 648 GURL(url),
649 base::Bind(&DownloadContactsRequest::HandlePhotoData, 649 base::Bind(&DownloadContactsRequest::HandlePhotoData,
650 weak_ptr_factory_.GetWeakPtr(), 650 weak_ptr_factory_.GetWeakPtr(),
651 contact))); 651 contact)));
652 num_in_progress_photo_downloads_++; 652 num_in_progress_photo_downloads_++;
653 } 653 }
654 } 654 }
655 655
656 // Callback for GetContactPhotoOperation calls. Updates the associated 656 // Callback for GetContactPhotoOperation calls. Updates the associated
657 // Contact and checks for completion. 657 // Contact and checks for completion.
658 void HandlePhotoData(contacts::Contact* contact, 658 void HandlePhotoData(contacts::Contact* contact,
659 GDataErrorCode error, 659 GDataErrorCode error,
660 scoped_ptr<std::string> download_data) { 660 scoped_ptr<std::string> download_data) {
661 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 661 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
662 VLOG(1) << "Got photo data for " << contact->provider_id() 662 VLOG(1) << "Got photo data for " << contact->contact_id()
663 << " (error=" << error << " size=" << download_data->size() << ")"; 663 << " (error=" << error << " size=" << download_data->size() << ")";
664 num_in_progress_photo_downloads_--; 664 num_in_progress_photo_downloads_--;
665 665
666 if (error == HTTP_INTERNAL_SERVER_ERROR || 666 if (error == HTTP_INTERNAL_SERVER_ERROR ||
667 error == HTTP_SERVICE_UNAVAILABLE) { 667 error == HTTP_SERVICE_UNAVAILABLE) {
668 int num_errors = ++transient_photo_download_errors_per_contact_[contact]; 668 int num_errors = ++transient_photo_download_errors_per_contact_[contact];
669 if (num_errors <= kMaxTransientPhotoDownloadErrorsPerContact) { 669 if (num_errors <= kMaxTransientPhotoDownloadErrorsPerContact) {
670 LOG(WARNING) << "Got error " << error << " while downloading photo " 670 LOG(WARNING) << "Got error " << error << " while downloading photo "
671 << "for " << contact->provider_id() << "; retrying"; 671 << "for " << contact->contact_id() << "; retrying";
672 contacts_needing_photo_downloads_.push_back(contact); 672 contacts_needing_photo_downloads_.push_back(contact);
673 return; 673 return;
674 } 674 }
675 } 675 }
676 676
677 if (error == HTTP_NOT_FOUND) { 677 if (error == HTTP_NOT_FOUND) {
678 LOG(WARNING) << "Got error " << error << " while downloading photo " 678 LOG(WARNING) << "Got error " << error << " while downloading photo "
679 << "for " << contact->provider_id() << "; skipping"; 679 << "for " << contact->contact_id() << "; skipping";
680 CheckCompletion(); 680 CheckCompletion();
681 return; 681 return;
682 } 682 }
683 683
684 if (error != HTTP_SUCCESS) { 684 if (error != HTTP_SUCCESS) {
685 LOG(WARNING) << "Got error " << error << " while downloading photo " 685 LOG(WARNING) << "Got error " << error << " while downloading photo "
686 << "for " << contact->provider_id() << "; giving up"; 686 << "for " << contact->contact_id() << "; giving up";
687 photo_download_failed_ = true; 687 photo_download_failed_ = true;
688 // Make sure we don't start any more downloads. 688 // Make sure we don't start any more downloads.
689 contacts_needing_photo_downloads_.clear(); 689 contacts_needing_photo_downloads_.clear();
690 CheckCompletion(); 690 CheckCompletion();
691 return; 691 return;
692 } 692 }
693 693
694 contact->set_raw_untrusted_photo(*download_data); 694 contact->set_raw_untrusted_photo(*download_data);
695 CheckCompletion(); 695 CheckCompletion();
696 } 696 }
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
782 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 782 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
783 DCHECK(request); 783 DCHECK(request);
784 VLOG(1) << "Download request " << request << " complete"; 784 VLOG(1) << "Download request " << request << " complete";
785 if (!request->my_contacts_group_id().empty()) 785 if (!request->my_contacts_group_id().empty())
786 cached_my_contacts_group_id_ = request->my_contacts_group_id(); 786 cached_my_contacts_group_id_ = request->my_contacts_group_id();
787 requests_.erase(request); 787 requests_.erase(request);
788 delete request; 788 delete request;
789 } 789 }
790 790
791 } // namespace contacts 791 } // namespace contacts
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698