| 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 <memory> | |
| 10 #include <string> | |
| 11 | |
| 12 #include "base/macros.h" | |
| 13 | |
| 14 class GURL; | |
| 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 struct ResourceRequest; | |
| 27 | |
| 28 // One instance of this class manages all active AsyncRevalidationDriver objects | |
| 29 // for all profiles. It is created by and owned by | |
| 30 // ResourceDispatcherHostImpl. It also implements the creation of a new | |
| 31 // net::URLRequest and AsyncRevalidationDriver from an existing net::URLRequest | |
| 32 // that has had the stale-while-revalidate algorithm applied to it. | |
| 33 class AsyncRevalidationManager { | |
| 34 public: | |
| 35 AsyncRevalidationManager(); | |
| 36 ~AsyncRevalidationManager(); | |
| 37 | |
| 38 // Starts an async revalidation by copying |for_request|. |scheduler| must | |
| 39 // remain valid until this object is destroyed. | |
| 40 void BeginAsyncRevalidation(net::URLRequest* for_request, | |
| 41 ResourceScheduler* scheduler); | |
| 42 | |
| 43 // Cancel all pending async revalidations that use ResourceContext. | |
| 44 void CancelAsyncRevalidationsForResourceContext( | |
| 45 ResourceContext* resource_context); | |
| 46 | |
| 47 static bool QualifiesForAsyncRevalidation(const ResourceRequest& request); | |
| 48 | |
| 49 private: | |
| 50 // The key of the map of pending async revalidations. This key has a distinct | |
| 51 // value for every in-progress async revalidation. It is used to avoid | |
| 52 // duplicate async revalidations, and also to cancel affected async | |
| 53 // revalidations when a ResourceContext is removed. | |
| 54 // | |
| 55 // Request headers are intentionally not included in the key for simplicity, | |
| 56 // as they usually don't affect caching. | |
| 57 // | |
| 58 // TODO(ricea): Behave correctly in cases where the request headers do make a | |
| 59 // difference. crbug.com/567721 | |
| 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 = | |
| 92 std::map<AsyncRevalidationKey, | |
| 93 std::unique_ptr<AsyncRevalidationDriver>, | |
| 94 AsyncRevalidationKey::LessThan>; | |
| 95 | |
| 96 void OnAsyncRevalidationComplete(AsyncRevalidationMap::iterator it); | |
| 97 | |
| 98 // Map of AsyncRevalidationDriver instances that are currently in-flight: | |
| 99 // either waiting to be scheduled or active on the network. | |
| 100 AsyncRevalidationMap in_progress_; | |
| 101 | |
| 102 DISALLOW_COPY_AND_ASSIGN(AsyncRevalidationManager); | |
| 103 }; | |
| 104 | |
| 105 } // namespace content | |
| 106 | |
| 107 #endif // CONTENT_BROWSER_LOADER_ASYNC_REVALIDATION_MANAGER_H_ | |
| OLD | NEW |