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.
5 #ifndef CHROMECAST_BROWSER_METRICS_CAST_STABILITY_METRICS_PROVIDER_H_
6 #define CHROMECAST_BROWSER_METRICS_CAST_STABILITY_METRICS_PROVIDER_H_
8 #include "base/basictypes.h"
9 #include "base/process/kill.h"
10 #include "components/metrics/metrics_provider.h"
11 #include "content/public/browser/browser_child_process_observer.h"
12 #include "content/public/browser/notification_observer.h"
13 #include "content/public/browser/notification_registrar.h"
15 class PrefRegistrySimple
;
18 class RenderProcessHost
;
26 namespace chromecast
{
29 // CastStabilityMetricsProvider gathers and logs stability-related metrics.
30 // Loosely based on ChromeStabilityMetricsProvider from chrome/browser/metrics.
31 class CastStabilityMetricsProvider
32 : public ::metrics::MetricsProvider
,
33 public content::BrowserChildProcessObserver
,
34 public content::NotificationObserver
{
36 // Registers local state prefs used by this class.
37 static void RegisterPrefs(PrefRegistrySimple
* registry
);
39 explicit CastStabilityMetricsProvider(
40 ::metrics::MetricsService
* metrics_service
);
41 ~CastStabilityMetricsProvider() override
;
43 // metrics::MetricsDataProvider implementation:
44 void OnRecordingEnabled() override
;
45 void OnRecordingDisabled() override
;
46 void ProvideStabilityMetrics(
47 ::metrics::SystemProfileProto
* system_profile_proto
) override
;
49 // Logs an external crash, presumably from the ExternalMetrics service.
50 void LogExternalCrash(const std::string
& crash_type
);
53 // content::NotificationObserver implementation:
54 void Observe(int type
,
55 const content::NotificationSource
& source
,
56 const content::NotificationDetails
& details
) override
;
58 // content::BrowserChildProcessObserver implementation:
59 void BrowserChildProcessCrashed(
60 const content::ChildProcessData
& data
) override
;
62 // Records a renderer process crash.
63 void LogRendererCrash(content::RenderProcessHost
* host
,
64 base::TerminationStatus status
,
67 // Records a renderer process hang.
68 void LogRendererHang();
70 // Registrar for receiving stability-related notifications.
71 content::NotificationRegistrar registrar_
;
73 // Reference to the current MetricsService. Raw pointer is safe, since
74 // MetricsService is responsible for the lifetime of
75 // CastStabilityMetricsProvider.
76 ::metrics::MetricsService
* metrics_service_
;
78 DISALLOW_COPY_AND_ASSIGN(CastStabilityMetricsProvider
);
81 } // namespace metrics
82 } // namespace chromecast
84 #endif // CHROMECAST_BROWSER_METRICS_CAST_STABILITY_METRICS_PROVIDER_H_