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

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

Issue 8373021: Convert URLFetcher::Delegates to use an interface in content/public/common. Also remove the old U... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: sync and remove unncessary forward declares Created 9 years, 2 months 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) 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"
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
43 const std::string& additional_headers) { 43 const std::string& additional_headers) {
44 StartRequestHelper(url, 44 StartRequestHelper(url,
45 URLFetcher::POST, 45 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 // URLFetcher::Delegate implementation. 53 void CloudPrintURLFetcher::OnURLFetchComplete(const URLFetcher* source) {
54 void CloudPrintURLFetcher::OnURLFetchComplete( 54 VLOG(1) << "CP_PROXY: OnURLFetchComplete, url: " << source->url()
55 const URLFetcher* source, 55 << ", response code: " << source->response_code();
56 const GURL& url,
57 const net::URLRequestStatus& status,
58 int response_code,
59 const net::ResponseCookies& cookies,
60 const std::string& data) {
61 VLOG(1) << "CP_PROXY: OnURLFetchComplete, url: " << url
62 << ", response code: " << response_code;
63 // Make sure we stay alive through the body of this function. 56 // Make sure we stay alive through the body of this function.
64 scoped_refptr<CloudPrintURLFetcher> keep_alive(this); 57 scoped_refptr<CloudPrintURLFetcher> keep_alive(this);
65 ResponseAction action = delegate_->HandleRawResponse(source, 58 std::string data;
66 url, 59 source->GetResponseAsString(&data);
67 status, 60 ResponseAction action = delegate_->HandleRawResponse(
68 response_code, 61 source,
69 cookies, 62 source->url(),
70 data); 63 source->status(),
64 source->response_code(),
65 source->cookies(),
66 data);
71 if (action == CONTINUE_PROCESSING) { 67 if (action == CONTINUE_PROCESSING) {
72 // If we are not using an OAuth token, and we got an auth error, we are 68 // If we are not using an OAuth token, and we got an auth error, we are
73 // done. Else, the token may have been refreshed. Let us try again. 69 // done. Else, the token may have been refreshed. Let us try again.
74 if ((RC_FORBIDDEN == response_code) && 70 if ((RC_FORBIDDEN == source->response_code()) &&
75 (!CloudPrintTokenStore::current() || 71 (!CloudPrintTokenStore::current() ||
76 !CloudPrintTokenStore::current()->token_is_oauth())) { 72 !CloudPrintTokenStore::current()->token_is_oauth())) {
77 delegate_->OnRequestAuthError(); 73 delegate_->OnRequestAuthError();
78 return; 74 return;
79 } 75 }
80 // We need to retry on all network errors. 76 // We need to retry on all network errors.
81 if (!status.is_success() || (response_code != 200)) 77 if (!source->status().is_success() || (source->response_code() != 200))
82 action = RETRY_REQUEST; 78 action = RETRY_REQUEST;
83 else 79 else
84 action = delegate_->HandleRawData(source, url, data); 80 action = delegate_->HandleRawData(source, source->url(), data);
85 81
86 if (action == CONTINUE_PROCESSING) { 82 if (action == CONTINUE_PROCESSING) {
87 // If the delegate is not interested in handling the raw response data, 83 // 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 84 // 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 85 // response, we will retry (to handle the case where we got redirected
90 // to a non-cloudprint-server URL eg. for authentication). 86 // to a non-cloudprint-server URL eg. for authentication).
91 bool succeeded = false; 87 bool succeeded = false;
92 DictionaryValue* response_dict = NULL; 88 DictionaryValue* response_dict = NULL;
93 CloudPrintHelpers::ParseResponseJSON(data, &succeeded, &response_dict); 89 CloudPrintHelpers::ParseResponseJSON(data, &succeeded, &response_dict);
94 if (response_dict) 90 if (response_dict)
95 action = delegate_->HandleJSONData(source, 91 action = delegate_->HandleJSONData(source,
96 url, 92 source->url(),
97 response_dict, 93 response_dict,
98 succeeded); 94 succeeded);
99 else 95 else
100 action = RETRY_REQUEST; 96 action = RETRY_REQUEST;
101 } 97 }
102 } 98 }
103 // Retry the request if needed. 99 // Retry the request if needed.
104 if (action == RETRY_REQUEST) { 100 if (action == RETRY_REQUEST) {
105 // Explicitly call ReceivedContentWasMalformed() to ensure the current 101 // Explicitly call ReceivedContentWasMalformed() to ensure the current
106 // request gets counted as a failure for calculation of the back-off 102 // request gets counted as a failure for calculation of the back-off
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
169 165
170 net::URLRequestContextGetter* CloudPrintURLFetcher::GetRequestContextGetter() { 166 net::URLRequestContextGetter* CloudPrintURLFetcher::GetRequestContextGetter() {
171 ServiceURLRequestContextGetter* getter = 167 ServiceURLRequestContextGetter* getter =
172 g_service_process->GetServiceURLRequestContextGetter(); 168 g_service_process->GetServiceURLRequestContextGetter();
173 // Now set up the user agent for cloudprint. 169 // Now set up the user agent for cloudprint.
174 std::string user_agent = getter->user_agent(); 170 std::string user_agent = getter->user_agent();
175 base::StringAppendF(&user_agent, " %s", kCloudPrintUserAgent); 171 base::StringAppendF(&user_agent, " %s", kCloudPrintUserAgent);
176 getter->set_user_agent(user_agent); 172 getter->set_user_agent(user_agent);
177 return getter; 173 return getter;
178 } 174 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698