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

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

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.cc
diff --git a/content/browser/loader/content_size_resource_handler_manager.cc b/content/browser/loader/content_size_resource_handler_manager.cc
new file mode 100644
index 0000000000000000000000000000000000000000..c631a7378db39a0596090f4998784bf906c3c194
--- /dev/null
+++ b/content/browser/loader/content_size_resource_handler_manager.cc
@@ -0,0 +1,81 @@
+// 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.
+
+#include "content/browser/loader/content_size_resource_handler_manager.h"
+
+#include "base/bind.h"
+#include "base/stl_util.h"
+#include "content/browser/loader/content_size_frame_counter.h"
+#include "content/browser/loader/content_size_resource_handler.h"
+#include "content/browser/loader/resource_request_info_impl.h"
+#include "content/public/browser/browser_thread.h"
+#include "net/url_request/url_request.h"
+
+namespace content {
+
+ContentSizeResourceHandlerManager::ContentSizeResourceHandlerManager()
+ : pending_updates_(new std::map<GlobalFrameRoutingId, uint64_t>) {}
+ContentSizeResourceHandlerManager::~ContentSizeResourceHandlerManager() {}
+
+std::unique_ptr<ResourceHandler>
+ContentSizeResourceHandlerManager::MaybeAddHandler(
+ std::unique_ptr<ResourceHandler> next_handler,
+ net::URLRequest* request) {
+ ResourceRequestInfoImpl* info = ResourceRequestInfoImpl::ForRequest(request);
+ DCHECK(info);
+ if (info->IsMainFrame())
+ return next_handler;
+
+ if (ContainsKey(frame_limits_, info->GetGlobalFrameRoutingId())) {
+ next_handler.reset(
+ new ContentSizeResourceHandler(std::move(next_handler), request, this));
+ }
+ return next_handler;
+}
+
+bool ContentSizeResourceHandlerManager::ShouldCancelRequest(
+ ResourceRequestInfoImpl* request_info,
+ uint64_t bytes_read) {
+ const GlobalFrameRoutingId& id = request_info->GetGlobalFrameRoutingId();
+ (*pending_updates_)[id] += bytes_read;
+
+ auto it = frame_limits_.find(id);
+ if (it == frame_limits_.end()) {
+ return false;
+ } else if (it->second > bytes_read) {
+ it->second -= bytes_read;
+ return false;
+ } else {
+ it->second = 0;
+ return true;
+ }
+}
+
+void ContentSizeResourceHandlerManager::NotifyUIThreadReadUpdates() {
+ BrowserThread::PostTask(
+ BrowserThread::UI, FROM_HERE,
+ base::Bind(&ContentSizeFrameCounter::UpdateGlobalDataAccounting,
+ base::Passed(std::move(pending_updates_))));
+ pending_updates_.reset(new std::map<GlobalFrameRoutingId, uint64_t>);
+}
+
+void ContentSizeResourceHandlerManager::FrameHasSizeLimit(
+ const GlobalFrameRoutingId& id,
+ uint64_t limit) {
+ frame_limits_[id] = limit;
+}
+
+void ContentSizeResourceHandlerManager::FramesWentOverSizeLimits(
+ std::unique_ptr<std::set<GlobalFrameRoutingId>> ids) {
+ for (const auto& it : *ids) {
+ FrameHasSizeLimit(it, 0);
+ }
+}
+
+void ContentSizeResourceHandlerManager::FrameDeleted(
+ const GlobalFrameRoutingId& id) {
+ frame_limits_.erase(id);
+}
+
+} // namespace content
« no previous file with comments | « content/browser/loader/content_size_resource_handler_manager.h ('k') | content/browser/loader/resource_dispatcher_host_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698