OLD | NEW |
---|---|
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome_frame/crash_reporting/crash_metrics.h" | 5 #include "chrome_frame/crash_reporting/crash_metrics.h" |
6 | 6 |
7 #include "base/metrics/histogram.h" | 7 #include "base/metrics/histogram.h" |
8 #include "base/win/registry.h" | 8 #include "base/win/registry.h" |
9 #include "chrome_frame/utils.h" | 9 #include "chrome_frame/utils.h" |
10 | 10 |
(...skipping 12 matching lines...) Expand all Loading... | |
23 }; | 23 }; |
24 | 24 |
25 CrashMetricsReporter* CrashMetricsReporter::GetInstance() { | 25 CrashMetricsReporter* CrashMetricsReporter::GetInstance() { |
26 return &g_crash_metrics_instance_.Get(); | 26 return &g_crash_metrics_instance_.Get(); |
27 } | 27 } |
28 | 28 |
29 bool CrashMetricsReporter::SetMetric(Metric metric, int value) { | 29 bool CrashMetricsReporter::SetMetric(Metric metric, int value) { |
30 DCHECK(metric >= NAVIGATION_COUNT && metric <= LAST_METRIC); | 30 DCHECK(metric >= NAVIGATION_COUNT && metric <= LAST_METRIC); |
31 | 31 |
32 base::win::RegKey metric_key; | 32 base::win::RegKey metric_key; |
33 if (metric_key.Create(HKEY_CURRENT_USER, kChromeFrameMetricsKey, | 33 LONG result = metric_key.Create(HKEY_CURRENT_USER, kChromeFrameMetricsKey, |
34 KEY_SET_VALUE)) { | 34 KEY_SET_VALUE); |
robertshield
2011/01/12 15:01:34
nit: the temporary here makes this harder to read
| |
35 if (metric_key.WriteValue(g_metric_names[metric], value)) { | 35 if (result == ERROR_SUCCESS) { |
36 result = metric_key.WriteValue(g_metric_names[metric], value); | |
37 if (result == ERROR_SUCCESS) { | |
36 return true; | 38 return true; |
37 } else { | 39 } else { |
38 DLOG(ERROR) << "Failed to read ChromeFrame metric:" | 40 DLOG(ERROR) << "Failed to read ChromeFrame metric:" |
39 << g_metric_names[metric]; | 41 << g_metric_names[metric] << " error: " << result; |
40 } | 42 } |
41 } else { | 43 } else { |
42 DLOG(ERROR) << "Failed to create ChromeFrame metrics key"; | 44 DLOG(ERROR) << "Failed to create ChromeFrame metrics key. error: " |
45 << result; | |
43 } | 46 } |
44 return false; | 47 return false; |
45 } | 48 } |
46 | 49 |
47 int CrashMetricsReporter::GetMetric(Metric metric) { | 50 int CrashMetricsReporter::GetMetric(Metric metric) { |
48 DCHECK(metric >= NAVIGATION_COUNT && metric <= LAST_METRIC); | 51 DCHECK(metric >= NAVIGATION_COUNT && metric <= LAST_METRIC); |
49 | 52 |
50 int ret = 0; | 53 int ret = 0; |
51 base::win::RegKey metric_key; | 54 base::win::RegKey metric_key; |
52 if (metric_key.Open(HKEY_CURRENT_USER, kChromeFrameMetricsKey, | 55 if (metric_key.Open(HKEY_CURRENT_USER, kChromeFrameMetricsKey, |
53 KEY_QUERY_VALUE)) { | 56 KEY_QUERY_VALUE) == ERROR_SUCCESS) { |
54 int value = 0; | 57 metric_key.ReadValueDW(g_metric_names[metric], |
55 if (metric_key.ReadValueDW(g_metric_names[metric], | 58 reinterpret_cast<DWORD*>(&ret)); |
56 reinterpret_cast<DWORD*>(&value))) { | |
57 ret = value; | |
58 } | |
59 } | 59 } |
60 | |
60 return ret; | 61 return ret; |
61 } | 62 } |
62 | 63 |
63 int CrashMetricsReporter::IncrementMetric(Metric metric) { | 64 int CrashMetricsReporter::IncrementMetric(Metric metric) { |
64 DCHECK(metric >= NAVIGATION_COUNT && metric <= LAST_METRIC); | 65 DCHECK(metric >= NAVIGATION_COUNT && metric <= LAST_METRIC); |
65 int metric_value = GetMetric(metric); | 66 int metric_value = GetMetric(metric); |
66 metric_value++; | 67 metric_value++; |
67 SetMetric(metric, metric_value); | 68 SetMetric(metric, metric_value); |
68 return metric_value; | 69 return metric_value; |
69 } | 70 } |
(...skipping 20 matching lines...) Expand all Loading... | |
90 SetMetric(CRASH_COUNT, 0); | 91 SetMetric(CRASH_COUNT, 0); |
91 } | 92 } |
92 | 93 |
93 int channel_error_count = GetMetric(CHANNEL_ERROR_COUNT); | 94 int channel_error_count = GetMetric(CHANNEL_ERROR_COUNT); |
94 if (channel_error_count > 0) { | 95 if (channel_error_count > 0) { |
95 THREAD_SAFE_UMA_HISTOGRAM_COUNTS("ChromeFrame.ChannelErrorCount", | 96 THREAD_SAFE_UMA_HISTOGRAM_COUNTS("ChromeFrame.ChannelErrorCount", |
96 channel_error_count); | 97 channel_error_count); |
97 SetMetric(CHANNEL_ERROR_COUNT, 0); | 98 SetMetric(CHANNEL_ERROR_COUNT, 0); |
98 } | 99 } |
99 } | 100 } |
OLD | NEW |