| Index: chrome/service/cloud_print/cloud_print_url_fetcher.cc
|
| ===================================================================
|
| --- chrome/service/cloud_print/cloud_print_url_fetcher.cc (revision 104911)
|
| +++ chrome/service/cloud_print/cloud_print_url_fetcher.cc (working copy)
|
| @@ -15,11 +15,17 @@
|
| #include "googleurl/src/gurl.h"
|
| #include "net/url_request/url_request_status.h"
|
|
|
| +const int kHTTPUnsupportedMediaType = 415;
|
| +
|
| CloudPrintURLFetcher::CloudPrintURLFetcher()
|
| : delegate_(NULL),
|
| num_retries_(0) {
|
| }
|
|
|
| +bool CloudPrintURLFetcher::IsSameRequest(const URLFetcher* source) {
|
| + return (request_.get() == source);
|
| +}
|
| +
|
| void CloudPrintURLFetcher::StartGetRequest(
|
| const GURL& url,
|
| Delegate* delegate,
|
| @@ -68,15 +74,13 @@
|
| response_code,
|
| cookies,
|
| data);
|
| +
|
| + // If we get auth error, notify delegate and check if it wants to procceed.
|
| + if (action == CONTINUE_PROCESSING && RC_FORBIDDEN == response_code) {
|
| + action = delegate_->OnRequestAuthError();
|
| + }
|
| +
|
| if (action == CONTINUE_PROCESSING) {
|
| - // If we are not using an OAuth token, and we got an auth error, we are
|
| - // done. Else, the token may have been refreshed. Let us try again.
|
| - if ((RC_FORBIDDEN == response_code) &&
|
| - (!CloudPrintTokenStore::current() ||
|
| - !CloudPrintTokenStore::current()->token_is_oauth())) {
|
| - delegate_->OnRequestAuthError();
|
| - return;
|
| - }
|
| // We need to retry on all network errors.
|
| if (!status.is_success() || (response_code != 200))
|
| action = RETRY_REQUEST;
|
| @@ -108,6 +112,12 @@
|
| // be ignored.
|
| request_->ReceivedContentWasMalformed();
|
|
|
| + // If we receive error code from the server "Media Type Not Supported",
|
| + // there is no reasons to retry, request will never succeed.
|
| + // In that case we should call OnRequestGiveUp() right away.
|
| + if (response_code == kHTTPUnsupportedMediaType)
|
| + num_retries_ = source->max_retries();
|
| +
|
| ++num_retries_;
|
| if ((-1 != source->max_retries()) &&
|
| (num_retries_ > source->max_retries())) {
|
| @@ -139,8 +149,8 @@
|
| // Since we implement our own retry logic, disable the retry in URLFetcher.
|
| request_->set_automatically_retry_on_5xx(false);
|
| request_->set_max_retries(max_retries);
|
| + delegate_ = delegate;
|
| SetupRequestHeaders();
|
| - delegate_ = delegate;
|
| if (request_type == URLFetcher::POST) {
|
| request_->set_upload_data(post_data_mime_type, post_data);
|
| }
|
| @@ -149,14 +159,9 @@
|
| }
|
|
|
| void CloudPrintURLFetcher::SetupRequestHeaders() {
|
| - std::string headers;
|
| - CloudPrintTokenStore* token_store = CloudPrintTokenStore::current();
|
| - if (token_store) {
|
| - headers = token_store->token_is_oauth() ?
|
| - "Authorization: OAuth " : "Authorization: GoogleLogin auth=";
|
| - headers += token_store->token();
|
| + std::string headers = delegate_->GetAuthHeader();
|
| + if (!headers.empty())
|
| headers += "\r\n";
|
| - }
|
| headers += kChromeCloudPrintProxyHeader;
|
| if (!additional_headers_.empty()) {
|
| headers += "\r\n";
|
|
|