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

Unified Diff: chrome/browser/page_load_metrics/observers/ads_page_load_metrics_observer.h

Issue 2798953002: [PageLoadMetrics] Keep track of Ad Sizes on Pages (Closed)
Patch Set: Address comments from PS11-13 Created 3 years, 8 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: chrome/browser/page_load_metrics/observers/ads_page_load_metrics_observer.h
diff --git a/chrome/browser/page_load_metrics/observers/ads_page_load_metrics_observer.h b/chrome/browser/page_load_metrics/observers/ads_page_load_metrics_observer.h
new file mode 100644
index 0000000000000000000000000000000000000000..5709588193df2329016db08e8b6db4c0acf908c9
--- /dev/null
+++ b/chrome/browser/page_load_metrics/observers/ads_page_load_metrics_observer.h
@@ -0,0 +1,77 @@
+// Copyright 2017 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.
+
+#ifndef CHROME_BROWSER_PAGE_LOAD_METRICS_OBSERVERS_ADS_PAGE_LOAD_METRICS_OBSERVER_H_
+#define CHROME_BROWSER_PAGE_LOAD_METRICS_OBSERVERS_ADS_PAGE_LOAD_METRICS_OBSERVER_H_
+
+#include <list>
+#include <memory>
+#include <unordered_map>
+
+#include "base/macros.h"
+#include "chrome/browser/page_load_metrics/page_load_metrics_observer.h"
+#include "net/http/http_response_info.h"
+
+class AdsPageLoadMetricsObserver
+ : public page_load_metrics::PageLoadMetricsObserver {
+ public:
+ // Returns a new AdsPageLoadMetricObserver. If the feature is disabled it
+ // returns nullptr.
+ static std::unique_ptr<AdsPageLoadMetricsObserver> CreateIfNeeded();
+
+ AdsPageLoadMetricsObserver();
+ ~AdsPageLoadMetricsObserver() override;
+
+ // page_load_metrics::PageLoadMetricsObserver:s
Charlie Harrison 2017/04/14 20:16:26 nit: remove the s.
jkarlin 2017/04/24 17:27:59 Done.
+ ObservePolicy OnCommit(content::NavigationHandle* navigation_handle) override;
+ ObservePolicy OnCommitSubFrame(
+ content::NavigationHandle* navigation_handle) override;
+ ObservePolicy FlushMetricsOnAppEnterBackground(
+ const page_load_metrics::PageLoadTiming& timing,
+ const page_load_metrics::PageLoadExtraInfo& extra_info) override;
+ void OnLoadedResource(
+ const page_load_metrics::ExtraRequestInfo& extra_request_info) override;
+ void OnComplete(const page_load_metrics::PageLoadTiming& timing,
+ const page_load_metrics::PageLoadExtraInfo& info) override;
+
+ private:
+ struct AdFrameData {
+ size_t frame_bytes;
+ size_t frame_bytes_uncached;
+ };
+
+ using FrameTreeNodeId = int;
+
+ void RecordHistograms();
+
+ // Checks to see if a resource is waiting for |frame_tree_node_id| to commit
Charlie Harrison 2017/04/14 20:16:26 for a navigation with the given |frame_tree_node_i
jkarlin 2017/04/24 17:27:59 Done.
+ // before it can be processed. If so, call OnLoadedResource for the delayed
+ // resource.
+ void ProcessOngoingNavigationResources(FrameTreeNodeId frame_tree_node_id);
Bryan McQuade 2017/04/17 22:00:04 nit: when i read this name, which has Resources pl
jkarlin 2017/04/24 17:27:59 Done.
+
+ // Stores the size data of each ad frame. Pointed to by ad_frames_ so use a
+ // data structure that won't move the data around.
+ std::list<AdFrameData> ad_frames_data_storage_;
Bryan McQuade 2017/04/17 22:00:04 My sense is that ad_frames_data_storage_ and ad_fr
jkarlin 2017/04/24 17:27:59 I think pretty much all of the logic would wind up
Bryan McQuade 2017/04/24 19:28:22 Sure - I'm fine with that.
+
+ // Maps a frame (by id) to the AdFrameData responsible for the frame. The
+ // responsible frame is the top-most frame labeled as an ad in the frame's
Bryan McQuade 2017/04/14 19:19:23 it sounds like it's possible for multiple FrameTre
jkarlin 2017/04/24 17:27:59 Done.
+ // ancestry, which may be itself. If no responsible frame is found, the data
+ // is nullptr.
+ std::unordered_map<FrameTreeNodeId, AdFrameData*> ad_frames_data_;
+
+ // When the observer receives report of a document resource loading for a
+ // sub-frame before the sub-frame commit occurs, hold onto the resource
+ // request info (delay it) until the sub-frame commits.
+ std::unordered_map<FrameTreeNodeId, page_load_metrics::ExtraRequestInfo>
+ ongoing_navigation_resources_;
+
+ size_t page_bytes_ = 0u;
+ size_t uncached_page_bytes_ = 0u;
+ int top_level_subframe_count_ = 0;
+ int top_level_ad_frame_count_ = 0;
+
+ DISALLOW_COPY_AND_ASSIGN(AdsPageLoadMetricsObserver);
+};
+
+#endif // CHROME_BROWSER_PAGE_LOAD_METRICS_OBSERVERS_ADS_PAGE_LOAD_METRICS_OBSERVER_H_

Powered by Google App Engine
This is Rietveld 408576698