| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2010 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. | |
| 4 | |
| 5 #include "chrome_frame/crash_metrics.h" | |
| 6 | |
| 7 #include "base/histogram.h" | |
| 8 #include "base/registry.h" | |
| 9 #include "chrome_frame/utils.h" | |
| 10 | |
| 11 static const wchar_t kChromeFrameMetricsKey[] = | |
| 12 L"Software\\Google\\ChromeFrameMetrics"; | |
| 13 | |
| 14 base::LazyInstance<CrashMetricsReporter> | |
| 15 g_crash_metrics_instance_(base::LINKER_INITIALIZED); | |
| 16 | |
| 17 wchar_t* CrashMetricsReporter::g_metric_names[LAST_METRIC] = { | |
| 18 L"navigationcount", | |
| 19 L"crashcount", | |
| 20 L"chrome_frame_navigationcount", | |
| 21 L"sessionid", | |
| 22 }; | |
| 23 | |
| 24 CrashMetricsReporter* CrashMetricsReporter::GetInstance() { | |
| 25 return &g_crash_metrics_instance_.Get(); | |
| 26 } | |
| 27 | |
| 28 bool CrashMetricsReporter::SetMetric(Metric metric, int value) { | |
| 29 DCHECK(metric >= NAVIGATION_COUNT && metric <= LAST_METRIC); | |
| 30 | |
| 31 RegKey metric_key; | |
| 32 if (metric_key.Create(HKEY_CURRENT_USER, kChromeFrameMetricsKey, | |
| 33 KEY_SET_VALUE)) { | |
| 34 if (metric_key.WriteValue(g_metric_names[metric], value)) { | |
| 35 return true; | |
| 36 } else { | |
| 37 DLOG(ERROR) << "Failed to read ChromeFrame metric:" | |
| 38 << g_metric_names[metric]; | |
| 39 } | |
| 40 } else { | |
| 41 DLOG(ERROR) << "Failed to create ChromeFrame metrics key"; | |
| 42 } | |
| 43 return false; | |
| 44 } | |
| 45 | |
| 46 int CrashMetricsReporter::GetMetric(Metric metric) { | |
| 47 DCHECK(metric >= NAVIGATION_COUNT && metric <= LAST_METRIC); | |
| 48 | |
| 49 int ret = 0; | |
| 50 RegKey metric_key; | |
| 51 if (metric_key.Open(HKEY_CURRENT_USER, kChromeFrameMetricsKey, | |
| 52 KEY_QUERY_VALUE)) { | |
| 53 int value = 0; | |
| 54 if (metric_key.ReadValueDW(g_metric_names[metric], | |
| 55 reinterpret_cast<DWORD*>(&value))) { | |
| 56 ret = value; | |
| 57 } | |
| 58 } | |
| 59 return ret; | |
| 60 } | |
| 61 | |
| 62 int CrashMetricsReporter::IncrementMetric(Metric metric) { | |
| 63 DCHECK(metric >= NAVIGATION_COUNT && metric <= LAST_METRIC); | |
| 64 int metric_value = GetMetric(metric); | |
| 65 metric_value++; | |
| 66 SetMetric(metric, metric_value); | |
| 67 return metric_value; | |
| 68 } | |
| 69 | |
| 70 void CrashMetricsReporter::RecordCrashMetrics() { | |
| 71 int navigation_count = GetMetric(NAVIGATION_COUNT); | |
| 72 if (navigation_count > 0) { | |
| 73 THREAD_SAFE_UMA_HISTOGRAM_COUNTS("ChromeFrame.HostNavigationCount", | |
| 74 navigation_count); | |
| 75 SetMetric(NAVIGATION_COUNT, 0); | |
| 76 } | |
| 77 | |
| 78 int chrome_frame_navigation_count = GetMetric(CHROME_FRAME_NAVIGATION_COUNT); | |
| 79 if (chrome_frame_navigation_count > 0) { | |
| 80 THREAD_SAFE_UMA_HISTOGRAM_COUNTS("ChromeFrame.CFNavigationCount", | |
| 81 chrome_frame_navigation_count); | |
| 82 SetMetric(CHROME_FRAME_NAVIGATION_COUNT, 0); | |
| 83 } | |
| 84 | |
| 85 int crash_count = GetMetric(CRASH_COUNT); | |
| 86 if (crash_count > 0) { | |
| 87 THREAD_SAFE_UMA_HISTOGRAM_COUNTS("ChromeFrame.HostCrashCount", | |
| 88 crash_count); | |
| 89 SetMetric(CRASH_COUNT, 0); | |
| 90 } | |
| 91 } | |
| 92 | |
| OLD | NEW |