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
,
61 int exit_code
) override
;
63 // Records a renderer process crash.
64 void LogRendererCrash(content::RenderProcessHost
* host
,
65 base::TerminationStatus status
,
68 // Records a renderer process hang.
69 void LogRendererHang();
71 // Registrar for receiving stability-related notifications.
72 content::NotificationRegistrar registrar_
;
74 // Reference to the current MetricsService. Raw pointer is safe, since
75 // MetricsService is responsible for the lifetime of
76 // CastStabilityMetricsProvider.
77 ::metrics::MetricsService
* metrics_service_
;
79 DISALLOW_COPY_AND_ASSIGN(CastStabilityMetricsProvider
);
82 } // namespace metrics
83 } // namespace chromecast
85 #endif // CHROMECAST_BROWSER_METRICS_CAST_STABILITY_METRICS_PROVIDER_H_