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

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

Issue 6056007: net: Add namespace net to the remaining files under url_request directory. (Closed)
Patch Set: chromeos fixes Created 9 years, 11 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
« no previous file with comments | « chrome/common/security_filter_peer.h ('k') | chrome/service/gaia/service_gaia_authenticator.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2010 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/scoped_ptr.h" 11 #include "base/scoped_ptr.h"
12 #include "chrome/common/net/url_fetcher.h" 12 #include "chrome/common/net/url_fetcher.h"
13 13
14 class DictionaryValue; 14 class DictionaryValue;
15 class GURL; 15 class GURL;
16
17 namespace net {
16 class URLRequestStatus; 18 class URLRequestStatus;
19 } // namespace net
17 20
18 // A wrapper around URLFetcher for CloudPrint. URLFetcher applies retry logic 21 // A wrapper around URLFetcher for CloudPrint. URLFetcher applies retry logic
19 // only on HTTP response codes >= 500. In the cloud print case, we want to 22 // only on HTTP response codes >= 500. In the cloud print case, we want to
20 // retry on all network errors. In addition, we want to treat non-JSON responses 23 // retry on all network errors. In addition, we want to treat non-JSON responses
21 // (for all CloudPrint APIs that expect JSON responses) as errors and they 24 // (for all CloudPrint APIs that expect JSON responses) as errors and they
22 // must also be retried. 25 // must also be retried.
23 class CloudPrintURLFetcher 26 class CloudPrintURLFetcher
24 : public base::RefCountedThreadSafe<CloudPrintURLFetcher>, 27 : public base::RefCountedThreadSafe<CloudPrintURLFetcher>,
25 public URLFetcher::Delegate { 28 public URLFetcher::Delegate {
26 public: 29 public:
27 enum ResponseAction { 30 enum ResponseAction {
28 CONTINUE_PROCESSING, 31 CONTINUE_PROCESSING,
29 STOP_PROCESSING, 32 STOP_PROCESSING,
30 RETRY_REQUEST, 33 RETRY_REQUEST,
31 }; 34 };
32 class Delegate { 35 class Delegate {
33 public: 36 public:
34 virtual ~Delegate() { } 37 virtual ~Delegate() { }
35 // Override this to handle the raw response as it is available. No response 38 // Override this to handle the raw response as it is available. No response
36 // error checking is done before this method is called. If the delegate 39 // error checking is done before this method is called. If the delegate
37 // returns CONTINUE_PROCESSING, we will then check for network 40 // returns CONTINUE_PROCESSING, we will then check for network
38 // errors. Most implementations will not override this. 41 // errors. Most implementations will not override this.
39 virtual ResponseAction HandleRawResponse(const URLFetcher* source, 42 virtual ResponseAction HandleRawResponse(
40 const GURL& url, 43 const URLFetcher* source,
41 const URLRequestStatus& status, 44 const GURL& url,
42 int response_code, 45 const net::URLRequestStatus& status,
43 const ResponseCookies& cookies, 46 int response_code,
44 const std::string& data) { 47 const ResponseCookies& cookies,
48 const std::string& data) {
45 return CONTINUE_PROCESSING; 49 return CONTINUE_PROCESSING;
46 } 50 }
47 // This will be invoked only if HandleRawResponse returns 51 // This will be invoked only if HandleRawResponse returns
48 // CONTINUE_PROCESSING AND if there are no network errors and the HTTP 52 // CONTINUE_PROCESSING AND if there are no network errors and the HTTP
49 // response code is 200. The delegate implementation returns 53 // response code is 200. The delegate implementation returns
50 // CONTINUE_PROCESSING if it does not want to handle the raw data itself. 54 // CONTINUE_PROCESSING if it does not want to handle the raw data itself.
51 // Handling the raw data is needed when the expected response is NOT JSON 55 // Handling the raw data is needed when the expected response is NOT JSON
52 // (like in the case of a print ticket response or a print job download 56 // (like in the case of a print ticket response or a print job download
53 // response). 57 // response).
54 virtual ResponseAction HandleRawData(const URLFetcher* source, 58 virtual ResponseAction HandleRawData(const URLFetcher* source,
(...skipping 25 matching lines...) Expand all
80 int max_retries); 84 int max_retries);
81 void StartPostRequest(const GURL& url, 85 void StartPostRequest(const GURL& url,
82 Delegate* delegate, 86 Delegate* delegate,
83 const std::string& auth_token, 87 const std::string& auth_token,
84 int max_retries, 88 int max_retries,
85 const std::string& post_data_mime_type, 89 const std::string& post_data_mime_type,
86 const std::string& post_data); 90 const std::string& post_data);
87 91
88 // URLFetcher::Delegate implementation. 92 // URLFetcher::Delegate implementation.
89 virtual void OnURLFetchComplete(const URLFetcher* source, const GURL& url, 93 virtual void OnURLFetchComplete(const URLFetcher* source, const GURL& url,
90 const URLRequestStatus& status, 94 const net::URLRequestStatus& status,
91 int response_code, 95 int response_code,
92 const ResponseCookies& cookies, 96 const ResponseCookies& cookies,
93 const std::string& data); 97 const std::string& data);
94 protected: 98 protected:
95 friend class base::RefCountedThreadSafe<CloudPrintURLFetcher>; 99 friend class base::RefCountedThreadSafe<CloudPrintURLFetcher>;
96 virtual ~CloudPrintURLFetcher(); 100 virtual ~CloudPrintURLFetcher();
97 101
98 // Virtual for testing. 102 // Virtual for testing.
99 virtual URLRequestContextGetter* GetRequestContextGetter(); 103 virtual URLRequestContextGetter* GetRequestContextGetter();
100 104
101 private: 105 private:
102 void StartRequestHelper(const GURL& url, 106 void StartRequestHelper(const GURL& url,
103 URLFetcher::RequestType request_type, 107 URLFetcher::RequestType request_type,
104 Delegate* delegate, 108 Delegate* delegate,
105 const std::string& auth_token, 109 const std::string& auth_token,
106 int max_retries, 110 int max_retries,
107 const std::string& post_data_mime_type, 111 const std::string& post_data_mime_type,
108 const std::string& post_data); 112 const std::string& post_data);
109 113
110 scoped_ptr<URLFetcher> request_; 114 scoped_ptr<URLFetcher> request_;
111 Delegate* delegate_; 115 Delegate* delegate_;
112 int num_retries_; 116 int num_retries_;
113 }; 117 };
114 118
115 typedef CloudPrintURLFetcher::Delegate CloudPrintURLFetcherDelegate; 119 typedef CloudPrintURLFetcher::Delegate CloudPrintURLFetcherDelegate;
116 120
117 #endif // CHROME_SERVICE_CLOUD_PRINT_CLOUD_PRINT_URL_FETCHER_H_ 121 #endif // CHROME_SERVICE_CLOUD_PRINT_CLOUD_PRINT_URL_FETCHER_H_
OLDNEW
« no previous file with comments | « chrome/common/security_filter_peer.h ('k') | chrome/service/gaia/service_gaia_authenticator.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698