Chromium Code Reviews| 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 | |
| 29 // AsyncRevalidationDriver from an existing net::URLRequest that has had the | |
| 30 // stale-while-revalidate algorithm applied to it. | |
| 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 used to lookup an AsyncRevalidationDriver in the map of pending | |
|
Bence
2015/11/17 13:12:23
Optional: feel free to remove "used to lookup". I
Adam Rice
2015/11/17 17:45:53
Done.
| |
| 50 // async revalidations. This key has a | |
| 51 // distinct value for every in-progress async revalidation. It is used to | |
| 52 // avoid | |
| 53 // duplicate async revalidations, and also to cancel affected async | |
| 54 // revalidations when a ResourceContext is removed. | |
| 55 // Request headers are intentionally not included in the key as they usually | |
| 56 // don't affect caching, and could cause effectively identical revalidations | |
| 57 // to be considered different because they have a different "Referer" | |
| 58 // header. In rare cases where a "Vary" header leads to us to access different | |
| 59 // resources at the same URL, they fight a single cache slot and so performing | |
| 60 // additional async revalidations will not improve matters. | |
|
Bence
2015/11/17 13:12:23
Please reflow this paragraph.
Adam Rice
2015/11/17 17:45:53
Done.
| |
| 61 struct AsyncRevalidationKey { | |
| 62 AsyncRevalidationKey(const ResourceContext* resource_context, | |
| 63 const net::HttpCache* http_cache, | |
| 64 const GURL& url); | |
| 65 | |
| 66 // Create a prefix key that is used to match all of the | |
| 67 // AsyncRevalidationDrivers using |resource_context| in the map. | |
| 68 explicit AsyncRevalidationKey(const ResourceContext* resource_context); | |
| 69 | |
| 70 // The key for a map needs to be copyable. | |
| 71 AsyncRevalidationKey(const AsyncRevalidationKey& rhs) = default; | |
| 72 ~AsyncRevalidationKey(); | |
| 73 | |
| 74 // No operator= is generated because the struct members are immutable. | |
| 75 | |
| 76 // |resource_context| and |http_cache| are never dereferenced; they are only | |
| 77 // compared to other values. In order to efficiently find and delete all | |
| 78 // in-progress async revalidations using a particular ResourceContext, it | |
| 79 // forms the first part of the key. | |
|
Bence
2015/11/17 13:12:23
This last sentence might be more appropriate as a
Adam Rice
2015/11/17 17:45:52
I think you're right. I have removed the implement
| |
| 80 const ResourceContext* const resource_context; | |
| 81 | |
| 82 // Each ResourceContext owns one or more HttpCache objects. | |
|
Bence
2015/11/17 13:12:23
Optional: write "There might be multiple HttpCache
Adam Rice
2015/11/17 17:45:53
Sorry about that. I changed it to "There are multi
Bence
2015/11/17 21:34:28
Splendid.
| |
| 83 const net::HttpCache* const http_cache; | |
| 84 | |
| 85 // Derived from the url via net::HttpUtil::SpecForRequest(). | |
| 86 const std::string url_key; | |
| 87 | |
| 88 struct LessThan { | |
| 89 bool operator()(const AsyncRevalidationKey& lhs, | |
| 90 const AsyncRevalidationKey& rhs) const; | |
| 91 }; | |
| 92 }; | |
| 93 | |
| 94 // Map of AsyncRevalidationDriver object. | |
|
Bence
2015/11/17 13:12:23
Optional: remove this comment, fold into the one b
Adam Rice
2015/11/17 17:45:53
Done.
| |
| 95 typedef std::map<AsyncRevalidationKey, | |
|
Bence
2015/11/17 13:12:23
Use "using" instead of "typedef", see https://chro
Adam Rice
2015/11/17 17:45:53
Thanks. Old habits die hard.
| |
| 96 AsyncRevalidationDriver*, | |
| 97 AsyncRevalidationKey::LessThan> AsyncRevalidationMap; | |
| 98 | |
| 99 void OnAsyncRevalidationComplete(AsyncRevalidationMap::iterator it); | |
| 100 | |
| 101 // Async revalidations that are currently in-flight: either waiting to be | |
|
Bence
2015/11/17 13:12:23
Optional: "AsyncRevalidationDriver instances that
Adam Rice
2015/11/17 17:45:53
Done.
| |
| 102 // scheduled or active on the network. | |
| 103 AsyncRevalidationMap in_progress_; | |
| 104 | |
| 105 DISALLOW_COPY_AND_ASSIGN(AsyncRevalidationManager); | |
| 106 }; | |
| 107 | |
| 108 } // namespace content | |
| 109 | |
| 110 #endif // CONTENT_BROWSER_LOADER_ASYNC_REVALIDATION_MANAGER_H_ | |
| OLD | NEW |