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_helpers.h" | 9 #include "chrome/common/cloud_print/cloud_print_helpers.h" |
10 #include "chrome/service/cloud_print/cloud_print_consts.h" | 10 #include "chrome/service/cloud_print/cloud_print_consts.h" |
(...skipping 13 matching lines...) Expand all Loading... |
24 bool CloudPrintURLFetcher::IsSameRequest(const net::URLFetcher* source) { | 24 bool CloudPrintURLFetcher::IsSameRequest(const net::URLFetcher* source) { |
25 return (request_.get() == source); | 25 return (request_.get() == source); |
26 } | 26 } |
27 | 27 |
28 void CloudPrintURLFetcher::StartGetRequest( | 28 void CloudPrintURLFetcher::StartGetRequest( |
29 const GURL& url, | 29 const GURL& url, |
30 Delegate* delegate, | 30 Delegate* delegate, |
31 int max_retries, | 31 int max_retries, |
32 const std::string& additional_headers) { | 32 const std::string& additional_headers) { |
33 StartRequestHelper(url, | 33 StartRequestHelper(url, |
34 content::URLFetcher::GET, | 34 net::URLFetcher::GET, |
35 delegate, | 35 delegate, |
36 max_retries, | 36 max_retries, |
37 std::string(), | 37 std::string(), |
38 std::string(), | 38 std::string(), |
39 additional_headers); | 39 additional_headers); |
40 } | 40 } |
41 | 41 |
42 void CloudPrintURLFetcher::StartPostRequest( | 42 void CloudPrintURLFetcher::StartPostRequest( |
43 const GURL& url, | 43 const GURL& url, |
44 Delegate* delegate, | 44 Delegate* delegate, |
45 int max_retries, | 45 int max_retries, |
46 const std::string& post_data_mime_type, | 46 const std::string& post_data_mime_type, |
47 const std::string& post_data, | 47 const std::string& post_data, |
48 const std::string& additional_headers) { | 48 const std::string& additional_headers) { |
49 StartRequestHelper(url, | 49 StartRequestHelper(url, |
50 content::URLFetcher::POST, | 50 net::URLFetcher::POST, |
51 delegate, | 51 delegate, |
52 max_retries, | 52 max_retries, |
53 post_data_mime_type, | 53 post_data_mime_type, |
54 post_data, | 54 post_data, |
55 additional_headers); | 55 additional_headers); |
56 } | 56 } |
57 | 57 |
58 void CloudPrintURLFetcher::OnURLFetchComplete( | 58 void CloudPrintURLFetcher::OnURLFetchComplete( |
59 const net::URLFetcher* source) { | 59 const net::URLFetcher* source) { |
60 VLOG(1) << "CP_PROXY: OnURLFetchComplete, url: " << source->GetURL() | 60 VLOG(1) << "CP_PROXY: OnURLFetchComplete, url: " << source->GetURL() |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
126 // may have changed. | 126 // may have changed. |
127 SetupRequestHeaders(); | 127 SetupRequestHeaders(); |
128 request_->SetRequestContext(GetRequestContextGetter()); | 128 request_->SetRequestContext(GetRequestContextGetter()); |
129 request_->Start(); | 129 request_->Start(); |
130 } | 130 } |
131 } | 131 } |
132 } | 132 } |
133 | 133 |
134 void CloudPrintURLFetcher::StartRequestHelper( | 134 void CloudPrintURLFetcher::StartRequestHelper( |
135 const GURL& url, | 135 const GURL& url, |
136 content::URLFetcher::RequestType request_type, | 136 net::URLFetcher::RequestType request_type, |
137 Delegate* delegate, | 137 Delegate* delegate, |
138 int max_retries, | 138 int max_retries, |
139 const std::string& post_data_mime_type, | 139 const std::string& post_data_mime_type, |
140 const std::string& post_data, | 140 const std::string& post_data, |
141 const std::string& additional_headers) { | 141 const std::string& additional_headers) { |
142 DCHECK(delegate); | 142 DCHECK(delegate); |
143 // Persist the additional headers in case we need to retry the request. | 143 // Persist the additional headers in case we need to retry the request. |
144 additional_headers_ = additional_headers; | 144 additional_headers_ = additional_headers; |
145 request_.reset(content::URLFetcher::Create(url, request_type, this)); | 145 request_.reset(content::URLFetcher::Create(url, request_type, this)); |
146 request_->SetRequestContext(GetRequestContextGetter()); | 146 request_->SetRequestContext(GetRequestContextGetter()); |
147 // Since we implement our own retry logic, disable the retry in URLFetcher. | 147 // Since we implement our own retry logic, disable the retry in URLFetcher. |
148 request_->SetAutomaticallyRetryOn5xx(false); | 148 request_->SetAutomaticallyRetryOn5xx(false); |
149 request_->SetMaxRetries(max_retries); | 149 request_->SetMaxRetries(max_retries); |
150 delegate_ = delegate; | 150 delegate_ = delegate; |
151 SetupRequestHeaders(); | 151 SetupRequestHeaders(); |
152 if (request_type == content::URLFetcher::POST) { | 152 if (request_type == net::URLFetcher::POST) { |
153 request_->SetUploadData(post_data_mime_type, post_data); | 153 request_->SetUploadData(post_data_mime_type, post_data); |
154 } | 154 } |
155 | 155 |
156 request_->Start(); | 156 request_->Start(); |
157 } | 157 } |
158 | 158 |
159 void CloudPrintURLFetcher::SetupRequestHeaders() { | 159 void CloudPrintURLFetcher::SetupRequestHeaders() { |
160 std::string headers = delegate_->GetAuthHeader(); | 160 std::string headers = delegate_->GetAuthHeader(); |
161 if (!headers.empty()) | 161 if (!headers.empty()) |
162 headers += "\r\n"; | 162 headers += "\r\n"; |
163 headers += cloud_print::kChromeCloudPrintProxyHeader; | 163 headers += cloud_print::kChromeCloudPrintProxyHeader; |
164 if (!additional_headers_.empty()) { | 164 if (!additional_headers_.empty()) { |
165 headers += "\r\n"; | 165 headers += "\r\n"; |
166 headers += additional_headers_; | 166 headers += additional_headers_; |
167 } | 167 } |
168 request_->SetExtraRequestHeaders(headers); | 168 request_->SetExtraRequestHeaders(headers); |
169 } | 169 } |
170 | 170 |
171 CloudPrintURLFetcher::~CloudPrintURLFetcher() {} | 171 CloudPrintURLFetcher::~CloudPrintURLFetcher() {} |
172 | 172 |
173 net::URLRequestContextGetter* CloudPrintURLFetcher::GetRequestContextGetter() { | 173 net::URLRequestContextGetter* CloudPrintURLFetcher::GetRequestContextGetter() { |
174 ServiceURLRequestContextGetter* getter = | 174 ServiceURLRequestContextGetter* getter = |
175 g_service_process->GetServiceURLRequestContextGetter(); | 175 g_service_process->GetServiceURLRequestContextGetter(); |
176 // Now set up the user agent for cloudprint. | 176 // Now set up the user agent for cloudprint. |
177 std::string user_agent = getter->user_agent(); | 177 std::string user_agent = getter->user_agent(); |
178 base::StringAppendF(&user_agent, " %s", kCloudPrintUserAgent); | 178 base::StringAppendF(&user_agent, " %s", kCloudPrintUserAgent); |
179 getter->set_user_agent(user_agent); | 179 getter->set_user_agent(user_agent); |
180 return getter; | 180 return getter; |
181 } | 181 } |
OLD | NEW |