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

Side by Side Diff: remoting/host/usage_stats_consent_win.cc

Issue 10537182: The user's consent to crash dumps reporting can now be set via the UI (Windows only). The checkbox … (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebased Created 8 years, 6 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
« no previous file with comments | « remoting/host/usage_stats_consent.h ('k') | remoting/webapp/_locales/en/messages.json » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/stringprintf.h" 11 #include "base/stringprintf.h"
11 #include "base/win/registry.h" 12 #include "base/win/registry.h"
12 #include "remoting/host/constants.h" 13 #include "remoting/host/constants.h"
13 14
14 namespace { 15 namespace {
15 16
16 // 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
17 // 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.
18 const wchar_t kOmahaClientStateKeyFormat[] = 20 const wchar_t kOmahaClientStateKeyFormat[] =
19 L"Software\\Google\\Update\\%ls\\%ls"; 21 L"Software\\Google\\Update\\%ls\\%ls";
20 const wchar_t kOmahaClientState[] = L"ClientState"; 22 const wchar_t kOmahaClientState[] = L"ClientState";
21 const wchar_t kOmahaClientStateMedium[] = L"ClientStateMedium"; 23 const wchar_t kOmahaClientStateMedium[] = L"ClientStateMedium";
22 const wchar_t kOmahaUsagestatsValue[] = L"usagestats"; 24 const wchar_t kOmahaUsagestatsValue[] = L"usagestats";
23 25
24 LONG ReadUsageStatsValue(const wchar_t* state_key, DWORD* usagestats_out) { 26 LONG ReadUsageStatsValue(const wchar_t* state_key, DWORD* usagestats_out) {
25 std::wstring client_state = StringPrintf(kOmahaClientStateKeyFormat, 27 std::wstring client_state = StringPrintf(kOmahaClientStateKeyFormat,
26 state_key, 28 state_key,
27 remoting::kHostOmahaAppid); 29 remoting::kHostOmahaAppid);
28 base::win::RegKey key; 30 base::win::RegKey key;
29 LONG result = key.Open(HKEY_LOCAL_MACHINE, client_state.c_str(), KEY_READ); 31 LONG result = key.Open(HKEY_LOCAL_MACHINE, client_state.c_str(), KEY_READ);
30 if (result != ERROR_SUCCESS) { 32 if (result != ERROR_SUCCESS) {
31 return result; 33 return result;
32 } 34 }
33 35
34 return key.ReadValueDW(kOmahaUsagestatsValue, usagestats_out); 36 return key.ReadValueDW(kOmahaUsagestatsValue, usagestats_out);
35 } 37 }
36 38
37 } // namespace 39 } // namespace
38 40
39 namespace remoting { 41 namespace remoting {
40 42
41 bool IsCrashReportingEnabled() { 43 bool GetUsageStatsConsent(bool* allowed, bool* set_by_policy) {
44 // TODO(alexeypa): report whether the consent is set by pollicy once
45 // supported.
46 *set_by_policy = false;
47
42 // The user's consent to collect crash dumps is recored as the "usagestats" 48 // The user's consent to collect crash dumps is recored as the "usagestats"
43 // value in the ClientState or ClientStateMedium key. Probe 49 // value in the ClientState or ClientStateMedium key. Probe
44 // the ClientStateMedium key first. 50 // the ClientStateMedium key first.
45 DWORD value = 0; 51 DWORD value = 0;
46 if (ReadUsageStatsValue(kOmahaClientStateMedium, &value) == ERROR_SUCCESS) { 52 if (ReadUsageStatsValue(kOmahaClientStateMedium, &value) == ERROR_SUCCESS) {
47 return value != 0; 53 *allowed = value != 0;
54 return true;
48 } 55 }
49 if (ReadUsageStatsValue(kOmahaClientState, &value) == ERROR_SUCCESS) { 56 if (ReadUsageStatsValue(kOmahaClientState, &value) == ERROR_SUCCESS) {
50 return value != 0; 57 *allowed = value != 0;
58 return true;
51 } 59 }
52 60
53 // Do not collect anything unless the user has explicitly allowed it. 61 LOG_GETLASTERROR(ERROR)
62 << "Failed to record the user's consent to crash dump reporting";
54 return false; 63 return false;
55 } 64 }
56 65
66 bool IsUsageStatsAllowed() {
67 bool allowed;
68 bool set_by_policy;
69 return GetUsageStatsConsent(&allowed, &set_by_policy) && allowed;
70 }
71
72 bool SetUsageStatsConsent(bool allowed) {
73 DWORD value = allowed;
74 std::wstring client_state = StringPrintf(kOmahaClientStateKeyFormat,
75 kOmahaClientStateMedium,
76 kHostOmahaAppid);
77 base::win::RegKey key;
78 LONG result = key.Create(HKEY_LOCAL_MACHINE, client_state.c_str(),
79 KEY_SET_VALUE);
80 if (result == ERROR_SUCCESS) {
81 result = key.WriteValue(kOmahaUsagestatsValue, value);
82 if (result == ERROR_SUCCESS) {
83 return true;
84 }
85 }
86
87 LOG_GETLASTERROR(ERROR)
88 << "Failed to record the user's consent to crash dump reporting";
89 return false;
90 }
91
57 } // namespace remoting 92 } // namespace remoting
OLDNEW
« no previous file with comments | « remoting/host/usage_stats_consent.h ('k') | remoting/webapp/_locales/en/messages.json » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698