1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 CHROME_BROWSER_METRICS_CHROME_STABILITY_METRICS_PROVIDER_H_ 6 #define CHROME_BROWSER_METRICS_CHROME_STABILITY_METRICS_PROVIDER_H_ 7 8 #include "base/basictypes.h" 9 #include "base/metrics/user_metrics.h" 10 #include "base/process/kill.h" 11 #include "components/metrics/metrics_provider.h" 12 #include "content/public/browser/browser_child_process_observer.h" 13 #include "content/public/browser/notification_observer.h" 14 #include "content/public/browser/notification_registrar.h" 15 16 class PrefRegistrySimple; 17 18 namespace content { 19 class RenderProcessHost; 20 class WebContents; 21 } 22 23 // ChromeStabilityMetricsProvider gathers and logs Chrome-specific stability- 24 // related metrics. 25 class ChromeStabilityMetricsProvider 26 : public metrics::MetricsProvider, 27 public content::BrowserChildProcessObserver, 28 public content::NotificationObserver { 29 public: 30 ChromeStabilityMetricsProvider(); 31 virtual ~ChromeStabilityMetricsProvider(); 32 33 // metrics::MetricsDataProvider: 34 virtual void OnRecordingEnabled() OVERRIDE; 35 virtual void OnRecordingDisabled() OVERRIDE; 36 virtual void ProvideStabilityMetrics( 37 metrics::SystemProfileProto* system_profile_proto) OVERRIDE; 38 39 // Registers local state prefs used by this class. 40 static void RegisterPrefs(PrefRegistrySimple* registry); 41 42 private: 43 // content::NotificationObserver: 44 virtual void Observe(int type, 45 const content::NotificationSource& source, 46 const content::NotificationDetails& details) OVERRIDE; 47 48 // content::BrowserChildProcessObserver: 49 virtual void BrowserChildProcessCrashed( 50 const content::ChildProcessData& data) OVERRIDE; 51 52 // Logs the initiation of a page load and uses |web_contents| to do 53 // additional logging of the type of page loaded. 54 void LogLoadStarted(content::WebContents* web_contents); 55 56 // Records a renderer process crash. 57 void LogRendererCrash(content::RenderProcessHost* host, 58 base::TerminationStatus status, 59 int exit_code); 60 61 // Records a renderer process hang. 62 void LogRendererHang(); 63 64 // Registrar for receiving stability-related notifications. 65 content::NotificationRegistrar registrar_; 66 67 DISALLOW_COPY_AND_ASSIGN(ChromeStabilityMetricsProvider); 68 }; 69 70 #endif // CHROME_BROWSER_METRICS_CHROME_STABILITY_METRICS_PROVIDER_H_ 71