| Index: components/browser_watcher/watcher_metrics_provider_win.cc
|
| diff --git a/components/browser_watcher/watcher_metrics_provider_win.cc b/components/browser_watcher/watcher_metrics_provider_win.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..72b14759fb37b08e2db8f3d0f50144d46ac73a33
|
| --- /dev/null
|
| +++ b/components/browser_watcher/watcher_metrics_provider_win.cc
|
| @@ -0,0 +1,88 @@
|
| +// Copyright (c) 2014 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 "components/browser_watcher/watcher_metrics_provider_win.h"
|
| +
|
| +#include "base/metrics/sparse_histogram.h"
|
| +#include "base/process/process_handle.h"
|
| +#include "base/strings/string_number_conversions.h"
|
| +#include "base/win/registry.h"
|
| +
|
| +namespace browser_watcher {
|
| +
|
| +namespace {
|
| +
|
| +// This function does soft matching on the PID recorded in the key only.
|
| +// Due to PID reuse, the possibility exists that the process that's now live
|
| +// is not the same process the data was recorded for. This doesn't matter for
|
| +// this purpose, as eventually the data will be scavenged and reported.
|
| +bool IsLiveProcess(const base::string16& key_name) {
|
| + int pid = 0;
|
| + base::StringToInt(key_name, &pid);
|
| +
|
| + if (pid == 0)
|
| + return false;
|
| +
|
| + // This is a very inexpensive check for the common case of our own PID.
|
| + if (static_cast<base::ProcessId>(pid) == base::GetCurrentProcId())
|
| + return true;
|
| +
|
| + // The process is not our own - see whether a process with this PID exists.
|
| + base::ProcessHandle process = base::kNullProcessHandle;
|
| + if (base::OpenProcessHandle(static_cast<base::ProcessId>(pid), &process)) {
|
| + base::CloseProcessHandle(process);
|
| +
|
| + return true;
|
| + }
|
| +
|
| + return false;
|
| +}
|
| +
|
| +} // namespace
|
| +
|
| +const char WatcherMetricsProviderWin::kBrowserExitCodeHistogramName[] =
|
| + "Stability.BrowserExitCodes";
|
| +
|
| +
|
| +WatcherMetricsProviderWin::WatcherMetricsProviderWin(
|
| + const base::string16& registry_path) : registry_path_(registry_path) {
|
| +}
|
| +
|
| +void WatcherMetricsProviderWin::ProvideStabilityMetrics(
|
| + metrics::SystemProfileProto* system_profile_proto) {
|
| + base::win::RegKey regkey(HKEY_CURRENT_USER,
|
| + registry_path_.c_str(),
|
| + KEY_QUERY_VALUE | KEY_SET_VALUE);
|
| +
|
| + std::vector<base::string16> to_delete;
|
| + size_t num = regkey.GetValueCount();
|
| +
|
| + // Record the exit codes in a sparse histogram, as the range of values
|
| + // used to report failures is large.
|
| + base::HistogramBase* exit_code_histogram =
|
| + // TODO(siggi): is this an acceptable name?
|
| + base::SparseHistogram::FactoryGet(kBrowserExitCodeHistogramName,
|
| + base::HistogramBase::kUmaStabilityHistogramFlag);
|
| +
|
| + for (size_t i = 0; i < num; ++i) {
|
| + base::string16 name;
|
| + if (regkey.GetValueNameAt(i, &name) == ERROR_SUCCESS) {
|
| + DWORD exit_code = 0;
|
| + if (regkey.ReadValueDW(name.c_str(), &exit_code) == ERROR_SUCCESS) {
|
| + // Do not report exit codes for processes that are still live, notably
|
| + // not for our own process.
|
| + if (exit_code != STILL_ACTIVE || !IsLiveProcess(name)) {
|
| + to_delete.push_back(name);
|
| + exit_code_histogram->Add(exit_code);
|
| + }
|
| + }
|
| + }
|
| + }
|
| +
|
| + // Delete the values reported above.
|
| + for (size_t i = 0; i < to_delete.size(); ++i)
|
| + regkey.DeleteValue(to_delete[i].c_str());
|
| +}
|
| +
|
| +} // namespace browser_watcher
|
|
|