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

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

Issue 2764683002: Remove stale-while-revalidate from content and chrome (Closed)
Patch Set: rebase Created 3 years, 9 months 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 <memory>
9 #include <string>
10
11 #include "base/callback.h"
12 #include "base/macros.h"
13 #include "base/memory/ref_counted.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_throttle.h"
18 #include "net/base/io_buffer.h"
19 #include "net/url_request/url_request.h"
20
21 namespace content {
22
23 // This class is responsible for driving the URLRequest for an async
24 // revalidation. It is passed an instance of ResourceThrottle created by
25 // content::ResourceScheduler to perform throttling on the request.
26 class CONTENT_EXPORT AsyncRevalidationDriver
27 : public net::URLRequest::Delegate,
28 public ResourceThrottle::Delegate {
29 public:
30 // |completion_callback| is guaranteed to be called on completion,
31 // regardless of success or failure.
32 AsyncRevalidationDriver(std::unique_ptr<net::URLRequest> request,
33 std::unique_ptr<ResourceThrottle> throttle,
34 const base::Closure& completion_callback);
35 ~AsyncRevalidationDriver() override;
36
37 void StartRequest();
38
39 private:
40 // This enum is logged as histogram "Net.AsyncRevalidation.Result". Only add
41 // new entries at the end and update histograms.xml to match.
42 enum AsyncRevalidationResult {
43 RESULT_LOADED,
44 RESULT_REVALIDATED,
45 RESULT_NET_ERROR,
46 RESULT_READ_ERROR,
47 RESULT_GOT_REDIRECT,
48 RESULT_AUTH_FAILED,
49 RESULT_RESPONSE_TIMEOUT,
50 RESULT_BODY_TIMEOUT,
51 RESULT_MAX
52 };
53
54 // net::URLRequest::Delegate implementation:
55 void OnReceivedRedirect(net::URLRequest* request,
56 const net::RedirectInfo& redirect_info,
57 bool* defer) override;
58 void OnAuthRequired(net::URLRequest* request,
59 net::AuthChallengeInfo* info) override;
60 void OnResponseStarted(net::URLRequest* request) override;
61 void OnReadCompleted(net::URLRequest* request, int bytes_read) override;
62
63 // ResourceThrottle::Delegate implementation:
64 void Resume() override;
65
66 // For simplicity, this class assumes that ResourceScheduler never cancels
67 // requests, and so these three methods are never called.
68 void Cancel() override;
69 void CancelAndIgnore() override;
70 void CancelWithError(int error_code) override;
71
72 // Internal methods.
73 void StartRequestInternal();
74 void CancelRequestInternal(int error, AsyncRevalidationResult result);
75 void StartReading(bool is_continuation);
76 void ReadMore(int* bytes_read);
77 // Logs the result histogram, then calls and clears |completion_callback_|.
78 void ResponseCompleted(AsyncRevalidationResult result);
79 void OnTimeout(AsyncRevalidationResult result);
80 void RecordDefer();
81
82 bool is_deferred_ = false;
83
84 scoped_refptr<net::IOBuffer> read_buffer_;
85 base::OneShotTimer timer_;
86
87 std::unique_ptr<net::URLRequest> request_;
88 std::unique_ptr<ResourceThrottle> throttle_;
89
90 base::Closure completion_callback_;
91
92 base::WeakPtrFactory<AsyncRevalidationDriver> weak_ptr_factory_;
93
94 DISALLOW_COPY_AND_ASSIGN(AsyncRevalidationDriver);
95 };
96
97 } // namespace content
98
99 #endif // CONTENT_BROWSER_LOADER_ASYNC_REVALIDATION_DRIVER_H_
OLDNEW
« no previous file with comments | « content/browser/loader/async_resource_handler_unittest.cc ('k') | content/browser/loader/async_revalidation_driver.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698