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

Side by Side Diff: net/url_request/url_fetcher_core.h

Issue 11464028: Introduce ERR_NETWORK_CHANGED and allow URLFetcher to automatically retry on that error. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 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) 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 NET_URL_REQUEST_URL_FETCHER_CORE_H_ 5 #ifndef NET_URL_REQUEST_URL_FETCHER_CORE_H_
6 #define NET_URL_REQUEST_URL_FETCHER_CORE_H_ 6 #define NET_URL_REQUEST_URL_FETCHER_CORE_H_
7 7
8 #include <set> 8 #include <set>
9 #include <string> 9 #include <string>
10 10
11 #include "base/basictypes.h" 11 #include "base/basictypes.h"
12 #include "base/compiler_specific.h" 12 #include "base/compiler_specific.h"
13 #include "base/debug/stack_trace.h" 13 #include "base/debug/stack_trace.h"
14 #include "base/file_path.h" 14 #include "base/file_path.h"
15 #include "base/lazy_instance.h" 15 #include "base/lazy_instance.h"
16 #include "base/memory/ref_counted.h" 16 #include "base/memory/ref_counted.h"
17 #include "base/memory/scoped_ptr.h" 17 #include "base/memory/scoped_ptr.h"
18 #include "base/memory/weak_ptr.h" 18 #include "base/memory/weak_ptr.h"
19 #include "base/platform_file.h" 19 #include "base/platform_file.h"
20 #include "base/timer.h" 20 #include "base/timer.h"
21 #include "googleurl/src/gurl.h" 21 #include "googleurl/src/gurl.h"
22 #include "net/base/host_port_pair.h" 22 #include "net/base/host_port_pair.h"
23 #include "net/base/network_change_notifier.h"
23 #include "net/http/http_request_headers.h" 24 #include "net/http/http_request_headers.h"
24 #include "net/url_request/url_fetcher.h" 25 #include "net/url_request/url_fetcher.h"
25 #include "net/url_request/url_request.h" 26 #include "net/url_request/url_request.h"
26 #include "net/url_request/url_request_status.h" 27 #include "net/url_request/url_request_status.h"
27 28
28 namespace base { 29 namespace base {
29 class SingleThreadTaskRunner; 30 class SingleThreadTaskRunner;
30 } // namespace base 31 } // namespace base
31 32
32 namespace net { 33 namespace net {
33 class HttpResponseHeaders; 34 class HttpResponseHeaders;
34 class IOBuffer; 35 class IOBuffer;
35 class URLFetcherDelegate; 36 class URLFetcherDelegate;
36 class URLRequestContextGetter; 37 class URLRequestContextGetter;
37 class URLRequestThrottlerEntryInterface; 38 class URLRequestThrottlerEntryInterface;
38 39
39 class URLFetcherCore 40 class URLFetcherCore
40 : public base::RefCountedThreadSafe<URLFetcherCore>, 41 : public base::RefCountedThreadSafe<URLFetcherCore>,
41 public URLRequest::Delegate { 42 public URLRequest::Delegate,
43 public NetworkChangeNotifier::ConnectionTypeObserver {
42 public: 44 public:
43 URLFetcherCore(URLFetcher* fetcher, 45 URLFetcherCore(URLFetcher* fetcher,
44 const GURL& original_url, 46 const GURL& original_url,
45 URLFetcher::RequestType request_type, 47 URLFetcher::RequestType request_type,
46 URLFetcherDelegate* d); 48 URLFetcherDelegate* d);
47 49
48 // Starts the load. It's important that this not happen in the constructor 50 // Starts the load. It's important that this not happen in the constructor
49 // because it causes the IO thread to begin AddRef()ing and Release()ing 51 // because it causes the IO thread to begin AddRef()ing and Release()ing
50 // us. If our caller hasn't had time to fully construct us and take a 52 // us. If our caller hasn't had time to fully construct us and take a
51 // reference, the IO thread could interrupt things, run a task, Release() 53 // reference, the IO thread could interrupt things, run a task, Release()
(...skipping 30 matching lines...) Expand all
82 // Set the key and data callback that is used when setting the user 84 // Set the key and data callback that is used when setting the user
83 // data on any URLRequest objects this object creates. 85 // data on any URLRequest objects this object creates.
84 void SetURLRequestUserData( 86 void SetURLRequestUserData(
85 const void* key, 87 const void* key,
86 const URLFetcher::CreateDataCallback& create_data_callback); 88 const URLFetcher::CreateDataCallback& create_data_callback);
87 void SetStopOnRedirect(bool stop_on_redirect); 89 void SetStopOnRedirect(bool stop_on_redirect);
88 void SetAutomaticallyRetryOn5xx(bool retry); 90 void SetAutomaticallyRetryOn5xx(bool retry);
89 void SetMaxRetries(int max_retries); 91 void SetMaxRetries(int max_retries);
90 int GetMaxRetries() const; 92 int GetMaxRetries() const;
91 base::TimeDelta GetBackoffDelay() const; 93 base::TimeDelta GetBackoffDelay() const;
94 void SetAutomaticallyRetryOnNetworkChanges(int max_retries);
92 void SaveResponseToFileAtPath( 95 void SaveResponseToFileAtPath(
93 const FilePath& file_path, 96 const FilePath& file_path,
94 scoped_refptr<base::TaskRunner> file_task_runner); 97 scoped_refptr<base::TaskRunner> file_task_runner);
95 void SaveResponseToTemporaryFile( 98 void SaveResponseToTemporaryFile(
96 scoped_refptr<base::TaskRunner> file_task_runner); 99 scoped_refptr<base::TaskRunner> file_task_runner);
97 HttpResponseHeaders* GetResponseHeaders() const; 100 HttpResponseHeaders* GetResponseHeaders() const;
98 HostPortPair GetSocketAddress() const; 101 HostPortPair GetSocketAddress() const;
99 bool WasFetchedViaProxy() const; 102 bool WasFetchedViaProxy() const;
100 const GURL& GetOriginalURL() const; 103 const GURL& GetOriginalURL() const;
101 const GURL& GetURL() const; 104 const GURL& GetURL() const;
(...skipping 13 matching lines...) Expand all
115 FilePath* out_response_path); 118 FilePath* out_response_path);
116 119
117 // Overridden from URLRequest::Delegate: 120 // Overridden from URLRequest::Delegate:
118 virtual void OnReceivedRedirect(URLRequest* request, 121 virtual void OnReceivedRedirect(URLRequest* request,
119 const GURL& new_url, 122 const GURL& new_url,
120 bool* defer_redirect) OVERRIDE; 123 bool* defer_redirect) OVERRIDE;
121 virtual void OnResponseStarted(URLRequest* request) OVERRIDE; 124 virtual void OnResponseStarted(URLRequest* request) OVERRIDE;
122 virtual void OnReadCompleted(URLRequest* request, 125 virtual void OnReadCompleted(URLRequest* request,
123 int bytes_read) OVERRIDE; 126 int bytes_read) OVERRIDE;
124 127
128 // Overridden from NetworkChangeNotifier::ConnectionTypeObserver:
129 virtual void OnConnectionTypeChanged(
130 NetworkChangeNotifier::ConnectionType type) OVERRIDE;
131
125 URLFetcherDelegate* delegate() const { return delegate_; } 132 URLFetcherDelegate* delegate() const { return delegate_; }
126 static void CancelAll(); 133 static void CancelAll();
127 static int GetNumFetcherCores(); 134 static int GetNumFetcherCores();
128 static void SetEnableInterceptionForTests(bool enabled); 135 static void SetEnableInterceptionForTests(bool enabled);
129 136
130 private: 137 private:
131 friend class base::RefCountedThreadSafe<URLFetcherCore>; 138 friend class base::RefCountedThreadSafe<URLFetcherCore>;
132 139
133 // How should the response be stored? 140 // How should the response be stored?
134 enum ResponseDestinationType { 141 enum ResponseDestinationType {
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after
378 // use this to ensure that |url_| is set to the redirect destination rather 385 // use this to ensure that |url_| is set to the redirect destination rather
379 // than the originally-fetched URL. 386 // than the originally-fetched URL.
380 bool stopped_on_redirect_; 387 bool stopped_on_redirect_;
381 388
382 // If |automatically_retry_on_5xx_| is false, 5xx responses will be 389 // If |automatically_retry_on_5xx_| is false, 5xx responses will be
383 // propagated to the observer, if it is true URLFetcher will automatically 390 // propagated to the observer, if it is true URLFetcher will automatically
384 // re-execute the request, after the back-off delay has expired. 391 // re-execute the request, after the back-off delay has expired.
385 // true by default. 392 // true by default.
386 bool automatically_retry_on_5xx_; 393 bool automatically_retry_on_5xx_;
387 // Maximum retries allowed. 394 // Maximum retries allowed.
388 int max_retries_; 395 int max_retries_;
pauljensen 2012/12/07 23:00:05 Might be nice to comment this more explicitly, dit
Joao da Silva 2012/12/10 15:32:42 Done. Also renamed these fields and the setter/get
389 // Back-off time delay. 0 by default. 396 // Back-off time delay. 0 by default.
390 base::TimeDelta backoff_delay_; 397 base::TimeDelta backoff_delay_;
391 398
399 // Number of times to retry when the request fails with ERR_NETWORK_CHANGED.
400 // Defaults to 0.
pauljensen 2012/12/07 23:00:05 nit: Maybe change to "0 by default." to match two
Joao da Silva 2012/12/10 15:32:42 Done.
401 int max_retries_on_network_changes_;
402
392 // Timer to poll the progress of uploading for POST and PUT requests. 403 // Timer to poll the progress of uploading for POST and PUT requests.
393 // When crbug.com/119629 is fixed, scoped_ptr is not necessary here. 404 // When crbug.com/119629 is fixed, scoped_ptr is not necessary here.
394 scoped_ptr<base::RepeatingTimer<URLFetcherCore> > 405 scoped_ptr<base::RepeatingTimer<URLFetcherCore> >
395 upload_progress_checker_timer_; 406 upload_progress_checker_timer_;
396 // Number of bytes sent so far. 407 // Number of bytes sent so far.
397 int64 current_upload_bytes_; 408 int64 current_upload_bytes_;
398 // Number of bytes received so far. 409 // Number of bytes received so far.
399 int64 current_response_bytes_; 410 int64 current_response_bytes_;
400 // Total expected bytes to receive (-1 if it cannot be determined). 411 // Total expected bytes to receive (-1 if it cannot be determined).
401 int64 total_response_bytes_; 412 int64 total_response_bytes_;
402 413
403 // TODO(willchan): Get rid of this after debugging crbug.com/90971. 414 // TODO(willchan): Get rid of this after debugging crbug.com/90971.
404 base::debug::StackTrace stack_trace_; 415 base::debug::StackTrace stack_trace_;
405 416
406 static base::LazyInstance<Registry> g_registry; 417 static base::LazyInstance<Registry> g_registry;
407 418
408 DISALLOW_COPY_AND_ASSIGN(URLFetcherCore); 419 DISALLOW_COPY_AND_ASSIGN(URLFetcherCore);
409 }; 420 };
410 421
411 } // namespace net 422 } // namespace net
412 423
413 #endif // NET_URL_REQUEST_URL_FETCHER_CORE_H_ 424 #endif // NET_URL_REQUEST_URL_FETCHER_CORE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698