| 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/service/cloud_print/cloud_print_url_fetcher.h" | 5 #include "chrome/service/cloud_print/cloud_print_url_fetcher.h" |
| 6 | 6 |
| 7 #include "base/stringprintf.h" | 7 #include "base/stringprintf.h" |
| 8 #include "base/values.h" | 8 #include "base/values.h" |
| 9 #include "chrome/common/cloud_print/cloud_print_constants.h" | 9 #include "chrome/common/cloud_print/cloud_print_constants.h" |
| 10 #include "chrome/common/cloud_print/cloud_print_helpers.h" | 10 #include "chrome/common/cloud_print/cloud_print_helpers.h" |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 138 // Explicitly call ReceivedContentWasMalformed() to ensure the current | 138 // Explicitly call ReceivedContentWasMalformed() to ensure the current |
| 139 // request gets counted as a failure for calculation of the back-off | 139 // request gets counted as a failure for calculation of the back-off |
| 140 // period. If it was already a failure by status code, this call will | 140 // period. If it was already a failure by status code, this call will |
| 141 // be ignored. | 141 // be ignored. |
| 142 request_->ReceivedContentWasMalformed(); | 142 request_->ReceivedContentWasMalformed(); |
| 143 | 143 |
| 144 // If we receive error code from the server "Media Type Not Supported", | 144 // If we receive error code from the server "Media Type Not Supported", |
| 145 // there is no reason to retry, request will never succeed. | 145 // there is no reason to retry, request will never succeed. |
| 146 // In that case we should call OnRequestGiveUp() right away. | 146 // In that case we should call OnRequestGiveUp() right away. |
| 147 if (source->GetResponseCode() == net::HTTP_UNSUPPORTED_MEDIA_TYPE) | 147 if (source->GetResponseCode() == net::HTTP_UNSUPPORTED_MEDIA_TYPE) |
| 148 num_retries_ = source->GetMaxRetries(); | 148 num_retries_ = source->GetMaxRetriesOn5xx(); |
| 149 | 149 |
| 150 ++num_retries_; | 150 ++num_retries_; |
| 151 if ((-1 != source->GetMaxRetries()) && | 151 if ((-1 != source->GetMaxRetriesOn5xx()) && |
| 152 (num_retries_ > source->GetMaxRetries())) { | 152 (num_retries_ > source->GetMaxRetriesOn5xx())) { |
| 153 // Retry limit reached. Give up. | 153 // Retry limit reached. Give up. |
| 154 delegate_->OnRequestGiveUp(); | 154 delegate_->OnRequestGiveUp(); |
| 155 } else { | 155 } else { |
| 156 // Either no retry limit specified or retry limit has not yet been | 156 // Either no retry limit specified or retry limit has not yet been |
| 157 // reached. Try again. Set up the request headers again because the token | 157 // reached. Try again. Set up the request headers again because the token |
| 158 // may have changed. | 158 // may have changed. |
| 159 SetupRequestHeaders(); | 159 SetupRequestHeaders(); |
| 160 request_->SetRequestContext(GetRequestContextGetter()); | 160 request_->SetRequestContext(GetRequestContextGetter()); |
| 161 request_->Start(); | 161 request_->Start(); |
| 162 } | 162 } |
| 163 } | 163 } |
| 164 } | 164 } |
| 165 | 165 |
| 166 void CloudPrintURLFetcher::StartRequestHelper( | 166 void CloudPrintURLFetcher::StartRequestHelper( |
| 167 const GURL& url, | 167 const GURL& url, |
| 168 net::URLFetcher::RequestType request_type, | 168 net::URLFetcher::RequestType request_type, |
| 169 Delegate* delegate, | 169 Delegate* delegate, |
| 170 int max_retries, | 170 int max_retries, |
| 171 const std::string& post_data_mime_type, | 171 const std::string& post_data_mime_type, |
| 172 const std::string& post_data, | 172 const std::string& post_data, |
| 173 const std::string& additional_headers) { | 173 const std::string& additional_headers) { |
| 174 DCHECK(delegate); | 174 DCHECK(delegate); |
| 175 // Persist the additional headers in case we need to retry the request. | 175 // Persist the additional headers in case we need to retry the request. |
| 176 additional_headers_ = additional_headers; | 176 additional_headers_ = additional_headers; |
| 177 request_.reset(net::URLFetcher::Create(url, request_type, this)); | 177 request_.reset(net::URLFetcher::Create(url, request_type, this)); |
| 178 request_->SetRequestContext(GetRequestContextGetter()); | 178 request_->SetRequestContext(GetRequestContextGetter()); |
| 179 // Since we implement our own retry logic, disable the retry in URLFetcher. | 179 // Since we implement our own retry logic, disable the retry in URLFetcher. |
| 180 request_->SetAutomaticallyRetryOn5xx(false); | 180 request_->SetAutomaticallyRetryOn5xx(false); |
| 181 request_->SetMaxRetries(max_retries); | 181 request_->SetMaxRetriesOn5xx(max_retries); |
| 182 delegate_ = delegate; | 182 delegate_ = delegate; |
| 183 SetupRequestHeaders(); | 183 SetupRequestHeaders(); |
| 184 request_->SetLoadFlags(net::LOAD_DO_NOT_SEND_COOKIES | | 184 request_->SetLoadFlags(net::LOAD_DO_NOT_SEND_COOKIES | |
| 185 net::LOAD_DO_NOT_SAVE_COOKIES); | 185 net::LOAD_DO_NOT_SAVE_COOKIES); |
| 186 if (request_type == net::URLFetcher::POST) { | 186 if (request_type == net::URLFetcher::POST) { |
| 187 request_->SetUploadData(post_data_mime_type, post_data); | 187 request_->SetUploadData(post_data_mime_type, post_data); |
| 188 } | 188 } |
| 189 | 189 |
| 190 request_->Start(); | 190 request_->Start(); |
| 191 } | 191 } |
| (...skipping 16 matching lines...) Expand all Loading... |
| 208 ServiceURLRequestContextGetter* getter = | 208 ServiceURLRequestContextGetter* getter = |
| 209 g_service_process->GetServiceURLRequestContextGetter(); | 209 g_service_process->GetServiceURLRequestContextGetter(); |
| 210 // Now set up the user agent for cloudprint. | 210 // Now set up the user agent for cloudprint. |
| 211 std::string user_agent = getter->user_agent(); | 211 std::string user_agent = getter->user_agent(); |
| 212 base::StringAppendF(&user_agent, " %s", kCloudPrintUserAgent); | 212 base::StringAppendF(&user_agent, " %s", kCloudPrintUserAgent); |
| 213 getter->set_user_agent(user_agent); | 213 getter->set_user_agent(user_agent); |
| 214 return getter; | 214 return getter; |
| 215 } | 215 } |
| 216 | 216 |
| 217 } // namespace cloud_print | 217 } // namespace cloud_print |
| OLD | NEW |