Chromium Code Reviews| 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_RESOURCE_HANDLER_H_ | |
| 6 #define CONTENT_BROWSER_LOADER_CONTENT_SIZE_RESOURCE_HANDLER_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/layered_resource_handler.h" | |
| 13 #include "net/url_request/url_request_status.h" | |
| 14 #include "url/gurl.h" | |
| 15 | |
| 16 namespace net { | |
| 17 class URLRequest; | |
| 18 } | |
| 19 | |
| 20 namespace content { | |
| 21 | |
| 22 class ContentSizeResourceHandler; | |
| 23 class ResourceRequestInfoImpl; | |
| 24 | |
| 25 // This class manages all in flight ContentSizeResourceHandlers. It keeps an IO | |
| 26 // thread map of GlobalFrameRoutingId -> bytes left, and keeps it as up to date | |
| 27 // as possible. This map is not exact, as it does not take into account child | |
| 28 // frames using up data from parent frames. To make the data accounting exact, | |
| 29 // the class periodically posts to the UI thread all of the current frame | |
| 30 // updates, and the UI thread posts back all of the frames that should be | |
| 31 // blocked. | |
| 32 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.
| |
| 33 public: | |
| 34 ContentSizeResourceHandlerManager(); | |
| 35 ~ContentSizeResourceHandlerManager(); | |
| 36 | |
| 37 std::unique_ptr<ResourceHandler> MaybeAddHandler( | |
| 38 std::unique_ptr<ResourceHandler> next_handler, | |
| 39 net::URLRequest* request); | |
| 40 | |
| 41 // Post a task to the UI thread of all the byte accounting updates so far. | |
| 42 // This is used for an asynchronous exact measurement of the policy. | |
| 43 void NotifyUIThreadReadUpdates(); | |
| 44 void NotifyRead(ResourceRequestInfoImpl* request_info, int bytes_read); | |
| 45 | |
| 46 // These methods are posted from the UI thread. | |
| 47 void FrameHasSizeLimit(const GlobalFrameRoutingId& id, int limit); | |
| 48 void FramesWentOverSizeLimits( | |
| 49 std::unique_ptr<std::set<GlobalFrameRoutingId>> ids); | |
| 50 void FrameDeleted(const GlobalFrameRoutingId& id); | |
| 51 | |
| 52 private: | |
| 53 // As frames update their data accounting, use this map to keep track of bytes | |
| 54 // downloaded, which gets sent to the UI thread to sync the source of truth | |
| 55 // data. | |
| 56 std::unique_ptr<std::map<GlobalFrameRoutingId, int>> pending_updates_; | |
| 57 | |
| 58 // Approximate data left per frame routing id. Resources for child frames do | |
| 59 // not update parent frames here, so this is an upper bound. This is a simple | |
| 60 // way to make easy case more accurate. If the UI thread notifies this class | |
| 61 // of a blocked id, it gets set to 0 here. | |
| 62 std::map<GlobalFrameRoutingId, int> frame_limits_; | |
| 63 }; | |
| 64 | |
| 65 class ContentSizeResourceHandler : public LayeredResourceHandler { | |
| 66 public: | |
| 67 ContentSizeResourceHandler( | |
| 68 std::unique_ptr<ResourceHandler> next_handler, | |
| 69 net::URLRequest* request, | |
| 70 ContentSizeResourceHandlerManager* manager, | |
| 71 std::map<GlobalFrameRoutingId, int>::iterator frame_limit_iterator); | |
| 72 ~ContentSizeResourceHandler() override; | |
| 73 | |
| 74 private: | |
| 75 // ResourceHandler: | |
| 76 bool OnWillStart(const GURL&, bool* defer) override; | |
| 77 bool OnReadCompleted(int bytes_read, bool* defer) override; | |
| 78 void OnResponseCompleted(const net::URLRequestStatus& status, | |
| 79 const std::string& security_info, | |
| 80 bool* defer) override; | |
| 81 | |
| 82 ContentSizeResourceHandlerManager* manager_; | |
| 83 | |
| 84 std::map<GlobalFrameRoutingId, int>::iterator frame_limit_iterator_; | |
| 85 | |
| 86 DISALLOW_COPY_AND_ASSIGN(ContentSizeResourceHandler); | |
| 87 }; | |
| 88 | |
| 89 } // namespace content | |
| 90 | |
| 91 #endif // CONTENT_BROWSER_LOADER_CONTENT_SIZE_RESOURCE_HANDLER_H_ | |
| OLD | NEW |