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_MANAGER_H_ | |
6 #define CONTENT_BROWSER_LOADER_ASYNC_REVALIDATION_MANAGER_H_ | |
7 | |
8 #include <map> | |
9 #include <string> | |
10 | |
11 #include "base/macros.h" | |
12 | |
13 class GURL; | |
14 struct ResourceHostMsg_Request; | |
15 | |
16 namespace net { | |
17 class URLRequest; | |
18 class HttpCache; | |
19 } | |
20 | |
21 namespace content { | |
22 | |
23 class AsyncRevalidationDriver; | |
24 class ResourceContext; | |
25 class ResourceScheduler; | |
26 | |
27 // This class manages all active AsyncRevalidationDriver objects for the whole | |
28 // process. It also implements the creation of a new net::URLRequest and | |
kinuko
2015/11/19 07:00:29
nit: process -> renderer process?
kinuko
2015/11/19 08:01:32
oops, sorry please ignore this
| |
29 // AsyncRevalidationDriver from an existing net::URLRequest that has had the | |
30 // stale-while-revalidate algorithm applied to it. | |
kinuko
2015/11/19 07:00:29
It'd be probably easier to understand its lifetime
Adam Rice
2015/11/19 21:13:52
Comment updated. PTAL.
| |
31 class AsyncRevalidationManager { | |
32 public: | |
33 AsyncRevalidationManager(); | |
34 ~AsyncRevalidationManager(); | |
35 | |
36 // Starts an async revalidation by copying |for_request|. |scheduler| must | |
37 // remain valid until this object is destroyed. | |
38 void BeginAsyncRevalidation(net::URLRequest* for_request, | |
39 ResourceScheduler* scheduler); | |
40 | |
41 // Cancel all pending async revalidations that use ResourceContext. | |
42 void CancelAsyncRevalidationsForResourceContext( | |
43 ResourceContext* resource_context); | |
44 | |
45 static bool QualifiesForAsyncRevalidation( | |
46 const ResourceHostMsg_Request& request); | |
47 | |
48 private: | |
49 // The key of the map of pending async revalidations. This key has a distinct | |
50 // value for every in-progress async revalidation. It is used to avoid | |
51 // duplicate async revalidations, and also to cancel affected async | |
52 // revalidations when a ResourceContext is removed. | |
53 // | |
54 // Request headers are intentionally not included in the key as they usually | |
55 // don't affect caching, and could cause effectively identical revalidations | |
56 // to be considered different because they have a different "Referer" | |
57 // header. In rare cases where a "Vary" header leads to us to access different | |
58 // resources at the same URL, they fight over a single cache slot and so | |
59 // performing additional async revalidations will not improve matters. | |
60 struct AsyncRevalidationKey { | |
61 AsyncRevalidationKey(const ResourceContext* resource_context, | |
62 const net::HttpCache* http_cache, | |
63 const GURL& url); | |
64 | |
65 // Create a prefix key that is used to match all of the | |
66 // AsyncRevalidationDrivers using |resource_context| in the map. | |
67 explicit AsyncRevalidationKey(const ResourceContext* resource_context); | |
68 | |
69 // The key for a map needs to be copyable. | |
70 AsyncRevalidationKey(const AsyncRevalidationKey& rhs) = default; | |
71 ~AsyncRevalidationKey(); | |
72 | |
73 // No operator= is generated because the struct members are immutable. | |
74 | |
75 // |resource_context| and |http_cache| are never dereferenced; they are only | |
76 // compared to other values. | |
77 const ResourceContext* const resource_context; | |
78 | |
79 // There are multiple independent HttpCache objects per ResourceContext. | |
80 const net::HttpCache* const http_cache; | |
81 | |
82 // Derived from the url via net::HttpUtil::SpecForRequest(). | |
83 const std::string url_key; | |
84 | |
85 struct LessThan { | |
86 bool operator()(const AsyncRevalidationKey& lhs, | |
87 const AsyncRevalidationKey& rhs) const; | |
88 }; | |
89 }; | |
90 | |
91 using AsyncRevalidationMap = std::map<AsyncRevalidationKey, | |
92 AsyncRevalidationDriver*, | |
93 AsyncRevalidationKey::LessThan>; | |
kinuko
2015/11/19 07:00:29
I think we could use ScopedPtrMap here
Adam Rice
2015/11/19 21:13:52
It's deprecated. But I can use scoped_ptr<AsyncRev
| |
94 | |
95 void OnAsyncRevalidationComplete(AsyncRevalidationMap::iterator it); | |
96 | |
97 // Map of AsyncRevalidationDriver instances that are currently in-flight: | |
98 // either waiting to be scheduled or active on the network. | |
99 AsyncRevalidationMap in_progress_; | |
100 | |
101 DISALLOW_COPY_AND_ASSIGN(AsyncRevalidationManager); | |
102 }; | |
103 | |
104 } // namespace content | |
105 | |
106 #endif // CONTENT_BROWSER_LOADER_ASYNC_REVALIDATION_MANAGER_H_ | |
OLD | NEW |