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 |
| 43 private: |
| 44 enum TimeoutType { RESPONSE_TIMEOUT, READ_TIMEOUT }; |
| 45 |
| 46 // net::URLRequest::Delegate implementation: |
| 47 void OnReceivedRedirect(net::URLRequest* request, |
| 48 const net::RedirectInfo& redirect_info, |
| 49 bool* defer) override; |
| 50 void OnAuthRequired(net::URLRequest* request, |
| 51 net::AuthChallengeInfo* info) override; |
| 52 void OnBeforeNetworkStart(net::URLRequest* request, bool* defer) override; |
| 53 void OnResponseStarted(net::URLRequest* request) override; |
| 54 void OnReadCompleted(net::URLRequest* request, int bytes_read) override; |
| 55 |
| 56 // ResourceController implementation: |
| 57 void Resume() override; |
| 58 |
| 59 // For simplicity, this class assumes that ResourceScheduler never cancels |
| 60 // requests, and so these three methods are never called. |
| 61 void Cancel() override; |
| 62 void CancelAndIgnore() override; |
| 63 void CancelWithError(int error_code) override; |
| 64 |
| 65 // Internal methods. |
| 66 void StartRequestInternal(); |
| 67 void CancelRequestInternal(int error); |
| 68 void StartReading(bool is_continuation); |
| 69 void ReadMore(int* bytes_read); |
| 70 // Calls |completion_callback_| and clears it. |
| 71 void ResponseCompleted(); |
| 72 void OnTimeout(TimeoutType type); |
| 73 void RecordDefer(); |
| 74 |
| 75 bool is_deferred_ = false; |
| 76 |
| 77 scoped_refptr<net::IOBuffer> read_buffer_; |
| 78 base::OneShotTimer timer_; |
| 79 |
| 80 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 |