1 // Copyright 2023 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "components/metrics/content/metrics_services_web_contents_observer.h"
6
7 #include "components/metrics/metrics_service.h"
8
9 namespace metrics {
10
MetricsServicesWebContentsObserver(content::WebContents * web_contents,OnDidStartLoadingCb did_start_loading_cb,OnDidStopLoadingCb did_stop_loading_cb,OnRendererUnresponsiveCb renderer_unresponsive_cb)11 MetricsServicesWebContentsObserver::MetricsServicesWebContentsObserver(
12 content::WebContents* web_contents,
13 OnDidStartLoadingCb did_start_loading_cb,
14 OnDidStopLoadingCb did_stop_loading_cb,
15 OnRendererUnresponsiveCb renderer_unresponsive_cb)
16 : content::WebContentsObserver(web_contents),
17 content::WebContentsUserData<MetricsServicesWebContentsObserver>(
18 *web_contents),
19 did_start_loading_cb_(std::move(did_start_loading_cb)),
20 did_stop_loading_cb_(std::move(did_stop_loading_cb)),
21 renderer_unresponsive_cb_(std::move(renderer_unresponsive_cb)) {}
22 MetricsServicesWebContentsObserver::~MetricsServicesWebContentsObserver() =
23 default;
24
DidStartLoading()25 void MetricsServicesWebContentsObserver::DidStartLoading() {
26 did_start_loading_cb_.Run();
27 }
28
DidStopLoading()29 void MetricsServicesWebContentsObserver::DidStopLoading() {
30 did_stop_loading_cb_.Run();
31 }
32
OnRendererUnresponsive(content::RenderProcessHost * host)33 void MetricsServicesWebContentsObserver::OnRendererUnresponsive(
34 content::RenderProcessHost* host) {
35 renderer_unresponsive_cb_.Run();
36 }
37
38 WEB_CONTENTS_USER_DATA_KEY_IMPL(MetricsServicesWebContentsObserver);
39
40 } // namespace metrics
41