Chromium Code Reviews| Index: chrome/browser/chromeos/policy/upload_job_impl.cc |
| diff --git a/chrome/browser/chromeos/policy/upload_job_impl.cc b/chrome/browser/chromeos/policy/upload_job_impl.cc |
| index d557c287b505fc11be6cbe0f215af769a4bd996e..ef498e0da83daeea3225e32b1a0b97eee12ba1f9 100644 |
| --- a/chrome/browser/chromeos/policy/upload_job_impl.cc |
| +++ b/chrome/browser/chromeos/policy/upload_job_impl.cc |
| @@ -28,8 +28,8 @@ const char kAuthorizationHeaderFormat[] = "Authorization: Bearer %s"; |
| // Value the "Content-Type" field will be set to in the POST request. |
| const char kUploadContentType[] = "multipart/form-data"; |
| -// Number of upload retries. |
| -const int kMaxRetries = 1; |
| +// Number of upload tries. |
|
Andrew T Wilson (Slow)
2016/04/08 15:42:56
nit: tries -> attempts
Marton Hunyady
2016/04/08 16:47:46
Done.
|
| +const int kMaxRetries = 3; |
| // Max size of MIME boundary according to RFC 1341, section 7.2.1. |
| const size_t kMaxMimeBoundarySize = 70; |
| @@ -298,53 +298,56 @@ void UploadJobImpl::OnGetTokenFailure( |
| delegate_->OnFailure(AUTHENTICATION_ERROR); |
| } |
| +void UploadJobImpl::HandleError(ErrorCode errorCode) { |
| + retry_++; |
| + upload_fetcher_.reset(); |
| + if (retry_ >= kMaxRetries) { |
| + // Maximum number of tries reached, failure |
| + access_token_.clear(); |
| + post_data_.reset(); |
| + state_ = ERROR; |
| + delegate_->OnFailure(errorCode); |
| + } else { |
| + if (errorCode == AUTHENTICATION_ERROR) { |
| + // Request new token and retry |
|
Andrew T Wilson (Slow)
2016/04/08 15:42:55
nit: if your comment is a full sentence, you shoul
Marton Hunyady
2016/04/08 16:47:46
Done.
|
| + OAuth2TokenService::ScopeSet scope_set; |
| + scope_set.insert(GaiaConstants::kDeviceManagementServiceOAuth); |
| + token_service_->InvalidateAccessToken(account_id_, scope_set, |
| + access_token_); |
| + access_token_.clear(); |
| + RequestAccessToken(); |
| + } else { |
| + // Retry without a new token |
| + state_ = ACQUIRING_TOKEN; |
| + StartUpload(access_token_); |
| + } |
| + } |
| +} |
| + |
| void UploadJobImpl::OnURLFetchComplete(const net::URLFetcher* source) { |
| DCHECK_EQ(upload_fetcher_.get(), source); |
| + DCHECK_EQ(UPLOADING, state_); |
| const net::URLRequestStatus& status = source->GetStatus(); |
| if (!status.is_success()) { |
| LOG(ERROR) << "URLRequestStatus error " << status.error(); |
| - upload_fetcher_.reset(); |
| - state_ = ERROR; |
| - post_data_.reset(); |
| - delegate_->OnFailure(NETWORK_ERROR); |
| - return; |
| - } |
| - |
| - const int response_code = source->GetResponseCode(); |
| - const bool success = response_code == net::HTTP_OK; |
| - if (!success) |
| - LOG(ERROR) << "POST request failed with HTTP status code " << response_code; |
| - |
| - if (response_code == net::HTTP_UNAUTHORIZED) { |
| - if (retry_ >= kMaxRetries) { |
| + HandleError(NETWORK_ERROR); |
| + } else { |
| + const int response_code = source->GetResponseCode(); |
| + if (response_code == net::HTTP_OK) { |
| + // Successful uploading |
| upload_fetcher_.reset(); |
| - LOG(ERROR) << "Unauthorized request."; |
| - state_ = ERROR; |
| + access_token_.clear(); |
| post_data_.reset(); |
| - delegate_->OnFailure(AUTHENTICATION_ERROR); |
| - return; |
| + state_ = SUCCESS; |
| + delegate_->OnSuccess(); |
| + } else if (response_code == net::HTTP_UNAUTHORIZED) { |
| + LOG(ERROR) << "Unauthorized request."; |
| + HandleError(AUTHENTICATION_ERROR); |
| + } else { |
| + LOG(ERROR) << "POST request failed with HTTP status code " |
| + << response_code; |
| + HandleError(SERVER_ERROR); |
| } |
| - retry_++; |
| - upload_fetcher_.reset(); |
| - OAuth2TokenService::ScopeSet scope_set; |
| - scope_set.insert(GaiaConstants::kDeviceManagementServiceOAuth); |
| - token_service_->InvalidateAccessToken(account_id_, scope_set, |
| - access_token_); |
| - access_token_.clear(); |
| - RequestAccessToken(); |
| - return; |
| - } |
| - |
| - upload_fetcher_.reset(); |
| - access_token_.clear(); |
| - upload_fetcher_.reset(); |
| - post_data_.reset(); |
| - if (success) { |
| - state_ = SUCCESS; |
| - delegate_->OnSuccess(); |
| - } else { |
| - state_ = ERROR; |
| - delegate_->OnFailure(SERVER_ERROR); |
| } |
| } |