| 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 #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/ref_counted.h" |
| 12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
| 13 #include "content/public/common/url_fetcher.h" | 13 #include "content/public/common/url_fetcher.h" |
| 14 #include "content/public/common/url_fetcher_delegate.h" | 14 #include "net/url_request/url_fetcher_delegate.h" |
| 15 | 15 |
| 16 class GURL; | 16 class GURL; |
| 17 | 17 |
| 18 namespace base { | 18 namespace base { |
| 19 class DictionaryValue; | 19 class DictionaryValue; |
| 20 } | 20 } |
| 21 | 21 |
| 22 namespace net { | 22 namespace net { |
| 23 class URLRequestContextGetter; | 23 class URLRequestContextGetter; |
| 24 class URLRequestStatus; | 24 class URLRequestStatus; |
| 25 } // namespace net | 25 } // namespace net |
| 26 | 26 |
| 27 // A wrapper around URLFetcher for CloudPrint. URLFetcher applies retry logic | 27 // A wrapper around URLFetcher for CloudPrint. URLFetcher applies retry logic |
| 28 // 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 |
| 29 // 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 |
| 30 // (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 |
| 31 // must also be retried. | 31 // must also be retried. |
| 32 class CloudPrintURLFetcher | 32 class CloudPrintURLFetcher |
| 33 : public base::RefCountedThreadSafe<CloudPrintURLFetcher>, | 33 : public base::RefCountedThreadSafe<CloudPrintURLFetcher>, |
| 34 public content::URLFetcherDelegate { | 34 public net::URLFetcherDelegate { |
| 35 public: | 35 public: |
| 36 enum ResponseAction { | 36 enum ResponseAction { |
| 37 CONTINUE_PROCESSING, | 37 CONTINUE_PROCESSING, |
| 38 STOP_PROCESSING, | 38 STOP_PROCESSING, |
| 39 RETRY_REQUEST, | 39 RETRY_REQUEST, |
| 40 }; | 40 }; |
| 41 | 41 |
| 42 class Delegate { | 42 class Delegate { |
| 43 public: | 43 public: |
| 44 virtual ~Delegate() { } | 44 virtual ~Delegate() { } |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 99 Delegate* delegate, | 99 Delegate* delegate, |
| 100 int max_retries, | 100 int max_retries, |
| 101 const std::string& additional_headers); | 101 const std::string& additional_headers); |
| 102 void StartPostRequest(const GURL& url, | 102 void StartPostRequest(const GURL& url, |
| 103 Delegate* delegate, | 103 Delegate* delegate, |
| 104 int max_retries, | 104 int max_retries, |
| 105 const std::string& post_data_mime_type, | 105 const std::string& post_data_mime_type, |
| 106 const std::string& post_data, | 106 const std::string& post_data, |
| 107 const std::string& additional_headers); | 107 const std::string& additional_headers); |
| 108 | 108 |
| 109 // content::URLFetcherDelegate implementation. | 109 // net::URLFetcherDelegate implementation. |
| 110 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE; | 110 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE; |
| 111 | 111 |
| 112 protected: | 112 protected: |
| 113 friend class base::RefCountedThreadSafe<CloudPrintURLFetcher>; | 113 friend class base::RefCountedThreadSafe<CloudPrintURLFetcher>; |
| 114 virtual ~CloudPrintURLFetcher(); | 114 virtual ~CloudPrintURLFetcher(); |
| 115 | 115 |
| 116 // Virtual for testing. | 116 // Virtual for testing. |
| 117 virtual net::URLRequestContextGetter* GetRequestContextGetter(); | 117 virtual net::URLRequestContextGetter* GetRequestContextGetter(); |
| 118 | 118 |
| 119 private: | 119 private: |
| (...skipping 11 matching lines...) Expand all Loading... |
| 131 int num_retries_; | 131 int num_retries_; |
| 132 content::URLFetcher::RequestType request_type_; | 132 content::URLFetcher::RequestType request_type_; |
| 133 std::string additional_headers_; | 133 std::string additional_headers_; |
| 134 std::string post_data_mime_type_; | 134 std::string post_data_mime_type_; |
| 135 std::string post_data_; | 135 std::string post_data_; |
| 136 }; | 136 }; |
| 137 | 137 |
| 138 typedef CloudPrintURLFetcher::Delegate CloudPrintURLFetcherDelegate; | 138 typedef CloudPrintURLFetcher::Delegate CloudPrintURLFetcherDelegate; |
| 139 | 139 |
| 140 #endif // CHROME_SERVICE_CLOUD_PRINT_CLOUD_PRINT_URL_FETCHER_H_ | 140 #endif // CHROME_SERVICE_CLOUD_PRINT_CLOUD_PRINT_URL_FETCHER_H_ |
| OLD | NEW |