Chromium Code Reviews

Side by Side Diff: chrome/browser/configuration_policy_provider_win.cc

Issue 3033030: [win] Don't initialize the crash reporter on windows if disabled by configuration management. (Closed) Base URL: ssh://mnissler@kea.muc/usr/local/google/home/mnissler/chrome/src/
Patch Set: Allow policy to force-enable metrics reporting. Created 10 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff |
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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 "chrome/browser/configuration_policy_provider_win.h" 5 #include "chrome/browser/configuration_policy_provider_win.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/registry.h" 10 #include "base/registry.h"
11 #include "base/scoped_ptr.h" 11 #include "base/scoped_ptr.h"
12 #include "base/string_piece.h" 12 #include "base/string_piece.h"
13 #include "base/sys_string_conversions.h" 13 #include "base/sys_string_conversions.h"
14 #include "base/utf_string_conversions.h" 14 #include "base/utf_string_conversions.h"
15 #include "base/values.h" 15 #include "base/values.h"
16 16 #include "chrome/common/policy_constants.h"
17 #if defined(GOOGLE_CHROME_BUILD)
18 const wchar_t ConfigurationPolicyProviderWin::kPolicyRegistrySubKey[] =
19 L"SOFTWARE\\Policies\\Google\\Chrome";
20 #else
21 const wchar_t ConfigurationPolicyProviderWin::kPolicyRegistrySubKey[] =
22 L"SOFTWARE\\Policies\\Chromium";
23 #endif
24 17
25 ConfigurationPolicyProviderWin::ConfigurationPolicyProviderWin() { 18 ConfigurationPolicyProviderWin::ConfigurationPolicyProviderWin() {
26 } 19 }
27 20
28 bool ConfigurationPolicyProviderWin::GetRegistryPolicyString( 21 bool ConfigurationPolicyProviderWin::GetRegistryPolicyString(
29 const wchar_t* value_name, string16* result) { 22 const wchar_t* value_name, string16* result) {
30 DWORD value_size = 0; 23 DWORD value_size = 0;
31 DWORD key_type = 0; 24 DWORD key_type = 0;
32 scoped_array<uint8> buffer; 25 scoped_array<uint8> buffer;
33 RegKey hkcu_policy_key(HKEY_LOCAL_MACHINE, kPolicyRegistrySubKey); 26 RegKey hkcu_policy_key(HKEY_LOCAL_MACHINE, policy::kRegistrySubKey);
34 if (hkcu_policy_key.ReadValue(value_name, 0, &value_size, &key_type)) { 27 if (hkcu_policy_key.ReadValue(value_name, 0, &value_size, &key_type)) {
35 if (key_type != REG_SZ) 28 if (key_type != REG_SZ)
36 return false; 29 return false;
37 // According to the Microsoft documentation, the string 30 // According to the Microsoft documentation, the string
38 // buffer may not be explicitly 0-terminated. Allocate a 31 // buffer may not be explicitly 0-terminated. Allocate a
39 // slightly larger buffer and prefill to zeros to guarantee 32 // slightly larger buffer and prefill to zeros to guarantee
40 // the 0-termination. 33 // the 0-termination.
41 buffer.reset(new uint8[value_size + 2]); 34 buffer.reset(new uint8[value_size + 2]);
42 memset(buffer.get(), 0, value_size + 2); 35 memset(buffer.get(), 0, value_size + 2);
43 hkcu_policy_key.ReadValue(value_name, buffer.get(), &value_size); 36 hkcu_policy_key.ReadValue(value_name, buffer.get(), &value_size);
44 } else { 37 } else {
45 RegKey hklm_policy_key(HKEY_CURRENT_USER, kPolicyRegistrySubKey); 38 RegKey hklm_policy_key(HKEY_CURRENT_USER, policy::kRegistrySubKey);
46 if (hklm_policy_key.ReadValue(value_name, 0, &value_size, &key_type)) { 39 if (hklm_policy_key.ReadValue(value_name, 0, &value_size, &key_type)) {
47 if (key_type != REG_SZ) 40 if (key_type != REG_SZ)
48 return false; 41 return false;
49 // According to the Microsoft documentation, the string 42 // According to the Microsoft documentation, the string
50 // buffer may not be explicitly 0-terminated. Allocate a 43 // buffer may not be explicitly 0-terminated. Allocate a
51 // slightly larger buffer and prefill to zeros to guarantee 44 // slightly larger buffer and prefill to zeros to guarantee
52 // the 0-termination. 45 // the 0-termination.
53 buffer.reset(new uint8[value_size + 2]); 46 buffer.reset(new uint8[value_size + 2]);
54 memset(buffer.get(), 0, value_size + 2); 47 memset(buffer.get(), 0, value_size + 2);
55 hklm_policy_key.ReadValue(value_name, buffer.get(), &value_size); 48 hklm_policy_key.ReadValue(value_name, buffer.get(), &value_size);
56 } else { 49 } else {
57 return false; 50 return false;
58 } 51 }
59 } 52 }
60 53
61 result->assign(reinterpret_cast<const wchar_t*>(buffer.get())); 54 result->assign(reinterpret_cast<const wchar_t*>(buffer.get()));
62 return true; 55 return true;
63 } 56 }
64 57
65 bool ConfigurationPolicyProviderWin::GetRegistryPolicyBoolean( 58 bool ConfigurationPolicyProviderWin::GetRegistryPolicyBoolean(
66 const wchar_t* value_name, bool* result) { 59 const wchar_t* value_name, bool* result) {
67 DWORD value; 60 DWORD value;
68 RegKey hkcu_policy_key(HKEY_LOCAL_MACHINE, kPolicyRegistrySubKey); 61 RegKey hkcu_policy_key(HKEY_LOCAL_MACHINE, policy::kRegistrySubKey);
69 if (hkcu_policy_key.ReadValueDW(value_name, &value)) { 62 if (hkcu_policy_key.ReadValueDW(value_name, &value)) {
70 *result = value != 0; 63 *result = value != 0;
71 return true; 64 return true;
72 } 65 }
73 66
74 RegKey hklm_policy_key(HKEY_CURRENT_USER, kPolicyRegistrySubKey); 67 RegKey hklm_policy_key(HKEY_CURRENT_USER, policy::kRegistrySubKey);
75 if (hklm_policy_key.ReadValueDW(value_name, &value)) { 68 if (hklm_policy_key.ReadValueDW(value_name, &value)) {
76 *result = value != 0; 69 *result = value != 0;
77 return true; 70 return true;
78 } 71 }
79 return false; 72 return false;
80 } 73 }
81 74
82 bool ConfigurationPolicyProviderWin::GetRegistryPolicyInteger( 75 bool ConfigurationPolicyProviderWin::GetRegistryPolicyInteger(
83 const wchar_t* value_name, uint32* result) { 76 const wchar_t* value_name, uint32* result) {
84 DWORD value; 77 DWORD value;
85 RegKey hkcu_policy_key(HKEY_LOCAL_MACHINE, kPolicyRegistrySubKey); 78 RegKey hkcu_policy_key(HKEY_LOCAL_MACHINE, policy::kRegistrySubKey);
86 if (hkcu_policy_key.ReadValueDW(value_name, &value)) { 79 if (hkcu_policy_key.ReadValueDW(value_name, &value)) {
87 *result = value; 80 *result = value;
88 return true; 81 return true;
89 } 82 }
90 83
91 RegKey hklm_policy_key(HKEY_CURRENT_USER, kPolicyRegistrySubKey); 84 RegKey hklm_policy_key(HKEY_CURRENT_USER, policy::kRegistrySubKey);
92 if (hklm_policy_key.ReadValueDW(value_name, &value)) { 85 if (hklm_policy_key.ReadValueDW(value_name, &value)) {
93 *result = value; 86 *result = value;
94 return true; 87 return true;
95 } 88 }
96 return false; 89 return false;
97 } 90 }
98 91
99 bool ConfigurationPolicyProviderWin::Provide( 92 bool ConfigurationPolicyProviderWin::Provide(
100 ConfigurationPolicyStore* store) { 93 ConfigurationPolicyStore* store) {
101 const PolicyValueMap* mapping = PolicyValueMapping(); 94 const PolicyValueMap* mapping = PolicyValueMapping();
(...skipping 25 matching lines...)
127 } 120 }
128 break; 121 break;
129 default: 122 default:
130 NOTREACHED(); 123 NOTREACHED();
131 return false; 124 return false;
132 } 125 }
133 } 126 }
134 127
135 return true; 128 return true;
136 } 129 }
137
OLDNEW

Powered by Google App Engine