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

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

Issue 4194001: Implement exponential back-off mechanism and enforce it at the URLRequestHttpJob level. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 10 years 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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 "chrome/common/net/url_fetcher.h" 11 #include "chrome/common/net/url_fetcher.h"
12 12
13 class DictionaryValue; 13 class DictionaryValue;
14 class GURL; 14 class GURL;
15 class URLFetcherProtectEntry;
16 class URLRequestStatus; 15 class URLRequestStatus;
17 16
18 // A wrapper around URLFetcher for CloudPrint. URLFetcher applies retry logic 17 // 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 18 // 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 19 // 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 20 // (for all CloudPrint APIs that expect JSON responses) as errors and they
22 // must also be retried. Also URLFetcher uses the host name of the URL as the 21 // must also be retried.
23 // key for applying the retry policy. In our case, we want to apply one global
24 // policy for many requests (not necessarily scoped by hostname).
25 class CloudPrintURLFetcher 22 class CloudPrintURLFetcher
26 : public base::RefCountedThreadSafe<CloudPrintURLFetcher>, 23 : public base::RefCountedThreadSafe<CloudPrintURLFetcher>,
sanjeevr 2010/11/22 19:09:26 Now that we don't post tasks to this object, perha
yzshen 2010/11/22 22:59:17 I saw the following code in CloudPrintURLFetcher::
27 public URLFetcher::Delegate { 24 public URLFetcher::Delegate {
28 public: 25 public:
29 enum ResponseAction { 26 enum ResponseAction {
30 CONTINUE_PROCESSING, 27 CONTINUE_PROCESSING,
31 STOP_PROCESSING, 28 STOP_PROCESSING,
32 RETRY_REQUEST, 29 RETRY_REQUEST,
33 }; 30 };
34 class Delegate { 31 class Delegate {
35 public: 32 public:
36 virtual ~Delegate() { } 33 virtual ~Delegate() { }
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
72 virtual void OnRequestGiveUp() { } 69 virtual void OnRequestGiveUp() { }
73 // Invoked when the request returns a 403 error (applicable only when 70 // Invoked when the request returns a 403 error (applicable only when
74 // HandleRawResponse returns CONTINUE_PROCESSING) 71 // HandleRawResponse returns CONTINUE_PROCESSING)
75 virtual void OnRequestAuthError() = 0; 72 virtual void OnRequestAuthError() = 0;
76 }; 73 };
77 CloudPrintURLFetcher(); 74 CloudPrintURLFetcher();
78 75
79 void StartGetRequest(const GURL& url, 76 void StartGetRequest(const GURL& url,
80 Delegate* delegate, 77 Delegate* delegate,
81 const std::string& auth_token, 78 const std::string& auth_token,
82 const std::string& retry_policy); 79 int max_retries);
83 void StartPostRequest(const GURL& url, 80 void StartPostRequest(const GURL& url,
84 Delegate* delegate, 81 Delegate* delegate,
85 const std::string& auth_token, 82 const std::string& auth_token,
86 const std::string& retry_policy, 83 int max_retries,
87 const std::string& post_data_mime_type, 84 const std::string& post_data_mime_type,
88 const std::string& post_data); 85 const std::string& post_data);
89 86
90 // URLFetcher::Delegate implementation. 87 // URLFetcher::Delegate implementation.
91 virtual void OnURLFetchComplete(const URLFetcher* source, const GURL& url, 88 virtual void OnURLFetchComplete(const URLFetcher* source, const GURL& url,
92 const URLRequestStatus& status, 89 const URLRequestStatus& status,
93 int response_code, 90 int response_code,
94 const ResponseCookies& cookies, 91 const ResponseCookies& cookies,
95 const std::string& data); 92 const std::string& data);
96 protected: 93 protected:
97 // Virtual for testing. 94 // Virtual for testing.
98 virtual URLRequestContextGetter* GetRequestContextGetter(); 95 virtual URLRequestContextGetter* GetRequestContextGetter();
99 96
100 private: 97 private:
101 void StartRequestHelper(const GURL& url, 98 void StartRequestHelper(const GURL& url,
102 URLFetcher::RequestType request_type, 99 URLFetcher::RequestType request_type,
103 Delegate* delegate, 100 Delegate* delegate,
104 const std::string& auth_token, 101 const std::string& auth_token,
105 const std::string& retry_policy, 102 int max_retries,
106 const std::string& post_data_mime_type, 103 const std::string& post_data_mime_type,
107 const std::string& post_data); 104 const std::string& post_data);
108 void StartRequestNow(); 105 void StartRequestNow();
109 106
110 scoped_ptr<URLFetcher> request_; 107 scoped_ptr<URLFetcher> request_;
111 Delegate* delegate_; 108 Delegate* delegate_;
112 URLFetcherProtectEntry* protect_entry_;
113 int num_retries_; 109 int num_retries_;
114 }; 110 };
115 111
116 typedef CloudPrintURLFetcher::Delegate CloudPrintURLFetcherDelegate; 112 typedef CloudPrintURLFetcher::Delegate CloudPrintURLFetcherDelegate;
117 113
118 #endif // CHROME_SERVICE_CLOUD_PRINT_CLOUD_PRINT_URL_FETCHER_H_ 114 #endif // CHROME_SERVICE_CLOUD_PRINT_CLOUD_PRINT_URL_FETCHER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698