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/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 16 matching lines...) Expand all Loading... | |
27 using content::BrowserThread; | 27 using content::BrowserThread; |
28 | 28 |
29 namespace gdata { | 29 namespace gdata { |
30 | 30 |
31 namespace { | 31 namespace { |
32 | 32 |
33 // Maximum number of profile photos that we'll download per second. | 33 // Maximum number of profile photos that we'll download per second. |
34 // At values above 10, Google starts returning 503 errors. | 34 // At values above 10, Google starts returning 503 errors. |
35 const int kMaxPhotoDownloadsPerSecond = 10; | 35 const int kMaxPhotoDownloadsPerSecond = 10; |
36 | 36 |
37 // Give up after seeing more than this many transient errors while trying to | |
38 // download a photo for a single contact. | |
39 const int kMaxTransientPhotoDownloadErrorsPerContact = 2; | |
40 | |
37 // Hardcoded system group ID for the "My Contacts" group, per | 41 // Hardcoded system group ID for the "My Contacts" group, per |
38 // https://developers.google.com/google-apps/contacts/v3/#contact_group_entry. | 42 // https://developers.google.com/google-apps/contacts/v3/#contact_group_entry. |
39 const char kMyContactsSystemGroupId[] = "Contacts"; | 43 const char kMyContactsSystemGroupId[] = "Contacts"; |
40 | 44 |
41 // Top-level field in a contact groups feed containing the list of entries. | 45 // Top-level field in a contact groups feed containing the list of entries. |
42 const char kGroupEntryField[] = "feed.entry"; | 46 const char kGroupEntryField[] = "feed.entry"; |
43 | 47 |
44 // Field in group entries containing the system group ID (e.g. ID "Contacts" | 48 // Field in group entries containing the system group ID (e.g. ID "Contacts" |
45 // for the "My Contacts" system group). See | 49 // for the "My Contacts" system group). See |
46 // https://developers.google.com/google-apps/contacts/v3/#contact_group_entry | 50 // https://developers.google.com/google-apps/contacts/v3/#contact_group_entry |
(...skipping 607 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
654 void HandlePhotoData(contacts::Contact* contact, | 658 void HandlePhotoData(contacts::Contact* contact, |
655 GDataErrorCode error, | 659 GDataErrorCode error, |
656 scoped_ptr<std::string> download_data) { | 660 scoped_ptr<std::string> download_data) { |
657 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 661 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
658 VLOG(1) << "Got photo data for " << contact->provider_id() | 662 VLOG(1) << "Got photo data for " << contact->provider_id() |
659 << " (error=" << error << " size=" << download_data->size() << ")"; | 663 << " (error=" << error << " size=" << download_data->size() << ")"; |
660 num_in_progress_photo_downloads_--; | 664 num_in_progress_photo_downloads_--; |
661 | 665 |
662 if (error == HTTP_INTERNAL_SERVER_ERROR || | 666 if (error == HTTP_INTERNAL_SERVER_ERROR || |
663 error == HTTP_SERVICE_UNAVAILABLE) { | 667 error == HTTP_SERVICE_UNAVAILABLE) { |
664 LOG(WARNING) << "Got error " << error << " while downloading photo " | 668 int num_errors = ++transient_photo_download_errors_per_contact_[contact]; |
665 << "for " << contact->provider_id() << "; retrying"; | 669 if (num_errors <= kMaxTransientPhotoDownloadErrorsPerContact) { |
666 contacts_needing_photo_downloads_.push_back(contact); | 670 LOG(WARNING) << "Got error " << error << " while downloading photo " |
667 return; | 671 << "for " << contact->provider_id() << "; retrying"; |
672 contacts_needing_photo_downloads_.push_back(contact); | |
673 return; | |
674 } | |
668 } | 675 } |
669 | 676 |
670 if (error == HTTP_NOT_FOUND) { | 677 if (error == HTTP_NOT_FOUND) { |
671 LOG(WARNING) << "Got error " << error << " while downloading photo " | 678 LOG(WARNING) << "Got error " << error << " while downloading photo " |
672 << "for " << contact->provider_id() << "; skipping"; | 679 << "for " << contact->provider_id() << "; skipping"; |
673 CheckCompletion(); | 680 CheckCompletion(); |
674 return; | 681 return; |
675 } | 682 } |
676 | 683 |
677 if (error != HTTP_SUCCESS) { | 684 if (error != HTTP_SUCCESS) { |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
710 // Invokes StartPhotoDownloads() once per second. | 717 // Invokes StartPhotoDownloads() once per second. |
711 base::RepeatingTimer<DownloadContactsRequest> photo_download_timer_; | 718 base::RepeatingTimer<DownloadContactsRequest> photo_download_timer_; |
712 | 719 |
713 // Contacts that have photos that we still need to start downloading. | 720 // Contacts that have photos that we still need to start downloading. |
714 // When we start a download, the contact is removed from this list. | 721 // When we start a download, the contact is removed from this list. |
715 std::vector<contacts::Contact*> contacts_needing_photo_downloads_; | 722 std::vector<contacts::Contact*> contacts_needing_photo_downloads_; |
716 | 723 |
717 // Number of in-progress photo downloads. | 724 // Number of in-progress photo downloads. |
718 int num_in_progress_photo_downloads_; | 725 int num_in_progress_photo_downloads_; |
719 | 726 |
727 // Map from a contact to the number of transient errors that we've encountered | |
728 // while trying to download its photo. Contacts for which no errors have been | |
729 // encountered aren't represented in the map. | |
730 std::map<contacts::Contact*, int> | |
satorux1
2012/08/17 21:55:21
I'm slightly concerned about using a key as a poin
Daniel Erat
2012/08/17 22:05:03
I'll change this if you really want me to, but non
| |
731 transient_photo_download_errors_per_contact_; | |
732 | |
720 // Did we encounter a fatal error while downloading a photo? | 733 // Did we encounter a fatal error while downloading a photo? |
721 bool photo_download_failed_; | 734 bool photo_download_failed_; |
722 | 735 |
723 // Note: This should remain the last member so it'll be destroyed and | 736 // Note: This should remain the last member so it'll be destroyed and |
724 // invalidate its weak pointers before any other members are destroyed. | 737 // invalidate its weak pointers before any other members are destroyed. |
725 base::WeakPtrFactory<DownloadContactsRequest> weak_ptr_factory_; | 738 base::WeakPtrFactory<DownloadContactsRequest> weak_ptr_factory_; |
726 | 739 |
727 DISALLOW_COPY_AND_ASSIGN(DownloadContactsRequest); | 740 DISALLOW_COPY_AND_ASSIGN(DownloadContactsRequest); |
728 }; | 741 }; |
729 | 742 |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
769 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 782 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
770 DCHECK(request); | 783 DCHECK(request); |
771 VLOG(1) << "Download request " << request << " complete"; | 784 VLOG(1) << "Download request " << request << " complete"; |
772 if (!request->my_contacts_group_id().empty()) | 785 if (!request->my_contacts_group_id().empty()) |
773 cached_my_contacts_group_id_ = request->my_contacts_group_id(); | 786 cached_my_contacts_group_id_ = request->my_contacts_group_id(); |
774 requests_.erase(request); | 787 requests_.erase(request); |
775 delete request; | 788 delete request; |
776 } | 789 } |
777 | 790 |
778 } // namespace contacts | 791 } // namespace contacts |
OLD | NEW |