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

Side by Side 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2016 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_CONTENT_SIZE_RESOURCE_HANDLER_MANAGER_H_
6 #define CONTENT_BROWSER_LOADER_CONTENT_SIZE_RESOURCE_HANDLER_MANAGER_H_
7
8 #include <map>
9
10 #include "base/macros.h"
11 #include "content/browser/loader/global_routing_id.h"
12 #include "content/browser/loader/resource_handler.h"
13 #include "net/url_request/url_request_status.h"
14
15 namespace net {
16 class URLRequest;
17 }
18
19 namespace content {
20
21 class ContentSizeResourceHandler;
22 class ResourceRequestInfoImpl;
23
24 // This class manages all in flight ContentSizeResourceHandlers. It keeps an IO
25 // thread map of GlobalFrameRoutingId -> bytes left, and keeps it as up to date
26 // as possible. This map is not exact, as it does not take into account child
27 // frames using up data from parent frames. To make the data accounting exact,
28 // the class periodically posts to the UI thread all of the current frame
29 // updates, and the UI thread posts back all of the frames that should be
30 // blocked.
31 class ContentSizeResourceHandlerManager {
32 public:
33 ContentSizeResourceHandlerManager();
34 ~ContentSizeResourceHandlerManager();
35
36 std::unique_ptr<ResourceHandler> MaybeAddHandler(
37 std::unique_ptr<ResourceHandler> next_handler,
38 net::URLRequest* request);
39
40 // Post a task to the UI thread of all the byte accounting updates so far.
41 // This is used for an asynchronous exact measurement of the policy.
42 void NotifyUIThreadReadUpdates();
43
44 bool ShouldCancelRequest(ResourceRequestInfoImpl* request_info,
45 uint64_t bytes_read);
46
47 // These methods are posted from the UI thread.
48 void FrameHasSizeLimit(const GlobalFrameRoutingId& id, uint64_t limit);
49 void FramesWentOverSizeLimits(
50 std::unique_ptr<std::set<GlobalFrameRoutingId>> ids);
51 void FrameDeleted(const GlobalFrameRoutingId& id);
52
53 private:
54 // As frames update their data accounting, use this map to keep track of bytes
55 // downloaded, which gets sent to the UI thread to sync the source of truth
56 // data.
57 std::unique_ptr<std::map<GlobalFrameRoutingId, uint64_t>> pending_updates_;
58
59 // Approximate data left per frame routing id. Resources for child frames do
60 // not update parent frames here, so this is an upper bound. This is a simple
61 // way to make easy case more accurate. If the UI thread notifies this class
62 // of a blocked id, it gets set to 0 here.
63 std::map<GlobalFrameRoutingId, uint64_t> frame_limits_;
64
65 DISALLOW_COPY_AND_ASSIGN(ContentSizeResourceHandlerManager);
66 };
67
68 } // namespace content
69
70 #endif // CONTENT_BROWSER_LOADER_CONTENT_SIZE_RESOURCE_HANDLER_MANAGER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698