Chromium Code Reviews| Index: remoting/host/usage_stats_consent_win.cc |
| diff --git a/remoting/host/usage_stats_consent_win.cc b/remoting/host/usage_stats_consent_win.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..3b5b283a0c8caad47043e321c505ad5bc37aa74f |
| --- /dev/null |
| +++ b/remoting/host/usage_stats_consent_win.cc |
| @@ -0,0 +1,57 @@ |
| +// Copyright (c) 2012 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 "remoting/host/usage_stats_consent.h" |
| + |
| +#include <windows.h> |
| +#include <string> |
| + |
| +#include "base/stringprintf.h" |
| +#include "base/win/registry.h" |
| +#include "remoting/host/constants.h" |
| + |
| +namespace { |
| + |
| +// The following strings are used to construct the registry key names where |
| +// we record whether the user has consented to crash dump collection. |
| +const wchar_t kOmahaClientStateKeyFormat[] = |
| + L"Software\\Google\\Update\\%ls\\%ls"; |
| +const wchar_t kOmahaClientState[] = L"ClientState"; |
| +const wchar_t kOmahaClientStateMedium[] = L"ClientStateMedium"; |
| +const wchar_t kOmahaUsagestatsValue[] = L"usagestats"; |
| + |
| +LONG ReadUsageStatsValue(const wchar_t* state_key, DWORD* usagestats_out) { |
| + std::wstring client_state = StringPrintf(kOmahaClientStateKeyFormat, |
| + state_key, |
| + remoting::kHostOmahaAppid); |
| + base::win::RegKey key; |
| + LONG result = key.Open(HKEY_LOCAL_MACHINE, client_state.c_str(), KEY_READ); |
| + if (result != ERROR_SUCCESS) { |
|
Peter Kasting
2012/06/15 21:19:30
Nit: You may also shorten as follows:
return (r
alexeypa (please no reviews)
2012/06/15 22:13:57
Ternary operators are less common in code. It seem
|
| + return result; |
| + } |
| + |
| + return key.ReadValueDW(kOmahaUsagestatsValue, usagestats_out); |
| +} |
| + |
| +} // namespace |
| + |
| +namespace remoting { |
| + |
| +bool IsCrashReportingEnabled() { |
| + // The user's consent to collect crash dumps is recored as the "usagestats" |
| + // value in the ClientState or ClientStateMedium key. Probe |
| + // the ClientStateMedium key first. |
| + DWORD value = 0; |
| + if (ReadUsageStatsValue(kOmahaClientStateMedium, &value) == ERROR_SUCCESS) { |
| + return value != 0; |
| + } |
| + if (ReadUsageStatsValue(kOmahaClientState, &value) == ERROR_SUCCESS) { |
| + return value != 0; |
| + } |
| + |
| + // Do not collect anything unless the user has explicitly allowed it. |
| + return false; |
| +} |
| + |
| +} // namespace remoting |