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" |
11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
12 #include "net/url_request/url_fetcher.h" | 12 #include "net/url_request/url_fetcher.h" |
13 #include "net/url_request/url_fetcher_delegate.h" | 13 #include "net/url_request/url_fetcher_delegate.h" |
14 | 14 |
15 class GURL; | 15 class GURL; |
16 | 16 |
17 namespace base { | 17 namespace base { |
18 class DictionaryValue; | 18 class DictionaryValue; |
19 } | 19 } |
20 | 20 |
21 namespace net { | 21 namespace net { |
22 class URLRequestContextGetter; | 22 class URLRequestContextGetter; |
23 class URLRequestStatus; | 23 class URLRequestStatus; |
24 } // namespace net | 24 } // namespace net |
25 | 25 |
26 namespace cloud_print { | 26 namespace cloud_print { |
27 | 27 |
28 | |
gene
2013/02/11 23:34:05
one empty line is enough here
| |
29 // Factory for creating CloudPrintURLFetchers. | |
30 class CloudPrintURLFetcher; | |
31 class CloudPrintURLFetcherFactory { | |
32 public: | |
33 CloudPrintURLFetcherFactory(); | |
gene
2013/02/11 23:34:05
May be we can omit constructor/destructor here?
| |
34 virtual ~CloudPrintURLFetcherFactory(); | |
35 virtual CloudPrintURLFetcher* CreateCloudPrintURLFetcher()=0; | |
gene
2013/02/11 23:34:05
add spaces around =. "() = 0;"
| |
36 }; | |
37 | |
38 | |
gene
2013/02/11 23:34:05
one empty line is enough here
| |
28 // A wrapper around URLFetcher for CloudPrint. URLFetcher applies retry logic | 39 // A wrapper around URLFetcher for CloudPrint. URLFetcher applies retry logic |
29 // only on HTTP response codes >= 500. In the cloud print case, we want to | 40 // only on HTTP response codes >= 500. In the cloud print case, we want to |
30 // retry on all network errors. In addition, we want to treat non-JSON responses | 41 // retry on all network errors. In addition, we want to treat non-JSON responses |
31 // (for all CloudPrint APIs that expect JSON responses) as errors and they | 42 // (for all CloudPrint APIs that expect JSON responses) as errors and they |
32 // must also be retried. | 43 // must also be retried. |
33 class CloudPrintURLFetcher | 44 class CloudPrintURLFetcher |
34 : public base::RefCountedThreadSafe<CloudPrintURLFetcher>, | 45 : public base::RefCountedThreadSafe<CloudPrintURLFetcher>, |
35 public net::URLFetcherDelegate { | 46 public net::URLFetcherDelegate { |
36 public: | 47 public: |
37 enum ResponseAction { | 48 enum ResponseAction { |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
85 // Returning CONTINUE_PROCESSING will treat auth error as a network error. | 96 // Returning CONTINUE_PROCESSING will treat auth error as a network error. |
86 virtual ResponseAction OnRequestAuthError() = 0; | 97 virtual ResponseAction OnRequestAuthError() = 0; |
87 | 98 |
88 // Authentication information may change between retries. | 99 // Authentication information may change between retries. |
89 // CloudPrintURLFetcher will request auth info before sending any request. | 100 // CloudPrintURLFetcher will request auth info before sending any request. |
90 virtual std::string GetAuthHeader() = 0; | 101 virtual std::string GetAuthHeader() = 0; |
91 | 102 |
92 protected: | 103 protected: |
93 virtual ~Delegate() {} | 104 virtual ~Delegate() {} |
94 }; | 105 }; |
106 | |
107 static CloudPrintURLFetcher* Create(); | |
108 static void set_factory(CloudPrintURLFetcherFactory* factory); | |
109 | |
95 CloudPrintURLFetcher(); | 110 CloudPrintURLFetcher(); |
gene
2013/02/11 23:34:05
Constructor should probably be in protected sectio
| |
96 | 111 |
97 bool IsSameRequest(const net::URLFetcher* source); | 112 bool IsSameRequest(const net::URLFetcher* source); |
98 | 113 |
99 void StartGetRequest(const GURL& url, | 114 void StartGetRequest(const GURL& url, |
100 Delegate* delegate, | 115 Delegate* delegate, |
101 int max_retries, | 116 int max_retries, |
102 const std::string& additional_headers); | 117 const std::string& additional_headers); |
103 void StartPostRequest(const GURL& url, | 118 void StartPostRequest(const GURL& url, |
104 Delegate* delegate, | 119 Delegate* delegate, |
105 int max_retries, | 120 int max_retries, |
(...skipping 21 matching lines...) Expand all Loading... | |
127 const std::string& additional_headers); | 142 const std::string& additional_headers); |
128 void SetupRequestHeaders(); | 143 void SetupRequestHeaders(); |
129 | 144 |
130 scoped_ptr<net::URLFetcher> request_; | 145 scoped_ptr<net::URLFetcher> request_; |
131 Delegate* delegate_; | 146 Delegate* delegate_; |
132 int num_retries_; | 147 int num_retries_; |
133 net::URLFetcher::RequestType request_type_; | 148 net::URLFetcher::RequestType request_type_; |
134 std::string additional_headers_; | 149 std::string additional_headers_; |
135 std::string post_data_mime_type_; | 150 std::string post_data_mime_type_; |
136 std::string post_data_; | 151 std::string post_data_; |
152 | |
153 static CloudPrintURLFetcherFactory* factory(); | |
gene
2013/02/11 23:34:05
Can you move this before declaring member variable
| |
137 }; | 154 }; |
138 | 155 |
139 typedef CloudPrintURLFetcher::Delegate CloudPrintURLFetcherDelegate; | 156 typedef CloudPrintURLFetcher::Delegate CloudPrintURLFetcherDelegate; |
140 | 157 |
141 } // namespace cloud_print | 158 } // namespace cloud_print |
142 | 159 |
143 #endif // CHROME_SERVICE_CLOUD_PRINT_CLOUD_PRINT_URL_FETCHER_H_ | 160 #endif // CHROME_SERVICE_CLOUD_PRINT_CLOUD_PRINT_URL_FETCHER_H_ |
OLD | NEW |