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

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: AsyncRevalidationDriver test reorganisation. Comment nits. Created 5 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
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/macros.h"
12 #include "base/memory/ref_counted.h"
13 #include "base/memory/scoped_ptr.h"
14 #include "base/memory/weak_ptr.h"
15 #include "base/timer/timer.h"
16 #include "content/common/content_export.h"
17 #include "content/public/browser/resource_controller.h"
18 #include "content/public/browser/resource_throttle.h"
19 #include "net/base/io_buffer.h"
20 #include "net/url_request/url_request.h"
21
22 namespace net {
23 class HttpCache;
24 }
25
26 namespace content {
27
28 // This class is responsible for driving the URLRequest for an async
29 // revalidation. It is passed an instance of ResourceThrottle created by
30 // content::ResourceScheduler to perform throttling on the request.
31 class CONTENT_EXPORT AsyncRevalidationDriver : public net::URLRequest::Delegate,
32 public ResourceController {
33 public:
34 // |completion_callback| is guaranteed to be called on completion,
35 // regardless of success or failure.
36 AsyncRevalidationDriver(scoped_ptr<net::URLRequest> request,
37 scoped_ptr<ResourceThrottle> throttle,
38 const base::Closure& completion_callback);
39 ~AsyncRevalidationDriver() override;
40
41 void StartRequest();
42 void CancelRequest();
davidben 2015/12/07 23:56:03 What need is there to make CancelRequest() a disti
Adam Rice 2015/12/08 18:05:35 Sorry I missed this. I have removed CancelRequest(
43
44 private:
45 enum TimeoutType {
46 RESPONSE_TIMEOUT,
47 READ_TIMEOUT
48 };
49
50 // net::URLRequest::Delegate implementation:
51 void OnReceivedRedirect(net::URLRequest* request,
52 const net::RedirectInfo& redirect_info,
53 bool* defer) override;
54 void OnAuthRequired(net::URLRequest* request,
55 net::AuthChallengeInfo* info) override;
56 void OnBeforeNetworkStart(net::URLRequest* request, bool* defer) override;
57 void OnResponseStarted(net::URLRequest* request) override;
58 void OnReadCompleted(net::URLRequest* request, int bytes_read) override;
59
60 // ResourceController implementation:
61 void Resume() override;
62
63 // For simplicity, this class assumes that ResourceScheduler never cancels
64 // requests, and so these three methods are never called.
65 void Cancel() override;
66 void CancelAndIgnore() override;
67 void CancelWithError(int error_code) override;
68
69 // Internal methods.
70 void StartRequestInternal();
71 void CancelRequestInternal(int error);
72 void StartReading(bool is_continuation);
73 void ResumeReading();
74 void ReadMore(int* bytes_read);
75 // Calls |completion_callback_| and clears it.
76 void ResponseCompleted();
77 void OnTimeout(TimeoutType type);
78 void RecordDefer();
79
80 bool is_deferred_ = false;
81
82 scoped_refptr<net::IOBuffer> read_buffer_;
83 base::OneShotTimer timer_;
84
85 const scoped_ptr<net::URLRequest> request_;
86 scoped_ptr<ResourceThrottle> throttle_;
87
88 base::Closure completion_callback_;
89
90 base::WeakPtrFactory<AsyncRevalidationDriver> weak_ptr_factory_;
91
92 DISALLOW_COPY_AND_ASSIGN(AsyncRevalidationDriver);
93 };
94
95 } // namespace content
96
97 #endif // CONTENT_BROWSER_LOADER_ASYNC_REVALIDATION_DRIVER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698