Chromium Code Reviews| Index: content/browser/loader/async_revalidation_manager.h |
| diff --git a/content/browser/loader/async_revalidation_manager.h b/content/browser/loader/async_revalidation_manager.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..a13e8feafb3d35828800f15ab353f29d4aa6a640 |
| --- /dev/null |
| +++ b/content/browser/loader/async_revalidation_manager.h |
| @@ -0,0 +1,110 @@ |
| +// Copyright 2015 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef CONTENT_BROWSER_LOADER_ASYNC_REVALIDATION_MANAGER_H_ |
| +#define CONTENT_BROWSER_LOADER_ASYNC_REVALIDATION_MANAGER_H_ |
| + |
| +#include <map> |
| +#include <string> |
| + |
| +#include "base/macros.h" |
| + |
| +class GURL; |
| +struct ResourceHostMsg_Request; |
| + |
| +namespace net { |
| +class URLRequest; |
| +class HttpCache; |
| +} |
| + |
| +namespace content { |
| + |
| +class AsyncRevalidationDriver; |
| +class ResourceContext; |
| +class ResourceScheduler; |
| + |
| +// This class manages all active AsyncRevalidationDriver objects for the whole |
| +// process. It also implements the creation of a new net::URLRequest and |
| +// AsyncRevalidationDriver from an existing net::URLRequest that has had the |
| +// stale-while-revalidate algorithm applied to it. |
| +class AsyncRevalidationManager { |
| + public: |
| + AsyncRevalidationManager(); |
| + ~AsyncRevalidationManager(); |
| + |
| + // Starts an async revalidation by copying |for_request|. |scheduler| must |
| + // remain valid until this object is destroyed. |
| + void BeginAsyncRevalidation(net::URLRequest* for_request, |
| + ResourceScheduler* scheduler); |
| + |
| + // Cancel all pending async revalidations that use ResourceContext. |
| + void CancelAsyncRevalidationsForResourceContext( |
| + ResourceContext* resource_context); |
| + |
| + static bool QualifiesForAsyncRevalidation( |
| + const ResourceHostMsg_Request& request); |
| + |
| + private: |
| + // 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.
|
| + // async revalidations. This key has a |
| + // distinct value for every in-progress async revalidation. It is used to |
| + // avoid |
| + // duplicate async revalidations, and also to cancel affected async |
| + // revalidations when a ResourceContext is removed. |
| + // Request headers are intentionally not included in the key as they usually |
| + // don't affect caching, and could cause effectively identical revalidations |
| + // to be considered different because they have a different "Referer" |
| + // header. In rare cases where a "Vary" header leads to us to access different |
| + // resources at the same URL, they fight a single cache slot and so performing |
| + // 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.
|
| + struct AsyncRevalidationKey { |
| + AsyncRevalidationKey(const ResourceContext* resource_context, |
| + const net::HttpCache* http_cache, |
| + const GURL& url); |
| + |
| + // Create a prefix key that is used to match all of the |
| + // AsyncRevalidationDrivers using |resource_context| in the map. |
| + explicit AsyncRevalidationKey(const ResourceContext* resource_context); |
| + |
| + // The key for a map needs to be copyable. |
| + AsyncRevalidationKey(const AsyncRevalidationKey& rhs) = default; |
| + ~AsyncRevalidationKey(); |
| + |
| + // No operator= is generated because the struct members are immutable. |
| + |
| + // |resource_context| and |http_cache| are never dereferenced; they are only |
| + // compared to other values. In order to efficiently find and delete all |
| + // in-progress async revalidations using a particular ResourceContext, it |
| + // 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
|
| + const ResourceContext* const resource_context; |
| + |
| + // 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.
|
| + const net::HttpCache* const http_cache; |
| + |
| + // Derived from the url via net::HttpUtil::SpecForRequest(). |
| + const std::string url_key; |
| + |
| + struct LessThan { |
| + bool operator()(const AsyncRevalidationKey& lhs, |
| + const AsyncRevalidationKey& rhs) const; |
| + }; |
| + }; |
| + |
| + // 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.
|
| + 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.
|
| + AsyncRevalidationDriver*, |
| + AsyncRevalidationKey::LessThan> AsyncRevalidationMap; |
| + |
| + void OnAsyncRevalidationComplete(AsyncRevalidationMap::iterator it); |
| + |
| + // 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.
|
| + // scheduled or active on the network. |
| + AsyncRevalidationMap in_progress_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(AsyncRevalidationManager); |
| +}; |
| + |
| +} // namespace content |
| + |
| +#endif // CONTENT_BROWSER_LOADER_ASYNC_REVALIDATION_MANAGER_H_ |