OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/net/http_return.h" | 9 #include "chrome/common/net/http_return.h" |
10 #include "chrome/service/cloud_print/cloud_print_consts.h" | 10 #include "chrome/service/cloud_print/cloud_print_consts.h" |
11 #include "chrome/service/cloud_print/cloud_print_helpers.h" | 11 #include "chrome/service/cloud_print/cloud_print_helpers.h" |
12 #include "chrome/service/cloud_print/cloud_print_token_store.h" | 12 #include "chrome/service/cloud_print/cloud_print_token_store.h" |
13 #include "chrome/service/net/service_url_request_context.h" | 13 #include "chrome/service/net/service_url_request_context.h" |
14 #include "chrome/service/service_process.h" | 14 #include "chrome/service/service_process.h" |
15 #include "googleurl/src/gurl.h" | 15 #include "googleurl/src/gurl.h" |
16 #include "net/url_request/url_request_status.h" | 16 #include "net/url_request/url_request_status.h" |
17 | 17 |
18 CloudPrintURLFetcher::CloudPrintURLFetcher() | 18 CloudPrintURLFetcher::CloudPrintURLFetcher() |
19 : delegate_(NULL), | 19 : delegate_(NULL), |
20 num_retries_(0) { | 20 num_retries_(0) { |
21 } | 21 } |
22 | 22 |
23 void CloudPrintURLFetcher::StartGetRequest( | 23 void CloudPrintURLFetcher::StartGetRequest( |
24 const GURL& url, | 24 const GURL& url, |
25 Delegate* delegate, | 25 Delegate* delegate, |
26 int max_retries, | 26 int max_retries, |
27 const std::string& additional_headers) { | 27 const std::string& additional_headers) { |
28 StartRequestHelper(url, | 28 StartRequestHelper(url, |
29 URLFetcher::GET, | 29 content::URLFetcher::GET, |
30 delegate, | 30 delegate, |
31 max_retries, | 31 max_retries, |
32 std::string(), | 32 std::string(), |
33 std::string(), | 33 std::string(), |
34 additional_headers); | 34 additional_headers); |
35 } | 35 } |
36 | 36 |
37 void CloudPrintURLFetcher::StartPostRequest( | 37 void CloudPrintURLFetcher::StartPostRequest( |
38 const GURL& url, | 38 const GURL& url, |
39 Delegate* delegate, | 39 Delegate* delegate, |
40 int max_retries, | 40 int max_retries, |
41 const std::string& post_data_mime_type, | 41 const std::string& post_data_mime_type, |
42 const std::string& post_data, | 42 const std::string& post_data, |
43 const std::string& additional_headers) { | 43 const std::string& additional_headers) { |
44 StartRequestHelper(url, | 44 StartRequestHelper(url, |
45 URLFetcher::POST, | 45 content::URLFetcher::POST, |
46 delegate, | 46 delegate, |
47 max_retries, | 47 max_retries, |
48 post_data_mime_type, | 48 post_data_mime_type, |
49 post_data, | 49 post_data, |
50 additional_headers); | 50 additional_headers); |
51 } | 51 } |
52 | 52 |
53 void CloudPrintURLFetcher::OnURLFetchComplete( | 53 void CloudPrintURLFetcher::OnURLFetchComplete( |
54 const content::URLFetcher* source) { | 54 const content::URLFetcher* source) { |
55 VLOG(1) << "CP_PROXY: OnURLFetchComplete, url: " << source->GetUrl() | 55 VLOG(1) << "CP_PROXY: OnURLFetchComplete, url: " << source->GetUrl() |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
124 const GURL& url, | 124 const GURL& url, |
125 content::URLFetcher::RequestType request_type, | 125 content::URLFetcher::RequestType request_type, |
126 Delegate* delegate, | 126 Delegate* delegate, |
127 int max_retries, | 127 int max_retries, |
128 const std::string& post_data_mime_type, | 128 const std::string& post_data_mime_type, |
129 const std::string& post_data, | 129 const std::string& post_data, |
130 const std::string& additional_headers) { | 130 const std::string& additional_headers) { |
131 DCHECK(delegate); | 131 DCHECK(delegate); |
132 // Persist the additional headers in case we need to retry the request. | 132 // Persist the additional headers in case we need to retry the request. |
133 additional_headers_ = additional_headers; | 133 additional_headers_ = additional_headers; |
134 request_.reset(new URLFetcher(url, request_type, this)); | 134 request_.reset(content::URLFetcher::Create(url, request_type, this)); |
135 request_->SetRequestContext(GetRequestContextGetter()); | 135 request_->SetRequestContext(GetRequestContextGetter()); |
136 // Since we implement our own retry logic, disable the retry in URLFetcher. | 136 // Since we implement our own retry logic, disable the retry in URLFetcher. |
137 request_->SetAutomaticallyRetryOn5xx(false); | 137 request_->SetAutomaticallyRetryOn5xx(false); |
138 request_->SetMaxRetries(max_retries); | 138 request_->SetMaxRetries(max_retries); |
139 SetupRequestHeaders(); | 139 SetupRequestHeaders(); |
140 delegate_ = delegate; | 140 delegate_ = delegate; |
141 if (request_type == URLFetcher::POST) { | 141 if (request_type == content::URLFetcher::POST) { |
142 request_->SetUploadData(post_data_mime_type, post_data); | 142 request_->SetUploadData(post_data_mime_type, post_data); |
143 } | 143 } |
144 | 144 |
145 request_->Start(); | 145 request_->Start(); |
146 } | 146 } |
147 | 147 |
148 void CloudPrintURLFetcher::SetupRequestHeaders() { | 148 void CloudPrintURLFetcher::SetupRequestHeaders() { |
149 std::string headers; | 149 std::string headers; |
150 CloudPrintTokenStore* token_store = CloudPrintTokenStore::current(); | 150 CloudPrintTokenStore* token_store = CloudPrintTokenStore::current(); |
151 if (token_store) { | 151 if (token_store) { |
(...skipping 14 matching lines...) Expand all Loading... |
166 | 166 |
167 net::URLRequestContextGetter* CloudPrintURLFetcher::GetRequestContextGetter() { | 167 net::URLRequestContextGetter* CloudPrintURLFetcher::GetRequestContextGetter() { |
168 ServiceURLRequestContextGetter* getter = | 168 ServiceURLRequestContextGetter* getter = |
169 g_service_process->GetServiceURLRequestContextGetter(); | 169 g_service_process->GetServiceURLRequestContextGetter(); |
170 // Now set up the user agent for cloudprint. | 170 // Now set up the user agent for cloudprint. |
171 std::string user_agent = getter->user_agent(); | 171 std::string user_agent = getter->user_agent(); |
172 base::StringAppendF(&user_agent, " %s", kCloudPrintUserAgent); | 172 base::StringAppendF(&user_agent, " %s", kCloudPrintUserAgent); |
173 getter->set_user_agent(user_agent); | 173 getter->set_user_agent(user_agent); |
174 return getter; | 174 return getter; |
175 } | 175 } |
OLD | NEW |