OLD | NEW |
---|---|
(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/11/23 23:40:41
What need is there to make CancelRequest() a disti
| |
43 | |
44 private: | |
45 // net::URLRequest::Delegate implementation: | |
46 void OnReceivedRedirect(net::URLRequest* request, | |
47 const net::RedirectInfo& redirect_info, | |
48 bool* defer) override; | |
49 void OnAuthRequired(net::URLRequest* request, | |
50 net::AuthChallengeInfo* info) override; | |
51 void OnBeforeNetworkStart(net::URLRequest* request, bool* defer) override; | |
52 void OnResponseStarted(net::URLRequest* request) override; | |
53 void OnReadCompleted(net::URLRequest* request, int bytes_read) override; | |
54 | |
55 // ResourceController implementation: | |
56 void Resume() override; | |
57 | |
58 // For simplicity, this class assumes that ResourceScheduler never cancels | |
59 // requests, and so these three methods are never called. | |
60 void Cancel() override; | |
61 void CancelAndIgnore() override; | |
62 void CancelWithError(int error_code) override; | |
63 | |
64 // Internal methods. | |
65 void StartRequestInternal(); | |
66 void CancelRequestInternal(int error); | |
67 void StartReading(bool is_continuation); | |
68 void ResumeReading(); | |
69 void ReadMore(int* bytes_read); | |
70 // Calls |completion_callback_| and clears it. | |
71 void ResponseCompleted(); | |
72 void OnReadTimeout(); | |
73 void RecordDefer(); | |
74 | |
75 bool is_deferred_ = false; | |
76 | |
77 scoped_refptr<net::IOBuffer> read_buffer_; | |
78 base::Timer read_timer_; | |
79 | |
80 const scoped_ptr<net::URLRequest> request_; | |
81 scoped_ptr<ResourceThrottle> throttle_; | |
82 | |
83 base::Closure completion_callback_; | |
84 | |
85 base::WeakPtrFactory<AsyncRevalidationDriver> weak_ptr_factory_; | |
86 | |
87 DISALLOW_COPY_AND_ASSIGN(AsyncRevalidationDriver); | |
88 }; | |
89 | |
90 } // namespace content | |
91 | |
92 #endif // CONTENT_BROWSER_LOADER_ASYNC_REVALIDATION_DRIVER_H_ | |
OLD | NEW |