Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(813)

Unified Diff: content/browser/loader/async_revalidation_manager.h

Issue 1041993004: content::ResourceDispatcherHostImpl changes for stale-while-revalidate (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@s-w-r-yhirano-patch
Patch Set: Use histograms instead of user actions. Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..1070ea9c8bc86f70f76093391e8cb112b9aee277
--- /dev/null
+++ b/content/browser/loader/async_revalidation_manager.h
@@ -0,0 +1,107 @@
+// 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"
+#include "base/memory/scoped_ptr.h"
+
+class GURL;
+struct ResourceHostMsg_Request;
+
+namespace net {
+class URLRequest;
+class HttpCache;
+}
+
+namespace content {
+
+class AsyncRevalidationDriver;
+class ResourceContext;
+class ResourceScheduler;
+
+// One instance of this class manages all active AsyncRevalidationDriver objects
+// for all profiles. It is created by and owned by
+// ResourceDispatcherHostImpl. 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(const 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 of the map of pending 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 for simplicity,
+ // as they usually don't affect caching.
+ //
+ // TODO(ricea): Behave correctly in cases where the request headers do make a
+ // difference. crbug.com/567721
+ 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.
+ const ResourceContext* const resource_context;
+
+ // There are multiple independent HttpCache objects per ResourceContext.
+ 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;
+ };
+ };
+
+ using AsyncRevalidationMap = std::map<AsyncRevalidationKey,
+ scoped_ptr<AsyncRevalidationDriver>,
+ AsyncRevalidationKey::LessThan>;
+
+ void OnAsyncRevalidationComplete(AsyncRevalidationMap::iterator it);
+
+ // Map of AsyncRevalidationDriver instances that are currently in-flight:
+ // either waiting to be scheduled or active on the network.
+ AsyncRevalidationMap in_progress_;
+
+ DISALLOW_COPY_AND_ASSIGN(AsyncRevalidationManager);
+};
+
+} // namespace content
+
+#endif // CONTENT_BROWSER_LOADER_ASYNC_REVALIDATION_MANAGER_H_
« no previous file with comments | « content/browser/loader/async_revalidation_driver_unittest.cc ('k') | content/browser/loader/async_revalidation_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698