Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(51)

Side by Side Diff: chrome/service/cloud_print/cloud_print_url_fetcher.cc

Issue 11360151: Move common cloud print methods from service/cloud_print to common/cloud_print. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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_helpers.h" 10 #include "chrome/common/cloud_print/cloud_print_helpers.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/base/load_flags.h" 16 #include "net/base/load_flags.h"
17 #include "net/http/http_status_code.h" 17 #include "net/http/http_status_code.h"
18 #include "net/url_request/url_fetcher.h" 18 #include "net/url_request/url_fetcher.h"
19 #include "net/url_request/url_request_status.h" 19 #include "net/url_request/url_request_status.h"
20 20
21 namespace cloud_print {
21 22
22 CloudPrintURLFetcher::ResponseAction 23 CloudPrintURLFetcher::ResponseAction
23 CloudPrintURLFetcher::Delegate::HandleRawResponse( 24 CloudPrintURLFetcher::Delegate::HandleRawResponse(
24 const net::URLFetcher* source, 25 const net::URLFetcher* source,
25 const GURL& url, 26 const GURL& url,
26 const net::URLRequestStatus& status, 27 const net::URLRequestStatus& status,
27 int response_code, 28 int response_code,
28 const net::ResponseCookies& cookies, 29 const net::ResponseCookies& cookies,
29 const std::string& data) { 30 const std::string& data) {
30 return CONTINUE_PROCESSING; 31 return CONTINUE_PROCESSING;
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 else 116 else
116 action = delegate_->HandleRawData(source, source->GetURL(), data); 117 action = delegate_->HandleRawData(source, source->GetURL(), data);
117 118
118 if (action == CONTINUE_PROCESSING) { 119 if (action == CONTINUE_PROCESSING) {
119 // If the delegate is not interested in handling the raw response data, 120 // If the delegate is not interested in handling the raw response data,
120 // we assume that a JSON response is expected. If we do not get a JSON 121 // we assume that a JSON response is expected. If we do not get a JSON
121 // response, we will retry (to handle the case where we got redirected 122 // response, we will retry (to handle the case where we got redirected
122 // to a non-cloudprint-server URL eg. for authentication). 123 // to a non-cloudprint-server URL eg. for authentication).
123 bool succeeded = false; 124 bool succeeded = false;
124 DictionaryValue* response_dict = NULL; 125 DictionaryValue* response_dict = NULL;
125 cloud_print::ParseResponseJSON(data, &succeeded, &response_dict); 126 ParseResponseJSON(data, &succeeded, &response_dict);
126 if (response_dict) 127 if (response_dict)
127 action = delegate_->HandleJSONData(source, 128 action = delegate_->HandleJSONData(source,
128 source->GetURL(), 129 source->GetURL(),
129 response_dict, 130 response_dict,
130 succeeded); 131 succeeded);
131 else 132 else
132 action = RETRY_REQUEST; 133 action = RETRY_REQUEST;
133 } 134 }
134 } 135 }
135 // Retry the request if needed. 136 // Retry the request if needed.
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
186 request_->SetUploadData(post_data_mime_type, post_data); 187 request_->SetUploadData(post_data_mime_type, post_data);
187 } 188 }
188 189
189 request_->Start(); 190 request_->Start();
190 } 191 }
191 192
192 void CloudPrintURLFetcher::SetupRequestHeaders() { 193 void CloudPrintURLFetcher::SetupRequestHeaders() {
193 std::string headers = delegate_->GetAuthHeader(); 194 std::string headers = delegate_->GetAuthHeader();
194 if (!headers.empty()) 195 if (!headers.empty())
195 headers += "\r\n"; 196 headers += "\r\n";
196 headers += cloud_print::kChromeCloudPrintProxyHeader; 197 headers += kChromeCloudPrintProxyHeader;
197 if (!additional_headers_.empty()) { 198 if (!additional_headers_.empty()) {
198 headers += "\r\n"; 199 headers += "\r\n";
199 headers += additional_headers_; 200 headers += additional_headers_;
200 } 201 }
201 request_->SetExtraRequestHeaders(headers); 202 request_->SetExtraRequestHeaders(headers);
202 } 203 }
203 204
204 CloudPrintURLFetcher::~CloudPrintURLFetcher() {} 205 CloudPrintURLFetcher::~CloudPrintURLFetcher() {}
205 206
206 net::URLRequestContextGetter* CloudPrintURLFetcher::GetRequestContextGetter() { 207 net::URLRequestContextGetter* CloudPrintURLFetcher::GetRequestContextGetter() {
207 ServiceURLRequestContextGetter* getter = 208 ServiceURLRequestContextGetter* getter =
208 g_service_process->GetServiceURLRequestContextGetter(); 209 g_service_process->GetServiceURLRequestContextGetter();
209 // Now set up the user agent for cloudprint. 210 // Now set up the user agent for cloudprint.
210 std::string user_agent = getter->user_agent(); 211 std::string user_agent = getter->user_agent();
211 base::StringAppendF(&user_agent, " %s", kCloudPrintUserAgent); 212 base::StringAppendF(&user_agent, " %s", kCloudPrintUserAgent);
212 getter->set_user_agent(user_agent); 213 getter->set_user_agent(user_agent);
213 return getter; 214 return getter;
214 } 215 }
216
217 } // namespace cloud_print
OLDNEW
« no previous file with comments | « chrome/service/cloud_print/cloud_print_url_fetcher.h ('k') | chrome/service/cloud_print/cloud_print_url_fetcher_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698