1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
android_webview / browser / page_load_metrics / page_load_metrics_initialize.cc [blame]
// Copyright 2019 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "android_webview/browser/page_load_metrics/page_load_metrics_initialize.h"
#include "android_webview/browser/page_load_metrics/aw_gws_page_load_metrics_observer.h"
#include "android_webview/browser/page_load_metrics/aw_page_load_metrics_memory_tracker_factory.h"
#include "android_webview/browser/page_load_metrics/service_level_page_load_metrics_observer.h"
#include "components/page_load_metrics/browser/metrics_web_contents_observer.h"
#include "components/page_load_metrics/browser/observers/abandoned_page_load_metrics_observer.h"
#include "components/page_load_metrics/browser/observers/third_party_metrics_observer.h"
#include "components/page_load_metrics/browser/page_load_metrics_embedder_base.h"
#include "components/page_load_metrics/browser/page_load_metrics_memory_tracker.h"
#include "components/page_load_metrics/browser/page_load_tracker.h"
#include "components/page_load_metrics/google/browser/gws_abandoned_page_load_metrics_observer.h"
namespace content {
class BrowserContext;
} // namespace content
namespace page_load_metrics {
class PageLoadMetricsMemoryTracker;
} // namespace page_load_metrics
namespace android_webview {
namespace {
class PageLoadMetricsEmbedder
: public page_load_metrics::PageLoadMetricsEmbedderBase {
public:
explicit PageLoadMetricsEmbedder(content::WebContents* web_contents);
PageLoadMetricsEmbedder(const PageLoadMetricsEmbedder&) = delete;
PageLoadMetricsEmbedder& operator=(const PageLoadMetricsEmbedder&) = delete;
~PageLoadMetricsEmbedder() override;
// page_load_metrics::PageLoadMetricsEmbedderBase:
bool IsNewTabPageUrl(const GURL& url) override;
bool IsNoStatePrefetch(content::WebContents* web_contents) override;
bool IsExtensionUrl(const GURL& url) override;
bool IsNonTabWebUI(const GURL& url) override;
page_load_metrics::PageLoadMetricsMemoryTracker*
GetMemoryTrackerForBrowserContext(
content::BrowserContext* browser_context) override;
protected:
// page_load_metrics::PageLoadMetricsEmbedderBase:
void RegisterObservers(page_load_metrics::PageLoadTracker* tracker,
content::NavigationHandle* navigation_handle) override;
};
PageLoadMetricsEmbedder::PageLoadMetricsEmbedder(
content::WebContents* web_contents)
: PageLoadMetricsEmbedderBase(web_contents) {}
PageLoadMetricsEmbedder::~PageLoadMetricsEmbedder() = default;
void PageLoadMetricsEmbedder::RegisterObservers(
page_load_metrics::PageLoadTracker* tracker,
content::NavigationHandle* navigation_handle) {
RegisterCommonObservers(tracker);
tracker->AddObserver(std::make_unique<ThirdPartyMetricsObserver>());
tracker->AddObserver(std::make_unique<AbandonedPageLoadMetricsObserver>());
tracker->AddObserver(std::make_unique<GWSAbandonedPageLoadMetricsObserver>());
tracker->AddObserver(std::make_unique<AwGWSPageLoadMetricsObserver>());
tracker->AddObserver(std::make_unique<ServiceLevelPageLoadMetricsObserver>());
}
bool PageLoadMetricsEmbedder::IsNewTabPageUrl(const GURL& url) {
return false;
}
bool PageLoadMetricsEmbedder::IsNoStatePrefetch(
content::WebContents* web_contents) {
return false;
}
bool PageLoadMetricsEmbedder::IsExtensionUrl(const GURL& url) {
return false;
}
bool PageLoadMetricsEmbedder::IsNonTabWebUI(const GURL& url) {
// Android web view doesn't have non-tab webUI surfaces (such as desktop tab
// search, side panel, etc).
return false;
}
page_load_metrics::PageLoadMetricsMemoryTracker*
PageLoadMetricsEmbedder::GetMemoryTrackerForBrowserContext(
content::BrowserContext* browser_context) {
if (!base::FeatureList::IsEnabled(features::kV8PerFrameMemoryMonitoring))
return nullptr;
return AwPageLoadMetricsMemoryTrackerFactory::GetForBrowserContext(
browser_context);
}
} // namespace
void InitializePageLoadMetricsForWebContents(
content::WebContents* web_contents) {
// Change this method? consider to modify the peer in
// chrome/browser/page_load_metrics/page_load_metrics_initialize.cc
// weblayer/browser/page_load_metrics_initialize.cc
// as well.
page_load_metrics::MetricsWebContentsObserver::CreateForWebContents(
web_contents, std::make_unique<PageLoadMetricsEmbedder>(web_contents));
}
} // namespace android_webview