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

Side by Side Diff: chrome/browser/page_load_metrics/observers/ads_page_load_metrics_observer.cc

Issue 2910843002: [Cleanup] Move all browsertests to use ScopedFeatureList to modify features
Patch Set: Move SFL calls to constructor Created 3 years, 5 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
1 // Copyright 2017 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/page_load_metrics/observers/ads_page_load_metrics_obser ver.h" 5 #include "chrome/browser/page_load_metrics/observers/ads_page_load_metrics_obser ver.h"
6 6
7 #include <string> 7 #include <string>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/feature_list.h" 10 #include "base/feature_list.h"
11 #include "base/logging.h" 11 #include "base/logging.h"
12 #include "base/memory/ptr_util.h" 12 #include "base/memory/ptr_util.h"
13 #include "base/strings/string_util.h" 13 #include "base/strings/string_util.h"
14 #include "chrome/browser/page_load_metrics/page_load_metrics_util.h" 14 #include "chrome/browser/page_load_metrics/page_load_metrics_util.h"
15 #include "chrome/common/chrome_features.h"
15 #include "content/public/browser/navigation_handle.h" 16 #include "content/public/browser/navigation_handle.h"
16 #include "content/public/browser/render_frame_host.h" 17 #include "content/public/browser/render_frame_host.h"
17 #include "content/public/browser/web_contents.h" 18 #include "content/public/browser/web_contents.h"
18 #include "url/gurl.h" 19 #include "url/gurl.h"
19 20
20 namespace { 21 namespace {
21 22
22 const base::Feature kAdsFeature{"AdsMetrics", base::FEATURE_ENABLED_BY_DEFAULT};
23
24 bool FrameIsAd(content::NavigationHandle* navigation_handle) { 23 bool FrameIsAd(content::NavigationHandle* navigation_handle) {
25 // Because sub-resource filtering isn't always enabled, and doesn't work 24 // Because sub-resource filtering isn't always enabled, and doesn't work
26 // well in monitoring mode (no CSS enforcement), it's difficult to identify 25 // well in monitoring mode (no CSS enforcement), it's difficult to identify
27 // ads. Google ads are prevalent and easy to track, so we'll start by 26 // ads. Google ads are prevalent and easy to track, so we'll start by
28 // tracking those. Note that the frame name can be very large, so be careful 27 // tracking those. Note that the frame name can be very large, so be careful
29 // to avoid full string searches if possible. 28 // to avoid full string searches if possible.
30 // TODO(jkarlin): Track other ad networks that are easy to identify. 29 // TODO(jkarlin): Track other ad networks that are easy to identify.
31 30
32 // In case the navigation aborted, look up the RFH by the Frame Tree Node 31 // In case the navigation aborted, look up the RFH by the Frame Tree Node
33 // ID. It returns the committed frame host or the initial frame host for the 32 // ID. It returns the committed frame host or the initial frame host for the
(...skipping 30 matching lines...) Expand all
64 63
65 AdsPageLoadMetricsObserver::AdFrameData::AdFrameData( 64 AdsPageLoadMetricsObserver::AdFrameData::AdFrameData(
66 FrameTreeNodeId frame_tree_node_id) 65 FrameTreeNodeId frame_tree_node_id)
67 : frame_bytes(0u), 66 : frame_bytes(0u),
68 frame_bytes_uncached(0u), 67 frame_bytes_uncached(0u),
69 frame_tree_node_id(frame_tree_node_id) {} 68 frame_tree_node_id(frame_tree_node_id) {}
70 69
71 // static 70 // static
72 std::unique_ptr<AdsPageLoadMetricsObserver> 71 std::unique_ptr<AdsPageLoadMetricsObserver>
73 AdsPageLoadMetricsObserver::CreateIfNeeded() { 72 AdsPageLoadMetricsObserver::CreateIfNeeded() {
74 if (!base::FeatureList::IsEnabled(kAdsFeature)) 73 if (!base::FeatureList::IsEnabled(features::kAdsFeature))
75 return nullptr; 74 return nullptr;
76 return base::MakeUnique<AdsPageLoadMetricsObserver>(); 75 return base::MakeUnique<AdsPageLoadMetricsObserver>();
77 } 76 }
78 77
79 AdsPageLoadMetricsObserver::AdsPageLoadMetricsObserver() = default; 78 AdsPageLoadMetricsObserver::AdsPageLoadMetricsObserver() = default;
80 AdsPageLoadMetricsObserver::~AdsPageLoadMetricsObserver() = default; 79 AdsPageLoadMetricsObserver::~AdsPageLoadMetricsObserver() = default;
81 80
82 page_load_metrics::PageLoadMetricsObserver::ObservePolicy 81 page_load_metrics::PageLoadMetricsObserver::ObservePolicy
83 AdsPageLoadMetricsObserver::OnCommit( 82 AdsPageLoadMetricsObserver::OnCommit(
84 content::NavigationHandle* navigation_handle, 83 content::NavigationHandle* navigation_handle,
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after
295 void AdsPageLoadMetricsObserver::ProcessOngoingNavigationResource( 294 void AdsPageLoadMetricsObserver::ProcessOngoingNavigationResource(
296 FrameTreeNodeId frame_tree_node_id) { 295 FrameTreeNodeId frame_tree_node_id) {
297 const auto& frame_id_and_request = 296 const auto& frame_id_and_request =
298 ongoing_navigation_resources_.find(frame_tree_node_id); 297 ongoing_navigation_resources_.find(frame_tree_node_id);
299 if (frame_id_and_request == ongoing_navigation_resources_.end()) 298 if (frame_id_and_request == ongoing_navigation_resources_.end())
300 return; 299 return;
301 300
302 ProcessLoadedResource(frame_id_and_request->second); 301 ProcessLoadedResource(frame_id_and_request->second);
303 ongoing_navigation_resources_.erase(frame_id_and_request); 302 ongoing_navigation_resources_.erase(frame_id_and_request);
304 } 303 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698