Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(370)

Side by Side Diff: chrome/service/cloud_print/cloud_print_url_fetcher.h

Issue 12208089: Changing CloudPrintURLFetcher instantiation to be more testable (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Incorporated Gene's suggestions Created 7 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 // Factory for creating CloudPrintURLFetchers.
29 class CloudPrintURLFetcher;
30 class CloudPrintURLFetcherFactory {
31 public:
32 virtual CloudPrintURLFetcher* CreateCloudPrintURLFetcher() = 0;
33 };
34
28 // A wrapper around URLFetcher for CloudPrint. URLFetcher applies retry logic 35 // 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 36 // 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 37 // 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 38 // (for all CloudPrint APIs that expect JSON responses) as errors and they
32 // must also be retried. 39 // must also be retried.
33 class CloudPrintURLFetcher 40 class CloudPrintURLFetcher
34 : public base::RefCountedThreadSafe<CloudPrintURLFetcher>, 41 : public base::RefCountedThreadSafe<CloudPrintURLFetcher>,
35 public net::URLFetcherDelegate { 42 public net::URLFetcherDelegate {
36 public: 43 public:
37 enum ResponseAction { 44 enum ResponseAction {
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
85 // Returning CONTINUE_PROCESSING will treat auth error as a network error. 92 // Returning CONTINUE_PROCESSING will treat auth error as a network error.
86 virtual ResponseAction OnRequestAuthError() = 0; 93 virtual ResponseAction OnRequestAuthError() = 0;
87 94
88 // Authentication information may change between retries. 95 // Authentication information may change between retries.
89 // CloudPrintURLFetcher will request auth info before sending any request. 96 // CloudPrintURLFetcher will request auth info before sending any request.
90 virtual std::string GetAuthHeader() = 0; 97 virtual std::string GetAuthHeader() = 0;
91 98
92 protected: 99 protected:
93 virtual ~Delegate() {} 100 virtual ~Delegate() {}
94 }; 101 };
95 CloudPrintURLFetcher(); 102
103 static CloudPrintURLFetcher* Create();
104 static void set_factory(CloudPrintURLFetcherFactory* factory);
96 105
97 bool IsSameRequest(const net::URLFetcher* source); 106 bool IsSameRequest(const net::URLFetcher* source);
98 107
99 void StartGetRequest(const GURL& url, 108 void StartGetRequest(const GURL& url,
100 Delegate* delegate, 109 Delegate* delegate,
101 int max_retries, 110 int max_retries,
102 const std::string& additional_headers); 111 const std::string& additional_headers);
103 void StartPostRequest(const GURL& url, 112 void StartPostRequest(const GURL& url,
104 Delegate* delegate, 113 Delegate* delegate,
105 int max_retries, 114 int max_retries,
106 const std::string& post_data_mime_type, 115 const std::string& post_data_mime_type,
107 const std::string& post_data, 116 const std::string& post_data,
108 const std::string& additional_headers); 117 const std::string& additional_headers);
109 118
110 // net::URLFetcherDelegate implementation. 119 // net::URLFetcherDelegate implementation.
111 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE; 120 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE;
112 121
113 protected: 122 protected:
123 CloudPrintURLFetcher();
114 friend class base::RefCountedThreadSafe<CloudPrintURLFetcher>; 124 friend class base::RefCountedThreadSafe<CloudPrintURLFetcher>;
115 virtual ~CloudPrintURLFetcher(); 125 virtual ~CloudPrintURLFetcher();
116 126
117 // Virtual for testing. 127 // Virtual for testing.
118 virtual net::URLRequestContextGetter* GetRequestContextGetter(); 128 virtual net::URLRequestContextGetter* GetRequestContextGetter();
119 129
120 private: 130 private:
121 void StartRequestHelper(const GURL& url, 131 void StartRequestHelper(const GURL& url,
122 net::URLFetcher::RequestType request_type, 132 net::URLFetcher::RequestType request_type,
123 Delegate* delegate, 133 Delegate* delegate,
124 int max_retries, 134 int max_retries,
125 const std::string& post_data_mime_type, 135 const std::string& post_data_mime_type,
126 const std::string& post_data, 136 const std::string& post_data,
127 const std::string& additional_headers); 137 const std::string& additional_headers);
128 void SetupRequestHeaders(); 138 void SetupRequestHeaders();
139 static CloudPrintURLFetcherFactory* factory();
129 140
130 scoped_ptr<net::URLFetcher> request_; 141 scoped_ptr<net::URLFetcher> request_;
131 Delegate* delegate_; 142 Delegate* delegate_;
132 int num_retries_; 143 int num_retries_;
133 net::URLFetcher::RequestType request_type_; 144 net::URLFetcher::RequestType request_type_;
134 std::string additional_headers_; 145 std::string additional_headers_;
135 std::string post_data_mime_type_; 146 std::string post_data_mime_type_;
136 std::string post_data_; 147 std::string post_data_;
137 }; 148 };
138 149
139 typedef CloudPrintURLFetcher::Delegate CloudPrintURLFetcherDelegate; 150 typedef CloudPrintURLFetcher::Delegate CloudPrintURLFetcherDelegate;
140 151
141 } // namespace cloud_print 152 } // namespace cloud_print
142 153
143 #endif // CHROME_SERVICE_CLOUD_PRINT_CLOUD_PRINT_URL_FETCHER_H_ 154 #endif // CHROME_SERVICE_CLOUD_PRINT_CLOUD_PRINT_URL_FETCHER_H_
OLDNEW
« no previous file with comments | « chrome/service/cloud_print/cloud_print_connector.cc ('k') | chrome/service/cloud_print/cloud_print_url_fetcher.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698