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

Side by Side Diff: content/browser/loader/async_revalidation_driver.h

Issue 1041993004: content::ResourceDispatcherHostImpl changes for stale-while-revalidate (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@s-w-r-yhirano-patch
Patch Set: Remove unnecessary deferral logic from AsyncRevalidationDriver Created 5 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
OLDNEW
(Empty)
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef CONTENT_BROWSER_LOADER_ASYNC_REVALIDATION_DRIVER_H_
6 #define CONTENT_BROWSER_LOADER_ASYNC_REVALIDATION_DRIVER_H_
7
8 #include <string>
9
10 #include "base/callback.h"
11 #include "base/memory/ref_counted.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "base/memory/weak_ptr.h"
14 #include "base/timer/timer.h"
15 #include "content/common/content_export.h"
16 #include "content/public/browser/resource_controller.h"
17 #include "content/public/browser/resource_throttle.h"
18 #include "net/base/io_buffer.h"
19 #include "net/url_request/url_request.h"
20
21 namespace net {
22 class HttpCache;
23 }
24
25 namespace content {
26
27 // This class is responsible for driving the URLRequest for an async
28 // revalidation. It is passed an instance of ResourceThrottle created by
29 // content::ResourceScheduler to perform throttling on the request.
30 class CONTENT_EXPORT AsyncRevalidationDriver : public net::URLRequest::Delegate,
31 public ResourceController {
32 public:
33 // |completion_callback| is guaranteed to be called on completion,
34 // regardless of success or failure.
35 AsyncRevalidationDriver(scoped_ptr<net::URLRequest> request,
36 scoped_ptr<ResourceThrottle> throttle,
37 const base::Closure& completion_callback);
38 ~AsyncRevalidationDriver() override;
39
40 void StartRequest();
41 void CancelRequest();
42
43 private:
44 // net::URLRequest::Delegate implementation:
45 void OnReceivedRedirect(net::URLRequest* request,
46 const net::RedirectInfo& redirect_info,
47 bool* defer) override;
48 void OnAuthRequired(net::URLRequest* request,
49 net::AuthChallengeInfo* info) override;
50 void OnBeforeNetworkStart(net::URLRequest* request, bool* defer) override;
51 void OnResponseStarted(net::URLRequest* request) override;
52 void OnReadCompleted(net::URLRequest* request, int bytes_read) override;
53
54 // ResourceController implementation:
55 void Resume() override;
56
57 // For simplicity, this class assumes that ResourceScheduler never cancels
58 // requests, and so these three methods are never called.
59 void Cancel() override;
60 void CancelAndIgnore() override;
61 void CancelWithError(int error_code) override;
62
63 // Internal methods.
64 void StartRequestInternal();
65 void CancelRequestInternal(int error);
66 void CompleteResponseStarted();
67 void StartReading(bool is_continuation);
68 void ResumeReading();
69 void ReadMore(int* bytes_read);
70 // Calls |completion_callback_|.
71 void ResponseCompleted();
72 void OnReadTimeout();
73 void RecordDefer();
74
75 bool is_deferred() const { return is_deferred_; }
Bence 2015/11/17 13:12:21 You DCHECK this twice accessor twice and DCHECK th
Adam Rice 2015/11/17 17:45:51 Done.
76
77 bool is_deferred_ = false;
78
79 // When this class cancels a redirect, URLRequest calls both the
80 // OnResponseStarted() and OnReadCompleted() callbacks. This class should not
81 // run |completion_callback_| twice.
82 //
83 // TODO(ricea): Work out why URLRequest calls both methods on cancellation and
84 // make it stop.
85 bool has_already_failed_ = false;
86
87 scoped_refptr<net::IOBuffer> read_buffer_;
88 base::Timer read_timer_;
89
90 const scoped_ptr<net::URLRequest> request_;
91 scoped_ptr<ResourceThrottle> throttle_;
92
93 base::Closure completion_callback_;
94
95 base::WeakPtrFactory<AsyncRevalidationDriver> weak_ptr_factory_;
96
97 DISALLOW_COPY_AND_ASSIGN(AsyncRevalidationDriver);
98 };
99
100 } // namespace content
101
102 #endif // CONTENT_BROWSER_LOADER_ASYNC_REVALIDATION_DRIVER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698