From 9607f6a8933093f55aeb63580efba974597b7e40 Mon Sep 17 00:00:00 2001 From: "mad@google.com" Date: Sat, 12 Jun 2010 17:24:41 +0000 Subject: 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 --- chrome_frame/bho.cc | 2 +- chrome_frame/chrome_active_document.cc | 2 +- chrome_frame/chrome_frame.gyp | 2 - chrome_frame/chrome_frame_automation.cc | 2 +- chrome_frame/crash_metrics.cc | 92 ------------------------ chrome_frame/crash_metrics.h | 65 ----------------- chrome_frame/crash_reporting/crash_metrics.cc | 92 ++++++++++++++++++++++++ chrome_frame/crash_reporting/crash_metrics.h | 65 +++++++++++++++++ chrome_frame/crash_reporting/crash_report.cc | 2 +- chrome_frame/crash_reporting/crash_reporting.gyp | 2 + chrome_frame/metrics_service.cc | 2 +- 11 files changed, 164 insertions(+), 164 deletions(-) delete mode 100644 chrome_frame/crash_metrics.cc delete mode 100644 chrome_frame/crash_metrics.h create mode 100644 chrome_frame/crash_reporting/crash_metrics.cc create mode 100644 chrome_frame/crash_reporting/crash_metrics.h (limited to 'chrome_frame') diff --git a/chrome_frame/bho.cc b/chrome_frame/bho.cc index 3033b9a..afa191d 100644 --- a/chrome_frame/bho.cc +++ b/chrome_frame/bho.cc @@ -14,7 +14,7 @@ #include "base/scoped_variant_win.h" #include "base/string_util.h" #include "chrome_tab.h" // NOLINT -#include "chrome_frame/crash_metrics.h" +#include "chrome_frame/crash_reporting/crash_metrics.h" #include "chrome_frame/extra_system_apis.h" #include "chrome_frame/http_negotiate.h" #include "chrome_frame/metrics_service.h" diff --git a/chrome_frame/chrome_active_document.cc b/chrome_frame/chrome_active_document.cc index 70b1656..3223edd 100644 --- a/chrome_frame/chrome_active_document.cc +++ b/chrome_frame/chrome_active_document.cc @@ -38,7 +38,7 @@ #include "chrome/test/automation/tab_proxy.h" #include "chrome_frame/bho.h" #include "chrome_frame/bind_context_info.h" -#include "chrome_frame/crash_metrics.h" +#include "chrome_frame/crash_reporting/crash_metrics.h" #include "chrome_frame/utils.h" const wchar_t kChromeAttachExternalTabPrefix[] = L"attach_external_tab"; diff --git a/chrome_frame/chrome_frame.gyp b/chrome_frame/chrome_frame.gyp index 3bb4fa9..607929e 100644 --- a/chrome_frame/chrome_frame.gyp +++ b/chrome_frame/chrome_frame.gyp @@ -621,8 +621,6 @@ 'com_message_event.h', 'com_type_info_holder.cc', 'com_type_info_holder.h', - 'crash_metrics.cc', - 'crash_metrics.h', 'delete_chrome_history.cc', 'delete_chrome_history.h', 'exception_barrier.cc', diff --git a/chrome_frame/chrome_frame_automation.cc b/chrome_frame/chrome_frame_automation.cc index 9deaeb5..1679758 100644 --- a/chrome_frame/chrome_frame_automation.cc +++ b/chrome_frame/chrome_frame_automation.cc @@ -23,8 +23,8 @@ #include "chrome/common/chrome_switches.h" #include "chrome/test/automation/tab_proxy.h" #include "chrome_frame/chrome_launcher_utils.h" +#include "chrome_frame/crash_reporting/crash_metrics.h" #include "chrome_frame/custom_sync_call_context.h" -#include "chrome_frame/crash_metrics.h" #include "chrome_frame/utils.h" #ifdef NDEBUG diff --git a/chrome_frame/crash_metrics.cc b/chrome_frame/crash_metrics.cc deleted file mode 100644 index 8b1a97a..0000000 --- a/chrome_frame/crash_metrics.cc +++ /dev/null @@ -1,92 +0,0 @@ -// 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_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 - 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(&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_metrics.h b/chrome_frame/crash_metrics.h deleted file mode 100644 index f0812c6..0000000 --- a/chrome_frame/crash_metrics.h +++ /dev/null @@ -1,65 +0,0 @@ -// 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_METRICS_H_ -#define CHROME_FRAME_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() - : 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_METRICS_H_ - 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 + 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(&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() + : 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', diff --git a/chrome_frame/metrics_service.cc b/chrome_frame/metrics_service.cc index 57fdf6e..85bb0b3 100644 --- a/chrome_frame/metrics_service.cc +++ b/chrome_frame/metrics_service.cc @@ -58,7 +58,7 @@ #include "chrome/installer/util/chrome_frame_distribution.h" #include "chrome/installer/util/google_update_settings.h" #include "chrome_frame/bind_status_callback_impl.h" -#include "chrome_frame/crash_metrics.h" +#include "chrome_frame/crash_reporting/crash_metrics.h" #include "chrome_frame/utils.h" #include "net/base/upload_data.h" #include "chrome_frame/urlmon_bind_status_callback.h" -- cgit v1.1