summaryrefslogtreecommitdiffstats
path: root/chrome_frame/crash_reporting
diff options
context:
space:
mode:
authormad@google.com <mad@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2010-06-12 17:24:41 +0000
committermad@google.com <mad@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2010-06-12 17:24:41 +0000
commit9607f6a8933093f55aeb63580efba974597b7e40 (patch)
treeb27d7723a09ce7bf54688d2095ce534a71de46c4 /chrome_frame/crash_reporting
parentd8d4a0ad53db7621b45b38cbc73be7521b8d81d2 (diff)
downloadchromium_src-9607f6a8933093f55aeb63580efba974597b7e40.zip
chromium_src-9607f6a8933093f55aeb63580efba974597b7e40.tar.gz
chromium_src-9607f6a8933093f55aeb63580efba974597b7e40.tar.bz2
Move the crash metrics to the crash reproting lib to avoid a back dependency on Chrome Frame.
BUG=0 TEST=none Review URL: http://codereview.chromium.org/2776010 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@49635 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome_frame/crash_reporting')
-rw-r--r--chrome_frame/crash_reporting/crash_metrics.cc92
-rw-r--r--chrome_frame/crash_reporting/crash_metrics.h65
-rw-r--r--chrome_frame/crash_reporting/crash_report.cc2
-rw-r--r--chrome_frame/crash_reporting/crash_reporting.gyp2
4 files changed, 160 insertions, 1 deletions
diff --git a/chrome_frame/crash_reporting/crash_metrics.cc b/chrome_frame/crash_reporting/crash_metrics.cc
new file mode 100644
index 0000000..81c2296
--- /dev/null
+++ b/chrome_frame/crash_reporting/crash_metrics.cc
@@ -0,0 +1,92 @@
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome_frame/crash_reporting/crash_metrics.h"
+
+#include "base/histogram.h"
+#include "base/registry.h"
+#include "chrome_frame/utils.h"
+
+static const wchar_t kChromeFrameMetricsKey[] =
+ L"Software\\Google\\ChromeFrameMetrics";
+
+base::LazyInstance<CrashMetricsReporter>
+ g_crash_metrics_instance_(base::LINKER_INITIALIZED);
+
+wchar_t* CrashMetricsReporter::g_metric_names[LAST_METRIC] = {
+ L"navigationcount",
+ L"crashcount",
+ L"chrome_frame_navigationcount",
+ L"sessionid",
+};
+
+CrashMetricsReporter* CrashMetricsReporter::GetInstance() {
+ return &g_crash_metrics_instance_.Get();
+}
+
+bool CrashMetricsReporter::SetMetric(Metric metric, int value) {
+ DCHECK(metric >= NAVIGATION_COUNT && metric <= LAST_METRIC);
+
+ RegKey metric_key;
+ if (metric_key.Create(HKEY_CURRENT_USER, kChromeFrameMetricsKey,
+ KEY_SET_VALUE)) {
+ if (metric_key.WriteValue(g_metric_names[metric], value)) {
+ return true;
+ } else {
+ DLOG(ERROR) << "Failed to read ChromeFrame metric:"
+ << g_metric_names[metric];
+ }
+ } else {
+ DLOG(ERROR) << "Failed to create ChromeFrame metrics key";
+ }
+ return false;
+}
+
+int CrashMetricsReporter::GetMetric(Metric metric) {
+ DCHECK(metric >= NAVIGATION_COUNT && metric <= LAST_METRIC);
+
+ int ret = 0;
+ RegKey metric_key;
+ if (metric_key.Open(HKEY_CURRENT_USER, kChromeFrameMetricsKey,
+ KEY_QUERY_VALUE)) {
+ int value = 0;
+ if (metric_key.ReadValueDW(g_metric_names[metric],
+ reinterpret_cast<DWORD*>(&value))) {
+ ret = value;
+ }
+ }
+ return ret;
+}
+
+int CrashMetricsReporter::IncrementMetric(Metric metric) {
+ DCHECK(metric >= NAVIGATION_COUNT && metric <= LAST_METRIC);
+ int metric_value = GetMetric(metric);
+ metric_value++;
+ SetMetric(metric, metric_value);
+ return metric_value;
+}
+
+void CrashMetricsReporter::RecordCrashMetrics() {
+ int navigation_count = GetMetric(NAVIGATION_COUNT);
+ if (navigation_count > 0) {
+ THREAD_SAFE_UMA_HISTOGRAM_COUNTS("ChromeFrame.HostNavigationCount",
+ navigation_count);
+ SetMetric(NAVIGATION_COUNT, 0);
+ }
+
+ int chrome_frame_navigation_count = GetMetric(CHROME_FRAME_NAVIGATION_COUNT);
+ if (chrome_frame_navigation_count > 0) {
+ THREAD_SAFE_UMA_HISTOGRAM_COUNTS("ChromeFrame.CFNavigationCount",
+ chrome_frame_navigation_count);
+ SetMetric(CHROME_FRAME_NAVIGATION_COUNT, 0);
+ }
+
+ int crash_count = GetMetric(CRASH_COUNT);
+ if (crash_count > 0) {
+ THREAD_SAFE_UMA_HISTOGRAM_COUNTS("ChromeFrame.HostCrashCount",
+ crash_count);
+ SetMetric(CRASH_COUNT, 0);
+ }
+}
+
diff --git a/chrome_frame/crash_reporting/crash_metrics.h b/chrome_frame/crash_reporting/crash_metrics.h
new file mode 100644
index 0000000..a51ca7d
--- /dev/null
+++ b/chrome_frame/crash_reporting/crash_metrics.h
@@ -0,0 +1,65 @@
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// This file defines a service that collects information about the user
+// experience in order to help improve future versions of the app.
+
+#ifndef CHROME_FRAME_CRASH_REPORTING_CRASH_METRICS_H_
+#define CHROME_FRAME_CRASH_REPORTING_CRASH_METRICS_H_
+
+#include "base/basictypes.h"
+#include "base/lazy_instance.h"
+#include "base/thread_local.h"
+
+// This class provides functionality to track counters like successful page
+// loads in the host browser, total number of crashes, page loads in chrome
+// frame.
+class CrashMetricsReporter {
+ public:
+ enum Metric {
+ NAVIGATION_COUNT,
+ CRASH_COUNT,
+ CHROME_FRAME_NAVIGATION_COUNT,
+ SESSION_ID,
+ LAST_METRIC,
+ };
+ // Returns the global instance of this class.
+ static CrashMetricsReporter* GetInstance();
+
+ // The following function pair return/set/increment the specified user
+ // metrics value from the registry. These values are set under the
+ // following key:-
+ // HKCU\Software\\Google\\ChromeFrame\\UserMetrics
+ int GetMetric(Metric metric);
+ bool SetMetric(Metric metric, int value);
+ int IncrementMetric(Metric metric);
+
+ // Records the crash metrics counters like navigation count, crash count.
+ void RecordCrashMetrics();
+
+ bool active() const {
+ return active_;
+ }
+
+ void set_active(bool active) {
+ active_ = active;
+ }
+
+ private:
+ friend struct base::DefaultLazyInstanceTraits<CrashMetricsReporter>;
+
+ CrashMetricsReporter()
+ : active_(false) {}
+ virtual ~CrashMetricsReporter() {}
+
+ // Indicates whether the crash metrics reporter instance is active.
+ bool active_;
+
+ static wchar_t* g_metric_names[LAST_METRIC];
+
+ DISALLOW_COPY_AND_ASSIGN(CrashMetricsReporter);
+};
+
+#endif // CHROME_FRAME_CRASH_REPORTING_CRASH_METRICS_H_
+
diff --git a/chrome_frame/crash_reporting/crash_report.cc b/chrome_frame/crash_reporting/crash_report.cc
index f821320..e71bd66 100644
--- a/chrome_frame/crash_reporting/crash_report.cc
+++ b/chrome_frame/crash_reporting/crash_report.cc
@@ -9,7 +9,7 @@
#include "base/basictypes.h"
#include "base/lock.h"
#include "breakpad/src/client/windows/handler/exception_handler.h"
-#include "chrome_frame/crash_metrics.h"
+#include "chrome_frame/crash_reporting/crash_metrics.h"
// TODO(joshia): factor out common code with chrome used for crash reporting
const wchar_t kGoogleUpdatePipeName[] = L"\\\\.\\pipe\\GoogleCrashServices\\";
diff --git a/chrome_frame/crash_reporting/crash_reporting.gyp b/chrome_frame/crash_reporting/crash_reporting.gyp
index 54473fc..63a16e6 100644
--- a/chrome_frame/crash_reporting/crash_reporting.gyp
+++ b/chrome_frame/crash_reporting/crash_reporting.gyp
@@ -17,6 +17,8 @@
'target_name': 'crash_report',
'type': 'static_library',
'sources': [
+ 'crash_metrics.cc',
+ 'crash_metrics.h',
'crash_report.cc',
'crash_report.h',
'nt_loader.cc',