OLD | NEW |
(Empty) | |
| 1 // Copyright 2017 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 CHROME_BROWSER_PAGE_LOAD_METRICS_OBSERVERS_ADS_PAGE_LOAD_METRICS_OBSERVE
R_H_ |
| 6 #define CHROME_BROWSER_PAGE_LOAD_METRICS_OBSERVERS_ADS_PAGE_LOAD_METRICS_OBSERVE
R_H_ |
| 7 |
| 8 #include <list> |
| 9 #include <unordered_map> |
| 10 |
| 11 #include "base/macros.h" |
| 12 #include "chrome/browser/page_load_metrics/page_load_metrics_observer.h" |
| 13 #include "net/http/http_response_info.h" |
| 14 |
| 15 class AdsPageLoadMetricsObserver |
| 16 : public page_load_metrics::PageLoadMetricsObserver { |
| 17 public: |
| 18 AdsPageLoadMetricsObserver(); |
| 19 ~AdsPageLoadMetricsObserver() override; |
| 20 |
| 21 // page_load_metrics::PageLoadMetricsObserver:s |
| 22 ObservePolicy OnCommit(content::NavigationHandle* navigation_handle) override; |
| 23 ObservePolicy OnCommitSubFrame( |
| 24 content::NavigationHandle* navigation_handle) override; |
| 25 ObservePolicy FlushMetricsOnAppEnterBackground( |
| 26 const page_load_metrics::PageLoadTiming& timing, |
| 27 const page_load_metrics::PageLoadExtraInfo& extra_info) override; |
| 28 void OnLoadedResource( |
| 29 const page_load_metrics::ExtraRequestInfo& extra_request_info) override; |
| 30 void OnComplete(const page_load_metrics::PageLoadTiming& timing, |
| 31 const page_load_metrics::PageLoadExtraInfo& info) override; |
| 32 |
| 33 private: |
| 34 struct AdFrameData { |
| 35 size_t frame_bytes; |
| 36 size_t frame_bytes_uncached; |
| 37 }; |
| 38 |
| 39 using FrameTreeNodeId = int; |
| 40 |
| 41 void RecordHistograms(); |
| 42 |
| 43 // Checks to see if a resource is waiting for |frame_tree_node_id| to commit |
| 44 // before it can be processed. If so, call OnLoadedResource for the delayed |
| 45 // resource. |
| 46 void ProcessDelayedResources(FrameTreeNodeId frame_tree_node_id); |
| 47 |
| 48 // Stores the size data of each ad frame. Pointed to by ad_frames_ so use a |
| 49 // data structure that won't move the data around. |
| 50 std::list<AdFrameData> ad_frames_data_storage_; |
| 51 |
| 52 // Maps a frame (by id) to the AdFrameData responsible for the frame. The |
| 53 // responsible frame is the top-most frame labeled as an ad in the frame's |
| 54 // ancestry, which may be itself. If no responsible frame is found, the data |
| 55 // is nullptr. |
| 56 std::unordered_map<FrameTreeNodeId, AdFrameData*> ad_frames_data_; |
| 57 |
| 58 // When the observer receives report of a document resource loading for a |
| 59 // sub-frame before the sub-frame commit occurs, hold onto the resource |
| 60 // request info (delay it) until the sub-frame commits. |
| 61 std::unordered_map<FrameTreeNodeId, page_load_metrics::ExtraRequestInfo> |
| 62 delayed_resources_; |
| 63 |
| 64 size_t page_bytes_ = 0; |
| 65 size_t uncached_page_bytes_ = 0; |
| 66 int top_level_frame_count_ = 0; |
| 67 int top_level_ad_frame_count_ = 0; |
| 68 |
| 69 bool enabled_ = true; |
| 70 |
| 71 DISALLOW_COPY_AND_ASSIGN(AdsPageLoadMetricsObserver); |
| 72 }; |
| 73 |
| 74 #endif // CHROME_BROWSER_PAGE_LOAD_METRICS_OBSERVERS_ADS_PAGE_LOAD_METRICS_OBSE
RVER_H_ |
OLD | NEW |