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

Unified Diff: sync/internal_api/attachments/attachment_uploader_impl.cc

Issue 554743004: Update AttachmentServiceImpl to retry attachment uploads. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Merge with master. Created 6 years, 3 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 side-by-side diff with in-line comments
Download patch
Index: sync/internal_api/attachments/attachment_uploader_impl.cc
diff --git a/sync/internal_api/attachments/attachment_uploader_impl.cc b/sync/internal_api/attachments/attachment_uploader_impl.cc
index 4d197eb6da7edb9d4114c7111c77b0eafe15aca3..59885b76d8854aa2ae967cd33ae060cda3f34b86 100644
--- a/sync/internal_api/attachments/attachment_uploader_impl.cc
+++ b/sync/internal_api/attachments/attachment_uploader_impl.cc
@@ -133,20 +133,22 @@ const Attachment& AttachmentUploaderImpl::UploadState::GetAttachment() {
void AttachmentUploaderImpl::UploadState::OnURLFetchComplete(
const net::URLFetcher* source) {
DCHECK(CalledOnValidThread());
- UploadResult result = UPLOAD_UNSPECIFIED_ERROR;
+ UploadResult result = UPLOAD_TRANSIENT_ERROR;
AttachmentId attachment_id = attachment_.GetId();
- if (source->GetResponseCode() == net::HTTP_OK) {
+ const int response_code = source->GetResponseCode();
+ if (response_code == net::HTTP_OK) {
result = UPLOAD_SUCCESS;
- } else if (source->GetResponseCode() == net::HTTP_UNAUTHORIZED) {
- // TODO(maniscalco): One possibility is that we received a 401 because our
- // access token has expired. We should probably fetch a new access token
- // and retry this upload before giving up and reporting failure to our
- // caller (bug 380437).
+ } else if (response_code == net::HTTP_UNAUTHORIZED) {
+ // Server tells us we've got a bad token so invalidate it.
OAuth2TokenServiceRequest::InvalidateToken(
token_service_provider_, account_id_, scopes_, access_token_);
- } else {
- // TODO(maniscalco): Once the protocol is better defined, deal with the
- // various HTTP response codes we may encounter.
+ // Fail the request, but indicate that it may be successful if retried.
+ result = UPLOAD_TRANSIENT_ERROR;
+ } else if (response_code == net::HTTP_FORBIDDEN) {
+ // User is not allowed to use attachments. Retrying won't help.
+ result = UPLOAD_UNSPECIFIED_ERROR;
+ } else if (response_code == net::URLFetcher::RESPONSE_CODE_INVALID) {
+ result = UPLOAD_TRANSIENT_ERROR;
}
ReportResult(result, attachment_id);
}
@@ -160,6 +162,7 @@ void AttachmentUploaderImpl::UploadState::OnGetTokenSuccess(
access_token_ = access_token;
fetcher_.reset(
net::URLFetcher::Create(upload_url_, net::URLFetcher::POST, this));
+ fetcher_->SetAutomaticallyRetryOn5xx(false);
fetcher_->SetRequestContext(url_request_context_getter_.get());
// TODO(maniscalco): Is there a better way? Copying the attachment data into
// a string feels wrong given how large attachments may be (several MBs). If
@@ -184,7 +187,11 @@ void AttachmentUploaderImpl::UploadState::OnGetTokenFailure(
const GoogleServiceAuthError& error) {
DCHECK_EQ(access_token_request_.get(), request);
access_token_request_.reset();
- ReportResult(UPLOAD_UNSPECIFIED_ERROR, attachment_.GetId());
+ // TODO(maniscalco): We treat this as a transient error, but it may in fact be
+ // a very long lived error and require user action. Consider differentiating
+ // between the causes of GetToken failure and act accordingly. Think about
+ // the causes of GetToken failure. Are there (bug 412802).
+ ReportResult(UPLOAD_TRANSIENT_ERROR, attachment_.GetId());
}
void AttachmentUploaderImpl::UploadState::GetToken() {

Powered by Google App Engine
This is Rietveld 408576698