Commit d031a26f authored by derat@chromium.org's avatar derat@chromium.org

contacts: Give up after repeated transient photo errors.

This make GDataContactsService report failure after getting
more than two 5xx errors while downloading a particular
contact's photo.  I'm doing this so we don't keep pounding
away indefinitely if the server is having trouble.

BUG=128805
TEST=none


Review URL: https://chromiumcodereview.appspot.com/10829398

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@152219 0039d316-1c4b-4281-b951-d872f2087c98
parent 404a0586
...@@ -34,6 +34,10 @@ namespace { ...@@ -34,6 +34,10 @@ namespace {
// At values above 10, Google starts returning 503 errors. // At values above 10, Google starts returning 503 errors.
const int kMaxPhotoDownloadsPerSecond = 10; const int kMaxPhotoDownloadsPerSecond = 10;
// Give up after seeing more than this many transient errors while trying to
// download a photo for a single contact.
const int kMaxTransientPhotoDownloadErrorsPerContact = 2;
// Hardcoded system group ID for the "My Contacts" group, per // Hardcoded system group ID for the "My Contacts" group, per
// https://developers.google.com/google-apps/contacts/v3/#contact_group_entry. // https://developers.google.com/google-apps/contacts/v3/#contact_group_entry.
const char kMyContactsSystemGroupId[] = "Contacts"; const char kMyContactsSystemGroupId[] = "Contacts";
...@@ -661,10 +665,13 @@ class GDataContactsService::DownloadContactsRequest { ...@@ -661,10 +665,13 @@ class GDataContactsService::DownloadContactsRequest {
if (error == HTTP_INTERNAL_SERVER_ERROR || if (error == HTTP_INTERNAL_SERVER_ERROR ||
error == HTTP_SERVICE_UNAVAILABLE) { error == HTTP_SERVICE_UNAVAILABLE) {
LOG(WARNING) << "Got error " << error << " while downloading photo " int num_errors = ++transient_photo_download_errors_per_contact_[contact];
<< "for " << contact->provider_id() << "; retrying"; if (num_errors <= kMaxTransientPhotoDownloadErrorsPerContact) {
contacts_needing_photo_downloads_.push_back(contact); LOG(WARNING) << "Got error " << error << " while downloading photo "
return; << "for " << contact->provider_id() << "; retrying";
contacts_needing_photo_downloads_.push_back(contact);
return;
}
} }
if (error == HTTP_NOT_FOUND) { if (error == HTTP_NOT_FOUND) {
...@@ -717,6 +724,12 @@ class GDataContactsService::DownloadContactsRequest { ...@@ -717,6 +724,12 @@ class GDataContactsService::DownloadContactsRequest {
// Number of in-progress photo downloads. // Number of in-progress photo downloads.
int num_in_progress_photo_downloads_; int num_in_progress_photo_downloads_;
// Map from a contact to the number of transient errors that we've encountered
// while trying to download its photo. Contacts for which no errors have been
// encountered aren't represented in the map.
std::map<contacts::Contact*, int>
transient_photo_download_errors_per_contact_;
// Did we encounter a fatal error while downloading a photo? // Did we encounter a fatal error while downloading a photo?
bool photo_download_failed_; bool photo_download_failed_;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment