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

Side by Side Diff: chrome_elf/blacklist/blacklist.cc

Issue 500563002: Reorder GenerateStateFromBeaconAndAttemptCount. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 4 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 | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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_elf/blacklist/blacklist.h" 5 #include "chrome_elf/blacklist/blacklist.h"
6 6
7 #include <assert.h> 7 #include <assert.h>
8 #include <string.h> 8 #include <string.h>
9 9
10 #include <vector> 10 #include <vector>
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
80 return ::RegSetValueEx(*key, 80 return ::RegSetValueEx(*key,
81 property, 81 property,
82 0, 82 0,
83 REG_DWORD, 83 REG_DWORD,
84 reinterpret_cast<LPBYTE>(&value), 84 reinterpret_cast<LPBYTE>(&value),
85 sizeof(value)); 85 sizeof(value));
86 } 86 }
87 87
88 bool GenerateStateFromBeaconAndAttemptCount(HKEY* key, DWORD blacklist_state) { 88 bool GenerateStateFromBeaconAndAttemptCount(HKEY* key, DWORD blacklist_state) {
89 LONG result = 0; 89 LONG result = 0;
90 if (blacklist_state == blacklist::BLACKLIST_SETUP_RUNNING) { 90 if (blacklist_state == blacklist::BLACKLIST_ENABLED) {
robertshield 2014/08/25 13:40:18 previously, BLACKLIST_STATE_FAILED would hit this
91 // If the blacklist succeeded on the previous run reset the failure
92 // counter.
93 return (SetDWValue(key,
94 blacklist::kBeaconAttemptCount,
95 static_cast<DWORD>(0)) == ERROR_SUCCESS);
96 } else {
91 // Some part of the blacklist setup failed last time. If this has occured 97 // Some part of the blacklist setup failed last time. If this has occured
92 // blacklist::kBeaconMaxAttempts times in a row we switch the state to 98 // blacklist::kBeaconMaxAttempts times in a row we switch the state to
93 // failed and skip setting up the blacklist. 99 // failed and skip setting up the blacklist.
94 DWORD attempt_count = 0; 100 DWORD attempt_count = 0;
95 DWORD attempt_count_size = sizeof(attempt_count); 101 DWORD attempt_count_size = sizeof(attempt_count);
96 result = ::RegQueryValueEx(*key, 102 result = ::RegQueryValueEx(*key,
97 blacklist::kBeaconAttemptCount, 103 blacklist::kBeaconAttemptCount,
98 0, 104 0,
99 NULL, 105 NULL,
100 reinterpret_cast<LPBYTE>(&attempt_count), 106 reinterpret_cast<LPBYTE>(&attempt_count),
101 &attempt_count_size); 107 &attempt_count_size);
102 108
103 if (result == ERROR_FILE_NOT_FOUND) 109 if (result == ERROR_FILE_NOT_FOUND)
104 attempt_count = 0; 110 attempt_count = 0;
105 else if (result != ERROR_SUCCESS) 111 else if (result != ERROR_SUCCESS)
106 return false; 112 return false;
107 113
108 ++attempt_count; 114 ++attempt_count;
109 SetDWValue(key, blacklist::kBeaconAttemptCount, attempt_count); 115 SetDWValue(key, blacklist::kBeaconAttemptCount, attempt_count);
110 116
111 if (attempt_count >= blacklist::kBeaconMaxAttempts) { 117 if (attempt_count >= blacklist::kBeaconMaxAttempts) {
112 blacklist_state = blacklist::BLACKLIST_SETUP_FAILED; 118 blacklist_state = blacklist::BLACKLIST_SETUP_FAILED;
113 SetDWValue(key, blacklist::kBeaconState, blacklist_state); 119 SetDWValue(key, blacklist::kBeaconState, blacklist_state);
114 return false;
115 } 120 }
116 } else if (blacklist_state == blacklist::BLACKLIST_ENABLED) { 121
117 // If the blacklist succeeded on the previous run reset the failure 122 return false;
118 // counter.
119 result =
120 SetDWValue(key, blacklist::kBeaconAttemptCount, static_cast<DWORD>(0));
121 if (result != ERROR_SUCCESS) {
122 return false;
123 }
124 } 123 }
125 return true;
126 } 124 }
127 125
128 } // namespace 126 } // namespace
129 127
130 namespace blacklist { 128 namespace blacklist {
131 129
132 #if defined(_WIN64) 130 #if defined(_WIN64)
133 // Allocate storage for the pointer to the old NtMapViewOfSectionFunction. 131 // Allocate storage for the pointer to the old NtMapViewOfSectionFunction.
134 #pragma section(".oldntmap",write,read) 132 #pragma section(".oldntmap",write,read)
135 __declspec(allocate(".oldntmap")) 133 __declspec(allocate(".oldntmap"))
(...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after
435 break; 433 break;
436 value_buffer[value_len - 1] = L'\0'; 434 value_buffer[value_len - 1] = L'\0';
437 AddDllToBlacklist(&value_buffer[0]); 435 AddDllToBlacklist(&value_buffer[0]);
438 } 436 }
439 437
440 ::RegCloseKey(key); 438 ::RegCloseKey(key);
441 return; 439 return;
442 } 440 }
443 441
444 } // namespace blacklist 442 } // namespace blacklist
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698