OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2012 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 "remoting/host/usage_stats_consent.h" | |
6 | |
7 #include <windows.h> | |
8 #include <string> | |
9 | |
10 #include "base/stringprintf.h" | |
11 #include "base/win/registry.h" | |
12 #include "remoting/host/constants.h" | |
13 | |
14 namespace { | |
15 | |
16 // The following strings are used to construct the registry key names where | |
17 // we record whether the user has consented to crash dump collection. | |
18 const wchar_t kOmahaClientStateKeyFormat[] = | |
19 L"Software\\Google\\Update\\%ls\\%ls"; | |
20 const wchar_t kOmahaClientState[] = L"ClientState"; | |
21 const wchar_t kOmahaClientStateMedium[] = L"ClientStateMedium"; | |
22 const wchar_t kOmahaUsagestatsValue[] = L"usagestats"; | |
23 | |
24 LONG ReadUsageStatsValue(const wchar_t* state_key, DWORD* usagestats_out) { | |
25 std::wstring client_state = StringPrintf(kOmahaClientStateKeyFormat, | |
26 state_key, | |
27 remoting::kHostOmahaAppid); | |
28 base::win::RegKey key; | |
29 LONG result = key.Open(HKEY_LOCAL_MACHINE, client_state.c_str(), KEY_READ); | |
30 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
| |
31 return result; | |
32 } | |
33 | |
34 return key.ReadValueDW(kOmahaUsagestatsValue, usagestats_out); | |
35 } | |
36 | |
37 } // namespace | |
38 | |
39 namespace remoting { | |
40 | |
41 bool IsCrashReportingEnabled() { | |
42 // The user's consent to collect crash dumps is recored as the "usagestats" | |
43 // value in the ClientState or ClientStateMedium key. Probe | |
44 // the ClientStateMedium key first. | |
45 DWORD value = 0; | |
46 if (ReadUsageStatsValue(kOmahaClientStateMedium, &value) == ERROR_SUCCESS) { | |
47 return value != 0; | |
48 } | |
49 if (ReadUsageStatsValue(kOmahaClientState, &value) == ERROR_SUCCESS) { | |
50 return value != 0; | |
51 } | |
52 | |
53 // Do not collect anything unless the user has explicitly allowed it. | |
54 return false; | |
55 } | |
56 | |
57 } // namespace remoting | |
OLD | NEW |