Chromium Code Reviews| 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 "base/win/registry.h" | 5 #include "base/win/registry.h" |
| 6 | 6 |
| 7 #include <shlwapi.h> | 7 #include <shlwapi.h> |
| 8 #include <algorithm> | 8 #include <algorithm> |
| 9 | 9 |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 98 if ((access & kWow64AccessMask) != wow64access_) { | 98 if ((access & kWow64AccessMask) != wow64access_) { |
| 99 NOTREACHED(); | 99 NOTREACHED(); |
| 100 return ERROR_INVALID_PARAMETER; | 100 return ERROR_INVALID_PARAMETER; |
| 101 } | 101 } |
| 102 HKEY subkey = NULL; | 102 HKEY subkey = NULL; |
| 103 LONG result = RegCreateKeyEx(key_, name, 0, NULL, REG_OPTION_NON_VOLATILE, | 103 LONG result = RegCreateKeyEx(key_, name, 0, NULL, REG_OPTION_NON_VOLATILE, |
| 104 access, NULL, &subkey, NULL); | 104 access, NULL, &subkey, NULL); |
| 105 if (result == ERROR_SUCCESS) { | 105 if (result == ERROR_SUCCESS) { |
| 106 Close(); | 106 Close(); |
| 107 key_ = subkey; | 107 key_ = subkey; |
| 108 wow64access_ = access & kWow64AccessMask; | |
| 108 } | 109 } |
| 109 | 110 |
| 110 return result; | 111 return result; |
| 111 } | 112 } |
| 112 | 113 |
| 113 LONG RegKey::Open(HKEY rootkey, const wchar_t* subkey, REGSAM access) { | 114 LONG RegKey::Open(HKEY rootkey, const wchar_t* subkey, REGSAM access) { |
| 114 DCHECK(rootkey && subkey && access); | 115 DCHECK(rootkey && subkey && access); |
| 115 HKEY subhkey = NULL; | 116 HKEY subhkey = NULL; |
| 116 | 117 |
| 117 LONG result = RegOpenKeyEx(rootkey, subkey, 0, access, &subhkey); | 118 LONG result = RegOpenKeyEx(rootkey, subkey, 0, access, &subhkey); |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 136 return ERROR_INVALID_PARAMETER; | 137 return ERROR_INVALID_PARAMETER; |
| 137 } | 138 } |
| 138 HKEY subkey = NULL; | 139 HKEY subkey = NULL; |
| 139 LONG result = RegOpenKeyEx(key_, relative_key_name, 0, access, &subkey); | 140 LONG result = RegOpenKeyEx(key_, relative_key_name, 0, access, &subkey); |
| 140 | 141 |
| 141 // We have to close the current opened key before replacing it with the new | 142 // We have to close the current opened key before replacing it with the new |
| 142 // one. | 143 // one. |
| 143 if (result == ERROR_SUCCESS) { | 144 if (result == ERROR_SUCCESS) { |
| 144 Close(); | 145 Close(); |
| 145 key_ = subkey; | 146 key_ = subkey; |
| 147 wow64access_ = access & kWow64AccessMask; | |
| 146 } | 148 } |
| 147 return result; | 149 return result; |
| 148 } | 150 } |
| 149 | 151 |
| 150 void RegKey::Close() { | 152 void RegKey::Close() { |
| 151 StopWatching(); | 153 StopWatching(); |
| 152 if (key_) { | 154 if (key_) { |
| 153 ::RegCloseKey(key_); | 155 ::RegCloseKey(key_); |
| 154 key_ = NULL; | 156 key_ = NULL; |
| 155 wow64access_ = 0; | 157 wow64access_ = 0; |
| 156 } | 158 } |
| 157 } | 159 } |
| 158 | 160 |
| 159 // TODO(wfh): Remove this and other unsafe methods. See http://crbug.com/375400 | 161 // TODO(wfh): Remove this and other unsafe methods. See http://crbug.com/375400 |
| 160 void RegKey::Set(HKEY key) { | 162 void RegKey::Set(HKEY key) { |
| 161 if (key_ != key) { | 163 if (key_ != key) { |
| 162 Close(); | 164 Close(); |
| 163 key_ = key; | 165 key_ = key; |
| 164 wow64access_ = 0; | 166 wow64access_ = 0; |
|
grt (UTC plus 2)
2014/06/14 13:23:17
this is redundant. remove it?
Will Harris
2014/06/16 16:04:50
Done.
| |
| 165 } | 167 } |
| 166 } | 168 } |
| 167 | 169 |
| 168 HKEY RegKey::Take() { | 170 HKEY RegKey::Take() { |
| 169 DCHECK(wow64access_ == 0); | 171 DCHECK(wow64access_ == 0); |
| 170 StopWatching(); | 172 StopWatching(); |
| 171 HKEY key = key_; | 173 HKEY key = key_; |
| 172 key_ = NULL; | 174 key_ = NULL; |
| 173 return key; | 175 return key; |
| 174 } | 176 } |
| (...skipping 453 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 628 if (ERROR_SUCCESS == r) | 630 if (ERROR_SUCCESS == r) |
| 629 return true; | 631 return true; |
| 630 } | 632 } |
| 631 | 633 |
| 632 name_[0] = '\0'; | 634 name_[0] = '\0'; |
| 633 return false; | 635 return false; |
| 634 } | 636 } |
| 635 | 637 |
| 636 } // namespace win | 638 } // namespace win |
| 637 } // namespace base | 639 } // namespace base |
| OLD | NEW |