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 #ifndef CHROME_SERVICE_CLOUD_PRINT_CLOUD_PRINT_URL_FETCHER_H_ | 5 #ifndef CHROME_SERVICE_CLOUD_PRINT_CLOUD_PRINT_URL_FETCHER_H_ |
6 #define CHROME_SERVICE_CLOUD_PRINT_CLOUD_PRINT_URL_FETCHER_H_ | 6 #define CHROME_SERVICE_CLOUD_PRINT_CLOUD_PRINT_URL_FETCHER_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
43 // Override this to handle the raw response as it is available. No response | 43 // Override this to handle the raw response as it is available. No response |
44 // error checking is done before this method is called. If the delegate | 44 // error checking is done before this method is called. If the delegate |
45 // returns CONTINUE_PROCESSING, we will then check for network | 45 // returns CONTINUE_PROCESSING, we will then check for network |
46 // errors. Most implementations will not override this. | 46 // errors. Most implementations will not override this. |
47 virtual ResponseAction HandleRawResponse( | 47 virtual ResponseAction HandleRawResponse( |
48 const net::URLFetcher* source, | 48 const net::URLFetcher* source, |
49 const GURL& url, | 49 const GURL& url, |
50 const net::URLRequestStatus& status, | 50 const net::URLRequestStatus& status, |
51 int response_code, | 51 int response_code, |
52 const net::ResponseCookies& cookies, | 52 const net::ResponseCookies& cookies, |
53 const std::string& data) { | 53 const std::string& data); |
54 return CONTINUE_PROCESSING; | 54 |
55 } | |
56 // This will be invoked only if HandleRawResponse returns | 55 // This will be invoked only if HandleRawResponse returns |
57 // CONTINUE_PROCESSING AND if there are no network errors and the HTTP | 56 // CONTINUE_PROCESSING AND if there are no network errors and the HTTP |
58 // response code is 200. The delegate implementation returns | 57 // response code is 200. The delegate implementation returns |
59 // CONTINUE_PROCESSING if it does not want to handle the raw data itself. | 58 // CONTINUE_PROCESSING if it does not want to handle the raw data itself. |
60 // Handling the raw data is needed when the expected response is NOT JSON | 59 // Handling the raw data is needed when the expected response is NOT JSON |
61 // (like in the case of a print ticket response or a print job download | 60 // (like in the case of a print ticket response or a print job download |
62 // response). | 61 // response). |
63 virtual ResponseAction HandleRawData(const net::URLFetcher* source, | 62 virtual ResponseAction HandleRawData(const net::URLFetcher* source, |
64 const GURL& url, | 63 const GURL& url, |
65 const std::string& data) { | 64 const std::string& data); |
66 return CONTINUE_PROCESSING; | 65 |
67 } | |
68 // This will be invoked only if HandleRawResponse and HandleRawData return | 66 // This will be invoked only if HandleRawResponse and HandleRawData return |
69 // CONTINUE_PROCESSING AND if the response contains a valid JSON dictionary. | 67 // CONTINUE_PROCESSING AND if the response contains a valid JSON dictionary. |
70 // |succeeded| is the value of the "success" field in the response JSON. | 68 // |succeeded| is the value of the "success" field in the response JSON. |
71 virtual ResponseAction HandleJSONData(const net::URLFetcher* source, | 69 virtual ResponseAction HandleJSONData(const net::URLFetcher* source, |
72 const GURL& url, | 70 const GURL& url, |
73 base::DictionaryValue* json_data, | 71 base::DictionaryValue* json_data, |
74 bool succeeded) { | 72 bool succeeded); |
75 return CONTINUE_PROCESSING; | 73 |
76 } | |
77 // Invoked when the retry limit for this request has been reached (if there | 74 // Invoked when the retry limit for this request has been reached (if there |
78 // was a retry limit - a limit of -1 implies no limit). | 75 // was a retry limit - a limit of -1 implies no limit). |
79 virtual void OnRequestGiveUp() { } | 76 virtual void OnRequestGiveUp() { } |
| 77 |
80 // Invoked when the request returns a 403 error (applicable only when | 78 // Invoked when the request returns a 403 error (applicable only when |
81 // HandleRawResponse returns CONTINUE_PROCESSING). | 79 // HandleRawResponse returns CONTINUE_PROCESSING). |
82 // Returning RETRY_REQUEST will retry current request. (auth information | 80 // Returning RETRY_REQUEST will retry current request. (auth information |
83 // may have been updated and new info is available through the | 81 // may have been updated and new info is available through the |
84 // Authenticator interface). | 82 // Authenticator interface). |
85 // Returning CONTINUE_PROCESSING will treat auth error as a network error. | 83 // Returning CONTINUE_PROCESSING will treat auth error as a network error. |
86 virtual ResponseAction OnRequestAuthError() = 0; | 84 virtual ResponseAction OnRequestAuthError() = 0; |
87 | 85 |
88 // Authentication information may change between retries. | 86 // Authentication information may change between retries. |
89 // CloudPrintURLFetcher will request auth info before sending any request. | 87 // CloudPrintURLFetcher will request auth info before sending any request. |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
132 int num_retries_; | 130 int num_retries_; |
133 net::URLFetcher::RequestType request_type_; | 131 net::URLFetcher::RequestType request_type_; |
134 std::string additional_headers_; | 132 std::string additional_headers_; |
135 std::string post_data_mime_type_; | 133 std::string post_data_mime_type_; |
136 std::string post_data_; | 134 std::string post_data_; |
137 }; | 135 }; |
138 | 136 |
139 typedef CloudPrintURLFetcher::Delegate CloudPrintURLFetcherDelegate; | 137 typedef CloudPrintURLFetcher::Delegate CloudPrintURLFetcherDelegate; |
140 | 138 |
141 #endif // CHROME_SERVICE_CLOUD_PRINT_CLOUD_PRINT_URL_FETCHER_H_ | 139 #endif // CHROME_SERVICE_CLOUD_PRINT_CLOUD_PRINT_URL_FETCHER_H_ |
OLD | NEW |