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

Unified Diff: content/browser/loader/content_size_resource_handler.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: rebase on dependent PS Created 4 years, 5 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.h
diff --git a/content/browser/loader/content_size_resource_handler.h b/content/browser/loader/content_size_resource_handler.h
new file mode 100644
index 0000000000000000000000000000000000000000..dcbe0cc12ba88d1019821c4e409d771baf2b1814
--- /dev/null
+++ b/content/browser/loader/content_size_resource_handler.h
@@ -0,0 +1,91 @@
+// 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_H_
+#define CONTENT_BROWSER_LOADER_CONTENT_SIZE_RESOURCE_HANDLER_H_
+
+#include <map>
+
+#include "base/macros.h"
+#include "content/browser/loader/global_routing_id.h"
+#include "content/browser/loader/layered_resource_handler.h"
+#include "net/url_request/url_request_status.h"
+#include "url/gurl.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 {
mmenke 2016/08/05 17:16:27 I'm not a fan of having two top-level classes in a
Charlie Harrison 2016/08/08 14:04:38 SGTM moved to a separate file.
+ 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();
+ void NotifyRead(ResourceRequestInfoImpl* request_info, int bytes_read);
+
+ // These methods are posted from the UI thread.
+ void FrameHasSizeLimit(const GlobalFrameRoutingId& id, int 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, int>> 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, int> frame_limits_;
+};
+
+class ContentSizeResourceHandler : public LayeredResourceHandler {
+ public:
+ ContentSizeResourceHandler(
+ std::unique_ptr<ResourceHandler> next_handler,
+ net::URLRequest* request,
+ ContentSizeResourceHandlerManager* manager,
+ std::map<GlobalFrameRoutingId, int>::iterator frame_limit_iterator);
+ ~ContentSizeResourceHandler() override;
+
+ private:
+ // ResourceHandler:
+ bool OnWillStart(const GURL&, bool* defer) override;
+ bool OnReadCompleted(int bytes_read, bool* defer) override;
+ void OnResponseCompleted(const net::URLRequestStatus& status,
+ const std::string& security_info,
+ bool* defer) override;
+
+ ContentSizeResourceHandlerManager* manager_;
+
+ std::map<GlobalFrameRoutingId, int>::iterator frame_limit_iterator_;
+
+ DISALLOW_COPY_AND_ASSIGN(ContentSizeResourceHandler);
+};
+
+} // namespace content
+
+#endif // CONTENT_BROWSER_LOADER_CONTENT_SIZE_RESOURCE_HANDLER_H_

Powered by Google App Engine
This is Rietveld 408576698