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 #ifndef COMPONENTS_METRICS_CONTENT_METRICS_SERVICES_WEB_CONTENTS_OBSERVER_H_ 6 #define COMPONENTS_METRICS_CONTENT_METRICS_SERVICES_WEB_CONTENTS_OBSERVER_H_ 7 8 #include "base/functional/callback.h" 9 #include "components/metrics/metrics_service_client.h" 10 #include "content/public/browser/web_contents_observer.h" 11 #include "content/public/browser/web_contents_user_data.h" 12 13 namespace metrics { 14 15 class MetricsServicesWebContentsObserver 16 : public content::WebContentsObserver, 17 public content::WebContentsUserData<MetricsServicesWebContentsObserver> { 18 public: 19 using OnDidStartLoadingCb = base::RepeatingClosure; 20 using OnDidStopLoadingCb = base::RepeatingClosure; 21 using OnRendererUnresponsiveCb = base::RepeatingClosure; 22 23 MetricsServicesWebContentsObserver( 24 const MetricsServicesWebContentsObserver&) = delete; 25 MetricsServicesWebContentsObserver& operator=( 26 const MetricsServicesWebContentsObserver&) = delete; 27 28 ~MetricsServicesWebContentsObserver() override; 29 30 private: 31 explicit MetricsServicesWebContentsObserver( 32 content::WebContents* web_contents, 33 OnDidStartLoadingCb did_start_loading_cb, 34 OnDidStopLoadingCb did_stop_loading_cb, 35 OnRendererUnresponsiveCb renderer_unresponsive_cb); 36 friend class content::WebContentsUserData<MetricsServicesWebContentsObserver>; 37 38 // content::WebContentsObserver: 39 void DidStartLoading() override; 40 void DidStopLoading() override; 41 void OnRendererUnresponsive(content::RenderProcessHost* host) override; 42 43 OnDidStartLoadingCb did_start_loading_cb_; 44 OnDidStopLoadingCb did_stop_loading_cb_; 45 OnRendererUnresponsiveCb renderer_unresponsive_cb_; 46 47 WEB_CONTENTS_USER_DATA_KEY_DECL(); 48 }; 49 50 } // namespace metrics 51 52 #endif // COMPONENTS_METRICS_CONTENT_METRICS_SERVICES_WEB_CONTENTS_OBSERVER_H_ 53