| 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/ref_counted.h" |
| 11 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
| 12 #include "content/common/net/url_fetcher.h" | 13 #include "content/common/net/url_fetcher.h" |
| 14 #include "content/public/common/url_fetcher_delegate.h" |
| 13 | 15 |
| 14 class GURL; | 16 class GURL; |
| 15 | 17 |
| 16 namespace base { | 18 namespace base { |
| 17 class DictionaryValue; | 19 class DictionaryValue; |
| 18 } | 20 } |
| 19 | 21 |
| 20 namespace net { | 22 namespace net { |
| 23 class URLRequestContextGetter; |
| 21 class URLRequestStatus; | 24 class URLRequestStatus; |
| 22 } // namespace net | 25 } // namespace net |
| 23 | 26 |
| 24 // A wrapper around URLFetcher for CloudPrint. URLFetcher applies retry logic | 27 // A wrapper around URLFetcher for CloudPrint. URLFetcher applies retry logic |
| 25 // only on HTTP response codes >= 500. In the cloud print case, we want to | 28 // only on HTTP response codes >= 500. In the cloud print case, we want to |
| 26 // retry on all network errors. In addition, we want to treat non-JSON responses | 29 // retry on all network errors. In addition, we want to treat non-JSON responses |
| 27 // (for all CloudPrint APIs that expect JSON responses) as errors and they | 30 // (for all CloudPrint APIs that expect JSON responses) as errors and they |
| 28 // must also be retried. | 31 // must also be retried. |
| 29 class CloudPrintURLFetcher | 32 class CloudPrintURLFetcher |
| 30 : public base::RefCountedThreadSafe<CloudPrintURLFetcher>, | 33 : public base::RefCountedThreadSafe<CloudPrintURLFetcher>, |
| 31 public URLFetcher::Delegate { | 34 public content::URLFetcherDelegate { |
| 32 public: | 35 public: |
| 33 enum ResponseAction { | 36 enum ResponseAction { |
| 34 CONTINUE_PROCESSING, | 37 CONTINUE_PROCESSING, |
| 35 STOP_PROCESSING, | 38 STOP_PROCESSING, |
| 36 RETRY_REQUEST, | 39 RETRY_REQUEST, |
| 37 }; | 40 }; |
| 38 class Delegate { | 41 class Delegate { |
| 39 public: | 42 public: |
| 40 virtual ~Delegate() { } | 43 virtual ~Delegate() { } |
| 41 // Override this to handle the raw response as it is available. No response | 44 // Override this to handle the raw response as it is available. No response |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 85 Delegate* delegate, | 88 Delegate* delegate, |
| 86 int max_retries, | 89 int max_retries, |
| 87 const std::string& additional_headers); | 90 const std::string& additional_headers); |
| 88 void StartPostRequest(const GURL& url, | 91 void StartPostRequest(const GURL& url, |
| 89 Delegate* delegate, | 92 Delegate* delegate, |
| 90 int max_retries, | 93 int max_retries, |
| 91 const std::string& post_data_mime_type, | 94 const std::string& post_data_mime_type, |
| 92 const std::string& post_data, | 95 const std::string& post_data, |
| 93 const std::string& additional_headers); | 96 const std::string& additional_headers); |
| 94 | 97 |
| 95 // URLFetcher::Delegate implementation. | 98 // content::URLFetcherDelegate implementation. |
| 96 virtual void OnURLFetchComplete(const URLFetcher* source, const GURL& url, | 99 virtual void OnURLFetchComplete(const URLFetcher* source); |
| 97 const net::URLRequestStatus& status, | 100 |
| 98 int response_code, | |
| 99 const net::ResponseCookies& cookies, | |
| 100 const std::string& data); | |
| 101 protected: | 101 protected: |
| 102 friend class base::RefCountedThreadSafe<CloudPrintURLFetcher>; | 102 friend class base::RefCountedThreadSafe<CloudPrintURLFetcher>; |
| 103 virtual ~CloudPrintURLFetcher(); | 103 virtual ~CloudPrintURLFetcher(); |
| 104 | 104 |
| 105 // Virtual for testing. | 105 // Virtual for testing. |
| 106 virtual net::URLRequestContextGetter* GetRequestContextGetter(); | 106 virtual net::URLRequestContextGetter* GetRequestContextGetter(); |
| 107 | 107 |
| 108 private: | 108 private: |
| 109 void StartRequestHelper(const GURL& url, | 109 void StartRequestHelper(const GURL& url, |
| 110 URLFetcher::RequestType request_type, | 110 URLFetcher::RequestType request_type, |
| 111 Delegate* delegate, | 111 Delegate* delegate, |
| 112 int max_retries, | 112 int max_retries, |
| 113 const std::string& post_data_mime_type, | 113 const std::string& post_data_mime_type, |
| 114 const std::string& post_data, | 114 const std::string& post_data, |
| 115 const std::string& additional_headers); | 115 const std::string& additional_headers); |
| 116 void SetupRequestHeaders(); | 116 void SetupRequestHeaders(); |
| 117 | 117 |
| 118 scoped_ptr<URLFetcher> request_; | 118 scoped_ptr<URLFetcher> request_; |
| 119 Delegate* delegate_; | 119 Delegate* delegate_; |
| 120 int num_retries_; | 120 int num_retries_; |
| 121 URLFetcher::RequestType request_type_; | 121 URLFetcher::RequestType request_type_; |
| 122 std::string additional_headers_; | 122 std::string additional_headers_; |
| 123 std::string post_data_mime_type_; | 123 std::string post_data_mime_type_; |
| 124 std::string post_data_; | 124 std::string post_data_; |
| 125 }; | 125 }; |
| 126 | 126 |
| 127 typedef CloudPrintURLFetcher::Delegate CloudPrintURLFetcherDelegate; | 127 typedef CloudPrintURLFetcher::Delegate CloudPrintURLFetcherDelegate; |
| 128 | 128 |
| 129 #endif // CHROME_SERVICE_CLOUD_PRINT_CLOUD_PRINT_URL_FETCHER_H_ | 129 #endif // CHROME_SERVICE_CLOUD_PRINT_CLOUD_PRINT_URL_FETCHER_H_ |
| OLD | NEW |