| OLD | NEW |
| (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_FRAME_COUNTER_H_ |
| 6 #define CONTENT_BROWSER_LOADER_CONTENT_SIZE_FRAME_COUNTER_H_ |
| 7 |
| 8 #include "base/macros.h" |
| 9 #include "content/browser/loader/global_routing_id.h" |
| 10 #include "content/public/browser/navigation_throttle.h" |
| 11 #include "content/public/browser/web_contents_observer.h" |
| 12 |
| 13 namespace content { |
| 14 |
| 15 class FrameTreeNode; |
| 16 class NavigationHandle; |
| 17 class RenderFrameHost; |
| 18 class WebContents; |
| 19 |
| 20 // This class is designed to do all the UI thread data accounting for the size |
| 21 // policy feature. It exchanges messages with the |
| 22 // ContentSizeResourceHandlerManager on the IO thread. |
| 23 class ContentSizeFrameCounter : public WebContentsObserver { |
| 24 public: |
| 25 explicit ContentSizeFrameCounter(WebContents* web_contents); |
| 26 ~ContentSizeFrameCounter() override; |
| 27 |
| 28 // WebContentsObserver: |
| 29 void DidFinishNavigation(NavigationHandle* handle) override; |
| 30 |
| 31 static void UpdateGlobalDataAccounting( |
| 32 std::unique_ptr<std::map<GlobalFrameRoutingId, uint64_t>> updates); |
| 33 |
| 34 private: |
| 35 // TODO(csharrison): It may be useful to include other data here like |
| 36 // |content_limit|. |
| 37 struct FrameSize { |
| 38 // In bytes. This is the source of truth data for how many bytes are left |
| 39 // per frame tree node in |frame_tree_node_sizes_|. |
| 40 uint64_t content_left = 0; |
| 41 }; |
| 42 |
| 43 // This method walks up the frame tree, and sees if applying |limit| to the |
| 44 // frame is necessary. If a parent frame has a lower effective limit, then the |
| 45 // child frame's limit is not necessary. Returns the effective limit of |
| 46 // |node|. |
| 47 ContentSizeFrameCounter::FrameSize* AddNewFrame(FrameTreeNode* node, |
| 48 uint64_t limit); |
| 49 |
| 50 // Walks up the frame tree starting from |node|. Updates the content_left |
| 51 // count of every parent, and collects all of the routing ids to block due to |
| 52 // this update. |
| 53 void ApplyUpdateToTree(FrameTreeNode* node, |
| 54 uint64_t bytes_downloaded, |
| 55 std::set<GlobalFrameRoutingId>* routing_ids_to_block); |
| 56 |
| 57 static void NotifyFramesWentOverSizeLimits( |
| 58 std::unique_ptr<std::set<GlobalFrameRoutingId>> frames); |
| 59 static void NotifyFrameHasLimit(const GlobalFrameRoutingId& frame, |
| 60 uint64_t limit); |
| 61 |
| 62 void UpdateDataAccounting(std::map<GlobalFrameRoutingId, uint64_t> updates); |
| 63 |
| 64 // frame_tree_node_id -> FrameSize map. |
| 65 std::map<int, FrameSize> frame_tree_node_sizes_; |
| 66 |
| 67 DISALLOW_COPY_AND_ASSIGN(ContentSizeFrameCounter); |
| 68 }; |
| 69 |
| 70 } // namespace content |
| 71 |
| 72 #endif // CONTENT_BROWSER_LOADER_CONTENT_SIZE_FRAME_COUNTER_H_ |
| OLD | NEW |