Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(55)

Side by Side Diff: chrome/browser/metrics/chrome_metrics_service_client.cc

Issue 296013005: [Metrics] Move Windows-specific CountBrowserCrashDumpAttempts() out of MetricsService (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/browser/metrics/chrome_metrics_service_client.h" 5 #include "chrome/browser/metrics/chrome_metrics_service_client.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/callback.h" 8 #include "base/callback.h"
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
11 #include "base/metrics/histogram.h" 11 #include "base/metrics/histogram.h"
12 #include "base/strings/string16.h"
13 #include "base/strings/string_util.h"
14 #include "base/strings/utf_string_conversions.h"
12 #include "base/threading/platform_thread.h" 15 #include "base/threading/platform_thread.h"
13 #include "base/time/time.h" 16 #include "base/time/time.h"
14 #include "chrome/browser/browser_process.h" 17 #include "chrome/browser/browser_process.h"
15 #include "chrome/browser/chrome_notification_types.h" 18 #include "chrome/browser/chrome_notification_types.h"
16 #include "chrome/browser/google/google_util.h" 19 #include "chrome/browser/google/google_util.h"
17 #include "chrome/browser/memory_details.h" 20 #include "chrome/browser/memory_details.h"
18 #include "chrome/browser/metrics/metrics_service.h" 21 #include "chrome/browser/metrics/metrics_service.h"
19 #include "chrome/browser/ui/browser_otr_state.h" 22 #include "chrome/browser/ui/browser_otr_state.h"
23 #include "chrome/common/chrome_constants.h"
20 #include "chrome/common/chrome_switches.h" 24 #include "chrome/common/chrome_switches.h"
21 #include "chrome/common/chrome_version_info.h" 25 #include "chrome/common/chrome_version_info.h"
22 #include "chrome/common/crash_keys.h" 26 #include "chrome/common/crash_keys.h"
23 #include "chrome/common/render_messages.h" 27 #include "chrome/common/render_messages.h"
24 #include "content/public/browser/histogram_fetcher.h" 28 #include "content/public/browser/histogram_fetcher.h"
25 #include "content/public/browser/notification_service.h" 29 #include "content/public/browser/notification_service.h"
26 #include "content/public/browser/render_process_host.h" 30 #include "content/public/browser/render_process_host.h"
27 31
28 #if !defined(OS_ANDROID) 32 #if !defined(OS_ANDROID)
29 #include "chrome/browser/service_process/service_process_control.h" 33 #include "chrome/browser/service_process/service_process_control.h"
30 #endif 34 #endif
31 35
36 #if defined(OS_WIN)
37 #include <windows.h>
38 #include "base/win/registry.h"
39 #include "chrome/browser/metrics/google_update_metrics_provider_win.h"
40 #endif
41
32 namespace { 42 namespace {
33 43
34 // This specifies the amount of time to wait for all renderers to send their 44 // This specifies the amount of time to wait for all renderers to send their
35 // data. 45 // data.
36 const int kMaxHistogramGatheringWaitDuration = 60000; // 60 seconds. 46 const int kMaxHistogramGatheringWaitDuration = 60000; // 60 seconds.
37 47
38 metrics::SystemProfileProto::Channel AsProtobufChannel( 48 metrics::SystemProfileProto::Channel AsProtobufChannel(
39 chrome::VersionInfo::Channel channel) { 49 chrome::VersionInfo::Channel channel) {
40 switch (channel) { 50 switch (channel) {
41 case chrome::VersionInfo::CHANNEL_UNKNOWN: 51 case chrome::VersionInfo::CHANNEL_UNKNOWN:
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
75 } // namespace 85 } // namespace
76 86
77 ChromeMetricsServiceClient::ChromeMetricsServiceClient() 87 ChromeMetricsServiceClient::ChromeMetricsServiceClient()
78 : service_(NULL), 88 : service_(NULL),
79 waiting_for_collect_final_metrics_step_(false), 89 waiting_for_collect_final_metrics_step_(false),
80 num_async_histogram_fetches_in_progress_(0), 90 num_async_histogram_fetches_in_progress_(0),
81 weak_ptr_factory_(this) { 91 weak_ptr_factory_(this) {
82 DCHECK(thread_checker_.CalledOnValidThread()); 92 DCHECK(thread_checker_.CalledOnValidThread());
83 RecordCommandLineMetrics(); 93 RecordCommandLineMetrics();
84 RegisterForNotifications(); 94 RegisterForNotifications();
95
96 #if defined(OS_WIN)
97 CountBrowserCrashDumpAttempts();
98 #endif // defined(OS_WIN)
85 } 99 }
86 100
87 ChromeMetricsServiceClient::~ChromeMetricsServiceClient() { 101 ChromeMetricsServiceClient::~ChromeMetricsServiceClient() {
88 DCHECK(thread_checker_.CalledOnValidThread()); 102 DCHECK(thread_checker_.CalledOnValidThread());
89 } 103 }
90 104
91 void ChromeMetricsServiceClient::SetClientID(const std::string& client_id) { 105 void ChromeMetricsServiceClient::SetClientID(const std::string& client_id) {
92 crash_keys::SetClientID(client_id); 106 crash_keys::SetClientID(client_id);
93 } 107 }
94 108
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
282 default: 296 default:
283 NOTREACHED(); 297 NOTREACHED();
284 } 298 }
285 } 299 }
286 300
287 void ChromeMetricsServiceClient::StartGatheringMetrics( 301 void ChromeMetricsServiceClient::StartGatheringMetrics(
288 const base::Closure& done_callback) { 302 const base::Closure& done_callback) {
289 // TODO(blundell): Move metrics gathering tasks from MetricsService to here. 303 // TODO(blundell): Move metrics gathering tasks from MetricsService to here.
290 done_callback.Run(); 304 done_callback.Run();
291 } 305 }
306
307 #if defined(OS_WIN)
308 void ChromeMetricsServiceClient::CountBrowserCrashDumpAttempts() {
309 // Open the registry key for iteration.
310 base::win::RegKey regkey;
311 if (regkey.Open(HKEY_CURRENT_USER,
312 chrome::kBrowserCrashDumpAttemptsRegistryPath,
313 KEY_ALL_ACCESS) != ERROR_SUCCESS) {
314 return;
315 }
316
317 // The values we're interested in counting are all prefixed with the version.
318 base::string16 chrome_version(base::ASCIIToUTF16(chrome::kChromeVersion));
319
320 // Track a list of values to delete. We don't modify the registry key while
321 // we're iterating over its values.
322 typedef std::vector<base::string16> StringVector;
323 StringVector to_delete;
324
325 // Iterate over the values in the key counting dumps with and without crashes.
326 // We directly walk the values instead of using RegistryValueIterator in order
327 // to read all of the values as DWORDS instead of strings.
328 base::string16 name;
329 DWORD value = 0;
330 int dumps_with_crash = 0;
331 int dumps_with_no_crash = 0;
332 for (int i = regkey.GetValueCount() - 1; i >= 0; --i) {
333 if (regkey.GetValueNameAt(i, &name) == ERROR_SUCCESS &&
334 StartsWith(name, chrome_version, false) &&
335 regkey.ReadValueDW(name.c_str(), &value) == ERROR_SUCCESS) {
336 to_delete.push_back(name);
337 if (value == 0)
338 ++dumps_with_no_crash;
339 else
340 ++dumps_with_crash;
341 }
342 }
343
344 // Delete the registry keys we've just counted.
345 for (StringVector::iterator i = to_delete.begin(); i != to_delete.end(); ++i)
346 regkey.DeleteValue(i->c_str());
347
348 // Capture the histogram samples.
349 if (dumps_with_crash != 0)
350 UMA_HISTOGRAM_COUNTS("Chrome.BrowserDumpsWithCrash", dumps_with_crash);
351 if (dumps_with_no_crash != 0)
352 UMA_HISTOGRAM_COUNTS("Chrome.BrowserDumpsWithNoCrash", dumps_with_no_crash);
353 int total_dumps = dumps_with_crash + dumps_with_no_crash;
354 if (total_dumps != 0)
355 UMA_HISTOGRAM_COUNTS("Chrome.BrowserCrashDumpAttempts", total_dumps);
356 }
357 #endif // defined(OS_WIN)
OLDNEW
« no previous file with comments | « chrome/browser/metrics/chrome_metrics_service_client.h ('k') | chrome/browser/metrics/metrics_service.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698