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 #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 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <string> | 9 #include <string> |
10 | 10 |
11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
12 #include "content/common/url_fetcher.h" | 12 #include "content/common/url_fetcher.h" |
13 | 13 |
| 14 class GURL; |
| 15 |
| 16 namespace base { |
14 class DictionaryValue; | 17 class DictionaryValue; |
15 class GURL; | 18 } |
16 | 19 |
17 namespace net { | 20 namespace net { |
18 class URLRequestStatus; | 21 class URLRequestStatus; |
19 } // namespace net | 22 } // namespace net |
20 | 23 |
21 // A wrapper around URLFetcher for CloudPrint. URLFetcher applies retry logic | 24 // A wrapper around URLFetcher for CloudPrint. URLFetcher applies retry logic |
22 // only on HTTP response codes >= 500. In the cloud print case, we want to | 25 // only on HTTP response codes >= 500. In the cloud print case, we want to |
23 // retry on all network errors. In addition, we want to treat non-JSON responses | 26 // retry on all network errors. In addition, we want to treat non-JSON responses |
24 // (for all CloudPrint APIs that expect JSON responses) as errors and they | 27 // (for all CloudPrint APIs that expect JSON responses) as errors and they |
25 // must also be retried. | 28 // must also be retried. |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
58 virtual ResponseAction HandleRawData(const URLFetcher* source, | 61 virtual ResponseAction HandleRawData(const URLFetcher* source, |
59 const GURL& url, | 62 const GURL& url, |
60 const std::string& data) { | 63 const std::string& data) { |
61 return CONTINUE_PROCESSING; | 64 return CONTINUE_PROCESSING; |
62 } | 65 } |
63 // This will be invoked only if HandleRawResponse and HandleRawData return | 66 // This will be invoked only if HandleRawResponse and HandleRawData return |
64 // CONTINUE_PROCESSING AND if the response contains a valid JSON dictionary. | 67 // CONTINUE_PROCESSING AND if the response contains a valid JSON dictionary. |
65 // |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. |
66 virtual ResponseAction HandleJSONData(const URLFetcher* source, | 69 virtual ResponseAction HandleJSONData(const URLFetcher* source, |
67 const GURL& url, | 70 const GURL& url, |
68 DictionaryValue* json_data, | 71 base::DictionaryValue* json_data, |
69 bool succeeded) { | 72 bool succeeded) { |
70 return CONTINUE_PROCESSING; | 73 return CONTINUE_PROCESSING; |
71 } | 74 } |
72 // Invoked when the retry limit for this request has been reached (if there | 75 // Invoked when the retry limit for this request has been reached (if there |
73 // was a retry limit - a limit of -1 implies no limit). | 76 // was a retry limit - a limit of -1 implies no limit). |
74 virtual void OnRequestGiveUp() { } | 77 virtual void OnRequestGiveUp() { } |
75 // Invoked when the request returns a 403 error (applicable only when | 78 // Invoked when the request returns a 403 error (applicable only when |
76 // HandleRawResponse returns CONTINUE_PROCESSING). | 79 // HandleRawResponse returns CONTINUE_PROCESSING). |
77 virtual void OnRequestAuthError() = 0; | 80 virtual void OnRequestAuthError() = 0; |
78 }; | 81 }; |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
117 int num_retries_; | 120 int num_retries_; |
118 URLFetcher::RequestType request_type_; | 121 URLFetcher::RequestType request_type_; |
119 std::string additional_headers_; | 122 std::string additional_headers_; |
120 std::string post_data_mime_type_; | 123 std::string post_data_mime_type_; |
121 std::string post_data_; | 124 std::string post_data_; |
122 }; | 125 }; |
123 | 126 |
124 typedef CloudPrintURLFetcher::Delegate CloudPrintURLFetcherDelegate; | 127 typedef CloudPrintURLFetcher::Delegate CloudPrintURLFetcherDelegate; |
125 | 128 |
126 #endif // CHROME_SERVICE_CLOUD_PRINT_CLOUD_PRINT_URL_FETCHER_H_ | 129 #endif // CHROME_SERVICE_CLOUD_PRINT_CLOUD_PRINT_URL_FETCHER_H_ |
OLD | NEW |