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

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: Use histograms instead of user actions. 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
« no previous file with comments | « no previous file | content/browser/loader/async_revalidation_driver.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
43 private:
44 // This enum is logged as histogram "Net.AsyncRevalidation.Result". Only add
45 // new entries at the end and update histograms.xml to match.
46 enum AsyncRevalidationResult {
47 RESULT_LOADED,
48 RESULT_REVALIDATED,
49 RESULT_NET_ERROR,
50 RESULT_READ_ERROR,
51 RESULT_GOT_REDIRECT,
52 RESULT_AUTH_FAILED,
53 RESULT_RESPONSE_TIMEOUT,
54 RESULT_BODY_TIMEOUT,
55 RESULT_MAX
56 };
57
58 // net::URLRequest::Delegate implementation:
59 void OnReceivedRedirect(net::URLRequest* request,
60 const net::RedirectInfo& redirect_info,
61 bool* defer) override;
62 void OnAuthRequired(net::URLRequest* request,
63 net::AuthChallengeInfo* info) override;
64 void OnBeforeNetworkStart(net::URLRequest* request, bool* defer) override;
65 void OnResponseStarted(net::URLRequest* request) override;
66 void OnReadCompleted(net::URLRequest* request, int bytes_read) override;
67
68 // ResourceController implementation:
69 void Resume() override;
70
71 // For simplicity, this class assumes that ResourceScheduler never cancels
72 // requests, and so these three methods are never called.
73 void Cancel() override;
74 void CancelAndIgnore() override;
75 void CancelWithError(int error_code) override;
76
77 // Internal methods.
78 void StartRequestInternal();
79 void CancelRequestInternal(int error, AsyncRevalidationResult result);
80 void StartReading(bool is_continuation);
81 void ReadMore(int* bytes_read);
82 // Logs the result histogram, then calls and clears |completion_callback_|.
83 void ResponseCompleted(AsyncRevalidationResult result);
84 void OnTimeout(AsyncRevalidationResult result);
85 void RecordDefer();
86
87 bool is_deferred_ = false;
88
89 scoped_refptr<net::IOBuffer> read_buffer_;
90 base::OneShotTimer timer_;
91
92 scoped_ptr<net::URLRequest> request_;
93 scoped_ptr<ResourceThrottle> throttle_;
94
95 base::Closure completion_callback_;
96
97 base::WeakPtrFactory<AsyncRevalidationDriver> weak_ptr_factory_;
98
99 DISALLOW_COPY_AND_ASSIGN(AsyncRevalidationDriver);
100 };
101
102 } // namespace content
103
104 #endif // CONTENT_BROWSER_LOADER_ASYNC_REVALIDATION_DRIVER_H_
OLDNEW
« no previous file with comments | « no previous file | content/browser/loader/async_revalidation_driver.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698