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

Unified Diff: chrome_elf/blacklist/blacklist.cc

Issue 2507263002: Make nt_registry Create/OpenRegKey return a scoped object
Patch Set: fixes Created 3 years, 10 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 side-by-side diff with in-line comments
Download patch
Index: chrome_elf/blacklist/blacklist.cc
diff --git a/chrome_elf/blacklist/blacklist.cc b/chrome_elf/blacklist/blacklist.cc
index 05d917fb6db8a32295d0c2f7a9ad96e65a195990..19df821b63515fde9281155b0db3a3ae404d07c1 100644
--- a/chrome_elf/blacklist/blacklist.cc
+++ b/chrome_elf/blacklist/blacklist.cc
@@ -101,16 +101,16 @@ __declspec(allocate(".oldntmap"))
#endif
bool LeaveSetupBeacon() {
- HANDLE key_handle = INVALID_HANDLE_VALUE;
+ nt::ScopedHANDLE key_handle = nt::CreateRegKey(
+ nt::HKCU, kRegistryBeaconPath, KEY_QUERY_VALUE | KEY_SET_VALUE);
- if (!nt::CreateRegKey(nt::HKCU, kRegistryBeaconPath,
- KEY_QUERY_VALUE | KEY_SET_VALUE, &key_handle))
+ if (!key_handle.is_valid())
return false;
DWORD blacklist_state = BLACKLIST_STATE_MAX;
- if (!nt::QueryRegValueDWORD(key_handle, kBeaconState, &blacklist_state) ||
+ if (!nt::QueryRegValueDWORD(key_handle.get(), kBeaconState,
+ &blacklist_state) ||
blacklist_state == BLACKLIST_DISABLED) {
- nt::CloseRegKey(key_handle);
return false;
}
@@ -120,9 +120,9 @@ bool LeaveSetupBeacon() {
if (blacklist_state == BLACKLIST_ENABLED) {
// If the blacklist succeeded on the previous run reset the failure
// counter. Then update the beacon state.
- if (nt::SetRegValueDWORD(key_handle, kBeaconAttemptCount,
+ if (nt::SetRegValueDWORD(key_handle.get(), kBeaconAttemptCount,
static_cast<DWORD>(0))) {
- if (nt::SetRegValueDWORD(key_handle, kBeaconState,
+ if (nt::SetRegValueDWORD(key_handle.get(), kBeaconState,
BLACKLIST_SETUP_RUNNING))
success = true;
}
@@ -132,47 +132,42 @@ bool LeaveSetupBeacon() {
// failed and skip setting up the blacklist.
DWORD attempt_count = 0;
- nt::QueryRegValueDWORD(key_handle, blacklist::kBeaconAttemptCount,
+ nt::QueryRegValueDWORD(key_handle.get(), blacklist::kBeaconAttemptCount,
&attempt_count);
++attempt_count;
- nt::SetRegValueDWORD(key_handle, blacklist::kBeaconAttemptCount,
+ nt::SetRegValueDWORD(key_handle.get(), blacklist::kBeaconAttemptCount,
attempt_count);
if (attempt_count >= blacklist::kBeaconMaxAttempts) {
blacklist_state = blacklist::BLACKLIST_SETUP_FAILED;
- nt::SetRegValueDWORD(key_handle, blacklist::kBeaconState,
+ nt::SetRegValueDWORD(key_handle.get(), blacklist::kBeaconState,
blacklist_state);
}
}
- nt::CloseRegKey(key_handle);
return success;
}
bool ResetBeacon() {
- HANDLE key_handle = INVALID_HANDLE_VALUE;
-
- if (!nt::CreateRegKey(nt::HKCU, kRegistryBeaconPath,
- KEY_QUERY_VALUE | KEY_SET_VALUE, &key_handle))
+ nt::ScopedHANDLE key_handle = nt::CreateRegKey(
+ nt::HKCU, kRegistryBeaconPath, KEY_QUERY_VALUE | KEY_SET_VALUE);
+ if (!key_handle.is_valid())
return false;
DWORD blacklist_state = BLACKLIST_STATE_MAX;
- if (!nt::QueryRegValueDWORD(key_handle, kBeaconState, &blacklist_state)) {
- nt::CloseRegKey(key_handle);
+ if (!nt::QueryRegValueDWORD(key_handle.get(), kBeaconState, &blacklist_state))
return false;
- }
// Reaching this point with the setup running state means the setup did not
// crash, so we reset to enabled. Any other state indicates that setup was
// skipped; in that case we leave the state alone for later recording.
if (blacklist_state == BLACKLIST_SETUP_RUNNING) {
- if (!nt::SetRegValueDWORD(key_handle, kBeaconState, BLACKLIST_ENABLED)) {
- nt::CloseRegKey(key_handle);
+ if (!nt::SetRegValueDWORD(key_handle.get(), kBeaconState,
+ BLACKLIST_ENABLED)) {
return false;
}
}
- nt::CloseRegKey(key_handle);
return true;
}

Powered by Google App Engine
This is Rietveld 408576698