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 #include "base/memory/scoped_ptr.h" |
| 13 |
| 14 class GURL; |
| 15 struct ResourceHostMsg_Request; |
| 16 |
| 17 namespace net { |
| 18 class URLRequest; |
| 19 class HttpCache; |
| 20 } |
| 21 |
| 22 namespace content { |
| 23 |
| 24 class AsyncRevalidationDriver; |
| 25 class ResourceContext; |
| 26 class ResourceScheduler; |
| 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(const 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( |
| 48 const ResourceHostMsg_Request& request); |
| 49 |
| 50 private: |
| 51 // The key of the map of pending async revalidations. This key has a distinct |
| 52 // value for every in-progress async revalidation. It is used to avoid |
| 53 // duplicate async revalidations, and also to cancel affected async |
| 54 // revalidations when a ResourceContext is removed. |
| 55 // |
| 56 // Request headers are intentionally not included in the key for simplicity, |
| 57 // as they usually don't affect caching. |
| 58 // |
| 59 // TODO(ricea): Behave correctly in cases where the request headers do make a |
| 60 // difference. crbug.com/567721 |
| 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. |
| 78 const ResourceContext* const resource_context; |
| 79 |
| 80 // There are multiple independent HttpCache objects per ResourceContext. |
| 81 const net::HttpCache* const http_cache; |
| 82 |
| 83 // Derived from the url via net::HttpUtil::SpecForRequest(). |
| 84 const std::string url_key; |
| 85 |
| 86 struct LessThan { |
| 87 bool operator()(const AsyncRevalidationKey& lhs, |
| 88 const AsyncRevalidationKey& rhs) const; |
| 89 }; |
| 90 }; |
| 91 |
| 92 using AsyncRevalidationMap = std::map<AsyncRevalidationKey, |
| 93 scoped_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 |