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 CHROME_BROWSER_METRICS_CHROME_STABILITY_METRICS_PROVIDER_H_
6 #define CHROME_BROWSER_METRICS_CHROME_STABILITY_METRICS_PROVIDER_H_
8 #include "base/basictypes.h"
9 #include "base/gtest_prod_util.h"
10 #include "base/metrics/user_metrics.h"
11 #include "base/process/kill.h"
12 #include "components/metrics/metrics_provider.h"
13 #include "content/public/browser/browser_child_process_observer.h"
14 #include "content/public/browser/notification_observer.h"
15 #include "content/public/browser/notification_registrar.h"
17 class PrefRegistrySimple
;
20 class RenderProcessHost
;
26 // ChromeStabilityMetricsProvider gathers and logs Chrome-specific stability-
28 class ChromeStabilityMetricsProvider
29 : public metrics::MetricsProvider
,
30 public content::BrowserChildProcessObserver
,
31 public content::NotificationObserver
{
33 explicit ChromeStabilityMetricsProvider(PrefService
* local_state
);
34 ~ChromeStabilityMetricsProvider() override
;
36 // metrics::MetricsDataProvider:
37 void OnRecordingEnabled() override
;
38 void OnRecordingDisabled() override
;
39 void ProvideStabilityMetrics(
40 metrics::SystemProfileProto
* system_profile_proto
) override
;
41 void ClearSavedStabilityMetrics() override
;
43 // Registers local state prefs used by this class.
44 static void RegisterPrefs(PrefRegistrySimple
* registry
);
47 FRIEND_TEST_ALL_PREFIXES(ChromeStabilityMetricsProviderTest
,
48 BrowserChildProcessObserver
);
49 FRIEND_TEST_ALL_PREFIXES(ChromeStabilityMetricsProviderTest
,
50 NotificationObserver
);
52 // content::NotificationObserver:
53 void Observe(int type
,
54 const content::NotificationSource
& source
,
55 const content::NotificationDetails
& details
) override
;
57 // content::BrowserChildProcessObserver:
58 void BrowserChildProcessCrashed(
59 const content::ChildProcessData
& data
,
60 int exit_code
) override
;
62 // Logs the initiation of a page load and uses |web_contents| to do
63 // additional logging of the type of page loaded.
64 void LogLoadStarted(content::WebContents
* web_contents
);
66 // Records a renderer process crash.
67 void LogRendererCrash(content::RenderProcessHost
* host
,
68 base::TerminationStatus status
,
71 // Increment an Integer pref value specified by |path|.
72 void IncrementPrefValue(const char* path
);
74 // Increment a 64-bit Integer pref value specified by |path|.
75 void IncrementLongPrefsValue(const char* path
);
77 // Records a renderer process hang.
78 void LogRendererHang();
80 PrefService
* local_state_
;
82 // Registrar for receiving stability-related notifications.
83 content::NotificationRegistrar registrar_
;
85 DISALLOW_COPY_AND_ASSIGN(ChromeStabilityMetricsProvider
);
88 #endif // CHROME_BROWSER_METRICS_CHROME_STABILITY_METRICS_PROVIDER_H_