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

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

Issue 2180933002: Add experimental code behind a flag for Content Size Policy (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: while -> for Created 4 years, 4 months 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/content_size_resource_handler_manager.h
diff --git a/content/browser/loader/content_size_resource_handler_manager.h b/content/browser/loader/content_size_resource_handler_manager.h
new file mode 100644
index 0000000000000000000000000000000000000000..cd878f6d7b8e40366856c163e4a31ad2baeb1322
--- /dev/null
+++ b/content/browser/loader/content_size_resource_handler_manager.h
@@ -0,0 +1,70 @@
+// Copyright 2016 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_CONTENT_SIZE_RESOURCE_HANDLER_MANAGER_H_
+#define CONTENT_BROWSER_LOADER_CONTENT_SIZE_RESOURCE_HANDLER_MANAGER_H_
+
+#include <map>
+
+#include "base/macros.h"
+#include "content/browser/loader/global_routing_id.h"
+#include "content/browser/loader/resource_handler.h"
+#include "net/url_request/url_request_status.h"
+
+namespace net {
+class URLRequest;
+}
+
+namespace content {
+
+class ContentSizeResourceHandler;
+class ResourceRequestInfoImpl;
+
+// This class manages all in flight ContentSizeResourceHandlers. It keeps an IO
+// thread map of GlobalFrameRoutingId -> bytes left, and keeps it as up to date
+// as possible. This map is not exact, as it does not take into account child
+// frames using up data from parent frames. To make the data accounting exact,
+// the class periodically posts to the UI thread all of the current frame
+// updates, and the UI thread posts back all of the frames that should be
+// blocked.
+class ContentSizeResourceHandlerManager {
+ public:
+ ContentSizeResourceHandlerManager();
+ ~ContentSizeResourceHandlerManager();
+
+ std::unique_ptr<ResourceHandler> MaybeAddHandler(
+ std::unique_ptr<ResourceHandler> next_handler,
+ net::URLRequest* request);
+
+ // Post a task to the UI thread of all the byte accounting updates so far.
+ // This is used for an asynchronous exact measurement of the policy.
+ void NotifyUIThreadReadUpdates();
+
+ bool ShouldCancelRequest(ResourceRequestInfoImpl* request_info,
+ uint64_t bytes_read);
+
+ // These methods are posted from the UI thread.
+ void FrameHasSizeLimit(const GlobalFrameRoutingId& id, uint64_t limit);
+ void FramesWentOverSizeLimits(
+ std::unique_ptr<std::set<GlobalFrameRoutingId>> ids);
+ void FrameDeleted(const GlobalFrameRoutingId& id);
+
+ private:
+ // As frames update their data accounting, use this map to keep track of bytes
+ // downloaded, which gets sent to the UI thread to sync the source of truth
+ // data.
+ std::unique_ptr<std::map<GlobalFrameRoutingId, uint64_t>> pending_updates_;
+
+ // Approximate data left per frame routing id. Resources for child frames do
+ // not update parent frames here, so this is an upper bound. This is a simple
+ // way to make easy case more accurate. If the UI thread notifies this class
+ // of a blocked id, it gets set to 0 here.
+ std::map<GlobalFrameRoutingId, uint64_t> frame_limits_;
+
+ DISALLOW_COPY_AND_ASSIGN(ContentSizeResourceHandlerManager);
+};
+
+} // namespace content
+
+#endif // CONTENT_BROWSER_LOADER_CONTENT_SIZE_RESOURCE_HANDLER_MANAGER_H_

Powered by Google App Engine
This is Rietveld 408576698