OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CHROMECAST_BROWSER_METRICS_CAST_STABILITY_METRICS_PROVIDER_H_ | 5 #ifndef CHROMECAST_BROWSER_METRICS_CAST_STABILITY_METRICS_PROVIDER_H_ |
6 #define CHROMECAST_BROWSER_METRICS_CAST_STABILITY_METRICS_PROVIDER_H_ | 6 #define CHROMECAST_BROWSER_METRICS_CAST_STABILITY_METRICS_PROVIDER_H_ |
7 | 7 |
8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
9 #include "base/metrics/user_metrics.h" | 9 #include "base/metrics/user_metrics.h" |
10 #include "base/process/kill.h" | 10 #include "base/process/kill.h" |
11 #include "components/metrics/metrics_provider.h" | 11 #include "components/metrics/metrics_provider.h" |
12 #include "content/public/browser/browser_child_process_observer.h" | 12 #include "content/public/browser/browser_child_process_observer.h" |
13 #include "content/public/browser/notification_observer.h" | 13 #include "content/public/browser/notification_observer.h" |
14 #include "content/public/browser/notification_registrar.h" | 14 #include "content/public/browser/notification_registrar.h" |
15 | 15 |
16 class MetricsService; | |
17 class PrefRegistrySimple; | 16 class PrefRegistrySimple; |
18 | 17 |
19 namespace content { | 18 namespace content { |
20 class RenderProcessHost; | 19 class RenderProcessHost; |
21 class WebContents; | 20 class WebContents; |
22 } | 21 } |
23 | 22 |
| 23 namespace metrics { |
| 24 class MetricsService; |
| 25 } |
| 26 |
24 namespace chromecast { | 27 namespace chromecast { |
25 namespace metrics { | 28 namespace metrics { |
26 | 29 |
27 // CastStabilityMetricsProvider gathers and logs stability-related metrics. | 30 // CastStabilityMetricsProvider gathers and logs stability-related metrics. |
28 // Loosely based on ChromeStabilityMetricsProvider from chrome/browser/metrics. | 31 // Loosely based on ChromeStabilityMetricsProvider from chrome/browser/metrics. |
29 class CastStabilityMetricsProvider | 32 class CastStabilityMetricsProvider |
30 : public ::metrics::MetricsProvider, | 33 : public ::metrics::MetricsProvider, |
31 public content::BrowserChildProcessObserver, | 34 public content::BrowserChildProcessObserver, |
32 public content::NotificationObserver { | 35 public content::NotificationObserver { |
33 public: | 36 public: |
34 // Registers local state prefs used by this class. | 37 // Registers local state prefs used by this class. |
35 static void RegisterPrefs(PrefRegistrySimple* registry); | 38 static void RegisterPrefs(PrefRegistrySimple* registry); |
36 | 39 |
37 CastStabilityMetricsProvider(); | 40 explicit CastStabilityMetricsProvider( |
| 41 ::metrics::MetricsService* metrics_service); |
38 virtual ~CastStabilityMetricsProvider(); | 42 virtual ~CastStabilityMetricsProvider(); |
39 | 43 |
40 // metrics::MetricsDataProvider implementation: | 44 // metrics::MetricsDataProvider implementation: |
41 virtual void OnRecordingEnabled() override; | 45 virtual void OnRecordingEnabled() override; |
42 virtual void OnRecordingDisabled() override; | 46 virtual void OnRecordingDisabled() override; |
43 virtual void ProvideStabilityMetrics( | 47 virtual void ProvideStabilityMetrics( |
44 ::metrics::SystemProfileProto* system_profile_proto) override; | 48 ::metrics::SystemProfileProto* system_profile_proto) override; |
45 | 49 |
| 50 // Logs an external crash, presumably from the ExternalMetrics service. |
| 51 void LogExternalCrash(const std::string& crash_type); |
| 52 |
46 private: | 53 private: |
47 // content::NotificationObserver implementation: | 54 // content::NotificationObserver implementation: |
48 virtual void Observe(int type, | 55 virtual void Observe(int type, |
49 const content::NotificationSource& source, | 56 const content::NotificationSource& source, |
50 const content::NotificationDetails& details) override; | 57 const content::NotificationDetails& details) override; |
51 | 58 |
52 // content::BrowserChildProcessObserver implementation: | 59 // content::BrowserChildProcessObserver implementation: |
53 virtual void BrowserChildProcessCrashed( | 60 virtual void BrowserChildProcessCrashed( |
54 const content::ChildProcessData& data) override; | 61 const content::ChildProcessData& data) override; |
55 | 62 |
56 // Records a renderer process crash. | 63 // Records a renderer process crash. |
57 void LogRendererCrash(content::RenderProcessHost* host, | 64 void LogRendererCrash(content::RenderProcessHost* host, |
58 base::TerminationStatus status, | 65 base::TerminationStatus status, |
59 int exit_code); | 66 int exit_code); |
60 | 67 |
61 // Records a renderer process hang. | 68 // Records a renderer process hang. |
62 void LogRendererHang(); | 69 void LogRendererHang(); |
63 | 70 |
64 // Registrar for receiving stability-related notifications. | 71 // Registrar for receiving stability-related notifications. |
65 content::NotificationRegistrar registrar_; | 72 content::NotificationRegistrar registrar_; |
66 | 73 |
| 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_; |
| 78 |
67 DISALLOW_COPY_AND_ASSIGN(CastStabilityMetricsProvider); | 79 DISALLOW_COPY_AND_ASSIGN(CastStabilityMetricsProvider); |
68 }; | 80 }; |
69 | 81 |
70 } // namespace metrics | 82 } // namespace metrics |
71 } // namespace chromecast | 83 } // namespace chromecast |
72 | 84 |
73 #endif // CHROMECAST_BROWSER_METRICS_CAST_STABILITY_METRICS_PROVIDER_H_ | 85 #endif // CHROMECAST_BROWSER_METRICS_CAST_STABILITY_METRICS_PROVIDER_H_ |
OLD | NEW |