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/service/cloud_print/cloud_print_consts.h" | 9 #include "chrome/service/cloud_print/cloud_print_consts.h" |
10 #include "chrome/service/cloud_print/cloud_print_helpers.h" | 10 #include "chrome/service/cloud_print/cloud_print_helpers.h" |
11 #include "chrome/service/cloud_print/cloud_print_token_store.h" | 11 #include "chrome/service/cloud_print/cloud_print_token_store.h" |
12 #include "chrome/service/net/service_url_request_context.h" | 12 #include "chrome/service/net/service_url_request_context.h" |
13 #include "chrome/service/service_process.h" | 13 #include "chrome/service/service_process.h" |
| 14 #include "content/public/common/content_url_request_user_data.h" |
14 #include "googleurl/src/gurl.h" | 15 #include "googleurl/src/gurl.h" |
15 #include "net/http/http_status_code.h" | 16 #include "net/http/http_status_code.h" |
16 #include "net/url_request/url_request_status.h" | 17 #include "net/url_request/url_request_status.h" |
17 | 18 |
18 CloudPrintURLFetcher::CloudPrintURLFetcher() | 19 CloudPrintURLFetcher::CloudPrintURLFetcher() |
19 : delegate_(NULL), | 20 : delegate_(NULL), |
20 num_retries_(0) { | 21 num_retries_(0) { |
21 } | 22 } |
22 | 23 |
23 bool CloudPrintURLFetcher::IsSameRequest(const content::URLFetcher* source) { | 24 bool CloudPrintURLFetcher::IsSameRequest(const content::URLFetcher* source) { |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
117 ++num_retries_; | 118 ++num_retries_; |
118 if ((-1 != source->GetMaxRetries()) && | 119 if ((-1 != source->GetMaxRetries()) && |
119 (num_retries_ > source->GetMaxRetries())) { | 120 (num_retries_ > source->GetMaxRetries())) { |
120 // Retry limit reached. Give up. | 121 // Retry limit reached. Give up. |
121 delegate_->OnRequestGiveUp(); | 122 delegate_->OnRequestGiveUp(); |
122 } else { | 123 } else { |
123 // Either no retry limit specified or retry limit has not yet been | 124 // Either no retry limit specified or retry limit has not yet been |
124 // reached. Try again. Set up the request headers again because the token | 125 // reached. Try again. Set up the request headers again because the token |
125 // may have changed. | 126 // may have changed. |
126 SetupRequestHeaders(); | 127 SetupRequestHeaders(); |
127 request_->StartWithRequestContextGetter(GetRequestContextGetter()); | 128 // TODO(jochen): Do cookie audit. |
| 129 request_->StartWithRequestContextGetterAndUserData( |
| 130 GetRequestContextGetter(), |
| 131 new content::ContentURLRequestUserData()); |
128 } | 132 } |
129 } | 133 } |
130 } | 134 } |
131 | 135 |
132 void CloudPrintURLFetcher::StartRequestHelper( | 136 void CloudPrintURLFetcher::StartRequestHelper( |
133 const GURL& url, | 137 const GURL& url, |
134 content::URLFetcher::RequestType request_type, | 138 content::URLFetcher::RequestType request_type, |
135 Delegate* delegate, | 139 Delegate* delegate, |
136 int max_retries, | 140 int max_retries, |
137 const std::string& post_data_mime_type, | 141 const std::string& post_data_mime_type, |
138 const std::string& post_data, | 142 const std::string& post_data, |
139 const std::string& additional_headers) { | 143 const std::string& additional_headers) { |
140 DCHECK(delegate); | 144 DCHECK(delegate); |
141 // Persist the additional headers in case we need to retry the request. | 145 // Persist the additional headers in case we need to retry the request. |
142 additional_headers_ = additional_headers; | 146 additional_headers_ = additional_headers; |
143 request_.reset(content::URLFetcher::Create(url, request_type, this)); | 147 request_.reset(content::URLFetcher::Create(url, request_type, this)); |
144 request_->SetRequestContext(GetRequestContextGetter()); | 148 request_->SetRequestContext(GetRequestContextGetter()); |
| 149 // TODO(jochen): Do cookie audit. |
| 150 request_->SetContentURLRequestUserData( |
| 151 new content::ContentURLRequestUserData()); |
145 // Since we implement our own retry logic, disable the retry in URLFetcher. | 152 // Since we implement our own retry logic, disable the retry in URLFetcher. |
146 request_->SetAutomaticallyRetryOn5xx(false); | 153 request_->SetAutomaticallyRetryOn5xx(false); |
147 request_->SetMaxRetries(max_retries); | 154 request_->SetMaxRetries(max_retries); |
148 delegate_ = delegate; | 155 delegate_ = delegate; |
149 SetupRequestHeaders(); | 156 SetupRequestHeaders(); |
150 if (request_type == content::URLFetcher::POST) { | 157 if (request_type == content::URLFetcher::POST) { |
151 request_->SetUploadData(post_data_mime_type, post_data); | 158 request_->SetUploadData(post_data_mime_type, post_data); |
152 } | 159 } |
153 | 160 |
154 request_->Start(); | 161 request_->Start(); |
(...skipping 15 matching lines...) Expand all Loading... |
170 | 177 |
171 net::URLRequestContextGetter* CloudPrintURLFetcher::GetRequestContextGetter() { | 178 net::URLRequestContextGetter* CloudPrintURLFetcher::GetRequestContextGetter() { |
172 ServiceURLRequestContextGetter* getter = | 179 ServiceURLRequestContextGetter* getter = |
173 g_service_process->GetServiceURLRequestContextGetter(); | 180 g_service_process->GetServiceURLRequestContextGetter(); |
174 // Now set up the user agent for cloudprint. | 181 // Now set up the user agent for cloudprint. |
175 std::string user_agent = getter->user_agent(); | 182 std::string user_agent = getter->user_agent(); |
176 base::StringAppendF(&user_agent, " %s", kCloudPrintUserAgent); | 183 base::StringAppendF(&user_agent, " %s", kCloudPrintUserAgent); |
177 getter->set_user_agent(user_agent); | 184 getter->set_user_agent(user_agent); |
178 return getter; | 185 return getter; |
179 } | 186 } |
OLD | NEW |