OLD | NEW |
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" | |
11 #include "base/logging.h" | 10 #include "base/logging.h" |
12 #include "base/memory/ptr_util.h" | 11 #include "base/memory/ptr_util.h" |
13 #include "base/strings/string_util.h" | 12 #include "base/strings/string_util.h" |
14 #include "chrome/browser/page_load_metrics/page_load_metrics_util.h" | 13 #include "chrome/browser/page_load_metrics/page_load_metrics_util.h" |
15 #include "content/public/browser/navigation_handle.h" | 14 #include "content/public/browser/navigation_handle.h" |
16 #include "content/public/browser/render_frame_host.h" | 15 #include "content/public/browser/render_frame_host.h" |
17 #include "content/public/browser/web_contents.h" | 16 #include "content/public/browser/web_contents.h" |
18 #include "url/gurl.h" | 17 #include "url/gurl.h" |
19 | 18 |
20 namespace { | 19 namespace features { |
21 | 20 |
22 const base::Feature kAdsFeature{"AdsMetrics", base::FEATURE_ENABLED_BY_DEFAULT}; | 21 const base::Feature kAdsFeature{"AdsMetrics", base::FEATURE_ENABLED_BY_DEFAULT}; |
23 | 22 |
| 23 } // namespace features |
| 24 |
| 25 namespace { |
| 26 |
24 bool FrameIsAd(content::NavigationHandle* navigation_handle) { | 27 bool FrameIsAd(content::NavigationHandle* navigation_handle) { |
25 // Because sub-resource filtering isn't always enabled, and doesn't work | 28 // 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 | 29 // 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 | 30 // 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 | 31 // tracking those. Note that the frame name can be very large, so be careful |
29 // to avoid full string searches if possible. | 32 // to avoid full string searches if possible. |
30 // TODO(jkarlin): Track other ad networks that are easy to identify. | 33 // TODO(jkarlin): Track other ad networks that are easy to identify. |
31 | 34 |
32 // In case the navigation aborted, look up the RFH by the Frame Tree Node | 35 // 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 | 36 // ID. It returns the committed frame host or the initial frame host for the |
(...skipping 30 matching lines...) Expand all Loading... |
64 | 67 |
65 AdsPageLoadMetricsObserver::AdFrameData::AdFrameData( | 68 AdsPageLoadMetricsObserver::AdFrameData::AdFrameData( |
66 FrameTreeNodeId frame_tree_node_id) | 69 FrameTreeNodeId frame_tree_node_id) |
67 : frame_bytes(0u), | 70 : frame_bytes(0u), |
68 frame_bytes_uncached(0u), | 71 frame_bytes_uncached(0u), |
69 frame_tree_node_id(frame_tree_node_id) {} | 72 frame_tree_node_id(frame_tree_node_id) {} |
70 | 73 |
71 // static | 74 // static |
72 std::unique_ptr<AdsPageLoadMetricsObserver> | 75 std::unique_ptr<AdsPageLoadMetricsObserver> |
73 AdsPageLoadMetricsObserver::CreateIfNeeded() { | 76 AdsPageLoadMetricsObserver::CreateIfNeeded() { |
74 if (!base::FeatureList::IsEnabled(kAdsFeature)) | 77 if (!base::FeatureList::IsEnabled(features::kAdsFeature)) |
75 return nullptr; | 78 return nullptr; |
76 return base::MakeUnique<AdsPageLoadMetricsObserver>(); | 79 return base::MakeUnique<AdsPageLoadMetricsObserver>(); |
77 } | 80 } |
78 | 81 |
79 AdsPageLoadMetricsObserver::AdsPageLoadMetricsObserver() = default; | 82 AdsPageLoadMetricsObserver::AdsPageLoadMetricsObserver() = default; |
80 AdsPageLoadMetricsObserver::~AdsPageLoadMetricsObserver() = default; | 83 AdsPageLoadMetricsObserver::~AdsPageLoadMetricsObserver() = default; |
81 | 84 |
82 page_load_metrics::PageLoadMetricsObserver::ObservePolicy | 85 page_load_metrics::PageLoadMetricsObserver::ObservePolicy |
83 AdsPageLoadMetricsObserver::OnCommit( | 86 AdsPageLoadMetricsObserver::OnCommit( |
84 content::NavigationHandle* navigation_handle, | 87 content::NavigationHandle* navigation_handle, |
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
302 void AdsPageLoadMetricsObserver::ProcessOngoingNavigationResource( | 305 void AdsPageLoadMetricsObserver::ProcessOngoingNavigationResource( |
303 FrameTreeNodeId frame_tree_node_id) { | 306 FrameTreeNodeId frame_tree_node_id) { |
304 const auto& frame_id_and_request = | 307 const auto& frame_id_and_request = |
305 ongoing_navigation_resources_.find(frame_tree_node_id); | 308 ongoing_navigation_resources_.find(frame_tree_node_id); |
306 if (frame_id_and_request == ongoing_navigation_resources_.end()) | 309 if (frame_id_and_request == ongoing_navigation_resources_.end()) |
307 return; | 310 return; |
308 | 311 |
309 ProcessLoadedResource(frame_id_and_request->second); | 312 ProcessLoadedResource(frame_id_and_request->second); |
310 ongoing_navigation_resources_.erase(frame_id_and_request); | 313 ongoing_navigation_resources_.erase(frame_id_and_request); |
311 } | 314 } |
OLD | NEW |