OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 "remoting/host/usage_stats_consent.h" | 5 #include "remoting/host/usage_stats_consent.h" |
6 | 6 |
7 #include <windows.h> | 7 #include <windows.h> |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
11 #include "base/stringprintf.h" | 11 #include "base/stringprintf.h" |
12 #include "base/win/registry.h" | 12 #include "base/win/registry.h" |
13 #include "remoting/host/constants.h" | 13 #include "remoting/host/constants.h" |
14 | 14 |
15 namespace { | 15 namespace { |
16 | 16 |
17 // The following strings are used to construct the registry key names where | 17 // The following strings are used to construct the registry key names where |
18 // we record whether the user has consented to crash dump collection. | 18 // we record whether the user has consented to crash dump collection. |
19 // the user's consent to collect crash dumps is recorded. | 19 // the user's consent to collect crash dumps is recorded. |
20 const wchar_t kOmahaClientStateKeyFormat[] = | 20 const wchar_t kOmahaClientStateKeyFormat[] = |
21 L"Software\\Google\\Update\\%ls\\%ls"; | 21 L"Software\\Google\\Update\\%ls\\%ls"; |
22 const wchar_t kOmahaClientState[] = L"ClientState"; | 22 const wchar_t kOmahaClientState[] = L"ClientState"; |
23 const wchar_t kOmahaClientStateMedium[] = L"ClientStateMedium"; | 23 const wchar_t kOmahaClientStateMedium[] = L"ClientStateMedium"; |
24 const wchar_t kOmahaUsagestatsValue[] = L"usagestats"; | 24 const wchar_t kOmahaUsagestatsValue[] = L"usagestats"; |
25 | 25 |
26 LONG ReadUsageStatsValue(const wchar_t* state_key, DWORD* usagestats_out) { | 26 LONG ReadUsageStatsValue(const wchar_t* state_key, DWORD* usagestats_out) { |
27 // presubmit: allow wstring | |
27 std::wstring client_state = StringPrintf(kOmahaClientStateKeyFormat, | 28 std::wstring client_state = StringPrintf(kOmahaClientStateKeyFormat, |
28 state_key, | 29 state_key, |
29 remoting::kHostOmahaAppid); | 30 remoting::kHostOmahaAppid); |
Wez
2012/08/06 18:33:18
Here.
alexeypa (please no reviews)
2012/08/06 19:31:54
RegKey's using wchar_t.
| |
30 base::win::RegKey key; | 31 base::win::RegKey key; |
31 LONG result = key.Open(HKEY_LOCAL_MACHINE, client_state.c_str(), KEY_READ); | 32 LONG result = key.Open(HKEY_LOCAL_MACHINE, client_state.c_str(), KEY_READ); |
32 if (result != ERROR_SUCCESS) { | 33 if (result != ERROR_SUCCESS) { |
33 return result; | 34 return result; |
34 } | 35 } |
35 | 36 |
36 return key.ReadValueDW(kOmahaUsagestatsValue, usagestats_out); | 37 return key.ReadValueDW(kOmahaUsagestatsValue, usagestats_out); |
37 } | 38 } |
38 | 39 |
39 } // namespace | 40 } // namespace |
(...skipping 24 matching lines...) Expand all Loading... | |
64 } | 65 } |
65 | 66 |
66 bool IsUsageStatsAllowed() { | 67 bool IsUsageStatsAllowed() { |
67 bool allowed; | 68 bool allowed; |
68 bool set_by_policy; | 69 bool set_by_policy; |
69 return GetUsageStatsConsent(&allowed, &set_by_policy) && allowed; | 70 return GetUsageStatsConsent(&allowed, &set_by_policy) && allowed; |
70 } | 71 } |
71 | 72 |
72 bool SetUsageStatsConsent(bool allowed) { | 73 bool SetUsageStatsConsent(bool allowed) { |
73 DWORD value = allowed; | 74 DWORD value = allowed; |
75 // presubmit: allow wstring | |
74 std::wstring client_state = StringPrintf(kOmahaClientStateKeyFormat, | 76 std::wstring client_state = StringPrintf(kOmahaClientStateKeyFormat, |
75 kOmahaClientStateMedium, | 77 kOmahaClientStateMedium, |
76 kHostOmahaAppid); | 78 kHostOmahaAppid); |
Wez
2012/08/06 18:33:18
Here.
alexeypa (please no reviews)
2012/08/06 19:31:54
RegKey's using wchar_t
| |
77 base::win::RegKey key; | 79 base::win::RegKey key; |
78 LONG result = key.Create(HKEY_LOCAL_MACHINE, client_state.c_str(), | 80 LONG result = key.Create(HKEY_LOCAL_MACHINE, client_state.c_str(), |
79 KEY_SET_VALUE); | 81 KEY_SET_VALUE); |
80 if (result == ERROR_SUCCESS) { | 82 if (result == ERROR_SUCCESS) { |
81 result = key.WriteValue(kOmahaUsagestatsValue, value); | 83 result = key.WriteValue(kOmahaUsagestatsValue, value); |
82 if (result == ERROR_SUCCESS) { | 84 if (result == ERROR_SUCCESS) { |
83 return true; | 85 return true; |
84 } | 86 } |
85 } | 87 } |
86 | 88 |
87 LOG_GETLASTERROR(ERROR) | 89 LOG_GETLASTERROR(ERROR) |
88 << "Failed to record the user's consent to crash dump reporting"; | 90 << "Failed to record the user's consent to crash dump reporting"; |
89 return false; | 91 return false; |
90 } | 92 } |
91 | 93 |
92 } // namespace remoting | 94 } // namespace remoting |
OLD | NEW |