diff options
Diffstat (limited to 'chrome_frame/crash_reporting')
-rw-r--r-- | chrome_frame/crash_reporting/crash_metrics.cc | 92 | ||||
-rw-r--r-- | chrome_frame/crash_reporting/crash_metrics.h | 65 | ||||
-rw-r--r-- | chrome_frame/crash_reporting/crash_report.cc | 2 | ||||
-rw-r--r-- | chrome_frame/crash_reporting/crash_reporting.gyp | 2 |
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', |