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

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, 1 month 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; 15 class RequestThrottlerManager;
16 class URLRequestStatus; 16 class URLRequestStatus;
17 17
18 // A wrapper around URLFetcher for CloudPrint. URLFetcher applies retry logic 18 // 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 19 // 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 20 // 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 21 // (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 22 // 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 23 class CloudPrintURLFetcher
26 : public base::RefCountedThreadSafe<CloudPrintURLFetcher>, 24 : public base::RefCountedThreadSafe<CloudPrintURLFetcher>,
27 public URLFetcher::Delegate { 25 public URLFetcher::Delegate {
28 public: 26 public:
29 enum ResponseAction { 27 enum ResponseAction {
30 CONTINUE_PROCESSING, 28 CONTINUE_PROCESSING,
31 STOP_PROCESSING, 29 STOP_PROCESSING,
32 RETRY_REQUEST, 30 RETRY_REQUEST,
33 }; 31 };
34 class Delegate { 32 class Delegate {
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
72 virtual void OnRequestGiveUp() { } 70 virtual void OnRequestGiveUp() { }
73 // Invoked when the request returns a 403 error (applicable only when 71 // Invoked when the request returns a 403 error (applicable only when
74 // HandleRawResponse returns CONTINUE_PROCESSING) 72 // HandleRawResponse returns CONTINUE_PROCESSING)
75 virtual void OnRequestAuthError() = 0; 73 virtual void OnRequestAuthError() = 0;
76 }; 74 };
77 CloudPrintURLFetcher(); 75 CloudPrintURLFetcher();
78 76
79 void StartGetRequest(const GURL& url, 77 void StartGetRequest(const GURL& url,
80 Delegate* delegate, 78 Delegate* delegate,
81 const std::string& auth_token, 79 const std::string& auth_token,
82 const std::string& retry_policy); 80 int max_retries);
83 void StartPostRequest(const GURL& url, 81 void StartPostRequest(const GURL& url,
84 Delegate* delegate, 82 Delegate* delegate,
85 const std::string& auth_token, 83 const std::string& auth_token,
86 const std::string& retry_policy, 84 int max_retries,
87 const std::string& post_data_mime_type, 85 const std::string& post_data_mime_type,
88 const std::string& post_data); 86 const std::string& post_data);
89 87
90 // URLFetcher::Delegate implementation. 88 // URLFetcher::Delegate implementation.
91 virtual void OnURLFetchComplete(const URLFetcher* source, const GURL& url, 89 virtual void OnURLFetchComplete(const URLFetcher* source, const GURL& url,
92 const URLRequestStatus& status, 90 const URLRequestStatus& status,
93 int response_code, 91 int response_code,
94 const ResponseCookies& cookies, 92 const ResponseCookies& cookies,
95 const std::string& data); 93 const std::string& data);
96 protected: 94 protected:
97 // Virtual for testing. 95 // Virtual for testing.
98 virtual URLRequestContextGetter* GetRequestContextGetter(); 96 virtual URLRequestContextGetter* GetRequestContextGetter();
99 97
100 private: 98 private:
101 void StartRequestHelper(const GURL& url, 99 void StartRequestHelper(const GURL& url,
102 URLFetcher::RequestType request_type, 100 URLFetcher::RequestType request_type,
103 Delegate* delegate, 101 Delegate* delegate,
104 const std::string& auth_token, 102 const std::string& auth_token,
105 const std::string& retry_policy, 103 int max_retries,
106 const std::string& post_data_mime_type, 104 const std::string& post_data_mime_type,
107 const std::string& post_data); 105 const std::string& post_data);
108 void StartRequestNow(); 106 void StartRequestNow();
109 107
110 scoped_ptr<URLFetcher> request_; 108 scoped_ptr<URLFetcher> request_;
111 Delegate* delegate_; 109 Delegate* delegate_;
112 URLFetcherProtectEntry* protect_entry_; 110 RequestThrottlerManager* request_throttler_manager_;
willchan no longer on Chromium 2010/11/17 20:32:34 Why are we caching the singleton into a pointer?
yzshen 2010/11/19 23:51:36 I thought it was right since I read this in single
113 int num_retries_; 111 int num_retries_;
114 }; 112 };
115 113
116 typedef CloudPrintURLFetcher::Delegate CloudPrintURLFetcherDelegate; 114 typedef CloudPrintURLFetcher::Delegate CloudPrintURLFetcherDelegate;
117 115
118 #endif // CHROME_SERVICE_CLOUD_PRINT_CLOUD_PRINT_URL_FETCHER_H_ 116 #endif // CHROME_SERVICE_CLOUD_PRINT_CLOUD_PRINT_URL_FETCHER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698