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/service/cloud_print/cloud_print_consts.h" | 10 #include "chrome/service/cloud_print/cloud_print_consts.h" |
10 #include "chrome/service/cloud_print/cloud_print_helpers.h" | 11 #include "chrome/service/cloud_print/cloud_print_helpers.h" |
11 #include "chrome/service/cloud_print/cloud_print_token_store.h" | 12 #include "chrome/service/cloud_print/cloud_print_token_store.h" |
12 #include "chrome/service/net/service_url_request_context.h" | 13 #include "chrome/service/net/service_url_request_context.h" |
13 #include "chrome/service/service_process.h" | 14 #include "chrome/service/service_process.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() |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
83 else | 84 else |
84 action = delegate_->HandleRawData(source, source->GetURL(), data); | 85 action = delegate_->HandleRawData(source, source->GetURL(), data); |
85 | 86 |
86 if (action == CONTINUE_PROCESSING) { | 87 if (action == CONTINUE_PROCESSING) { |
87 // If the delegate is not interested in handling the raw response data, | 88 // If the delegate is not interested in handling the raw response data, |
88 // we assume that a JSON response is expected. If we do not get a JSON | 89 // we assume that a JSON response is expected. If we do not get a JSON |
89 // response, we will retry (to handle the case where we got redirected | 90 // response, we will retry (to handle the case where we got redirected |
90 // to a non-cloudprint-server URL eg. for authentication). | 91 // to a non-cloudprint-server URL eg. for authentication). |
91 bool succeeded = false; | 92 bool succeeded = false; |
92 DictionaryValue* response_dict = NULL; | 93 DictionaryValue* response_dict = NULL; |
93 CloudPrintHelpers::ParseResponseJSON(data, &succeeded, &response_dict); | 94 cloud_print::ParseResponseJSON(data, &succeeded, &response_dict); |
94 if (response_dict) | 95 if (response_dict) |
95 action = delegate_->HandleJSONData(source, | 96 action = delegate_->HandleJSONData(source, |
96 source->GetURL(), | 97 source->GetURL(), |
97 response_dict, | 98 response_dict, |
98 succeeded); | 99 succeeded); |
99 else | 100 else |
100 action = RETRY_REQUEST; | 101 action = RETRY_REQUEST; |
101 } | 102 } |
102 } | 103 } |
103 // Retry the request if needed. | 104 // Retry the request if needed. |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
151 request_->SetUploadData(post_data_mime_type, post_data); | 152 request_->SetUploadData(post_data_mime_type, post_data); |
152 } | 153 } |
153 | 154 |
154 request_->Start(); | 155 request_->Start(); |
155 } | 156 } |
156 | 157 |
157 void CloudPrintURLFetcher::SetupRequestHeaders() { | 158 void CloudPrintURLFetcher::SetupRequestHeaders() { |
158 std::string headers = delegate_->GetAuthHeader(); | 159 std::string headers = delegate_->GetAuthHeader(); |
159 if (!headers.empty()) | 160 if (!headers.empty()) |
160 headers += "\r\n"; | 161 headers += "\r\n"; |
161 headers += kChromeCloudPrintProxyHeader; | 162 headers += cloud_print::kChromeCloudPrintProxyHeader; |
162 if (!additional_headers_.empty()) { | 163 if (!additional_headers_.empty()) { |
163 headers += "\r\n"; | 164 headers += "\r\n"; |
164 headers += additional_headers_; | 165 headers += additional_headers_; |
165 } | 166 } |
166 request_->SetExtraRequestHeaders(headers); | 167 request_->SetExtraRequestHeaders(headers); |
167 } | 168 } |
168 | 169 |
169 CloudPrintURLFetcher::~CloudPrintURLFetcher() {} | 170 CloudPrintURLFetcher::~CloudPrintURLFetcher() {} |
170 | 171 |
171 net::URLRequestContextGetter* CloudPrintURLFetcher::GetRequestContextGetter() { | 172 net::URLRequestContextGetter* CloudPrintURLFetcher::GetRequestContextGetter() { |
172 ServiceURLRequestContextGetter* getter = | 173 ServiceURLRequestContextGetter* getter = |
173 g_service_process->GetServiceURLRequestContextGetter(); | 174 g_service_process->GetServiceURLRequestContextGetter(); |
174 // Now set up the user agent for cloudprint. | 175 // Now set up the user agent for cloudprint. |
175 std::string user_agent = getter->user_agent(); | 176 std::string user_agent = getter->user_agent(); |
176 base::StringAppendF(&user_agent, " %s", kCloudPrintUserAgent); | 177 base::StringAppendF(&user_agent, " %s", kCloudPrintUserAgent); |
177 getter->set_user_agent(user_agent); | 178 getter->set_user_agent(user_agent); |
178 return getter; | 179 return getter; |
179 } | 180 } |
OLD | NEW |