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

Side by Side Diff: chrome/installer/setup/setup_util.cc

Issue 10912096: C++ reability review for gab. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 3 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
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 // This file declares util functions for setup project. 5 // This file declares util functions for setup project.
6 6
7 //Pickup file for readability review.
8
7 #include "chrome/installer/setup/setup_util.h" 9 #include "chrome/installer/setup/setup_util.h"
8 10
9 #include <windows.h> 11 #include <windows.h>
10 12
11 #include "base/file_util.h" 13 #include "base/file_util.h"
12 #include "base/logging.h" 14 #include "base/logging.h"
13 #include "base/string_util.h" 15 #include "base/string_util.h"
14 #include "chrome/installer/util/installer_state.h" 16 #include "chrome/installer/util/installer_state.h"
15 #include "chrome/installer/util/util_constants.h" 17 #include "chrome/installer/util/util_constants.h"
16 #include "courgette/courgette.h" 18 #include "courgette/courgette.h"
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
142 144
143 string16 GetActiveSetupPath(BrowserDistribution* dist) { 145 string16 GetActiveSetupPath(BrowserDistribution* dist) {
144 static const wchar_t kInstalledComponentsPath[] = 146 static const wchar_t kInstalledComponentsPath[] =
145 L"Software\\Microsoft\\Active Setup\\Installed Components\\"; 147 L"Software\\Microsoft\\Active Setup\\Installed Components\\";
146 return kInstalledComponentsPath + dist->GetAppGuid(); 148 return kInstalledComponentsPath + dist->GetAppGuid();
147 } 149 }
148 150
149 ScopedTokenPrivilege::ScopedTokenPrivilege(const wchar_t* privilege_name) 151 ScopedTokenPrivilege::ScopedTokenPrivilege(const wchar_t* privilege_name)
150 : is_enabled_(false) { 152 : is_enabled_(false) {
151 if (!::OpenProcessToken(::GetCurrentProcess(), 153 if (!::OpenProcessToken(::GetCurrentProcess(),
152 TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, token_.Receive())) { 154 TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, token_.Receive())) {
dominich 2012/09/06 17:26:12 this should either align with ::GetCurrentProcess(
gab 2012/09/07 20:56:44 Done.
153 return; 155 return;
154 } 156 }
155 157
156 LUID privilege_luid; 158 LUID privilege_luid;
157 if (!::LookupPrivilegeValue(NULL, privilege_name, &privilege_luid)) { 159 if (!::LookupPrivilegeValue(NULL, privilege_name, &privilege_luid)) {
158 token_.Close(); 160 token_.Close();
159 return; 161 return;
160 } 162 }
161 163
162 // Adjust the token's privileges to enable |privilege_name|. If this privilege 164 // Adjust the token's privileges to enable |privilege_name|. If this privilege
163 // was already enabled, |previous_privileges_|.PrivilegeCount will be set to 0 165 // was already enabled, |previous_privileges_|.PrivilegeCount will be set to 0
164 // and we then know not to disable this privilege upon destruction. 166 // and we then know not to disable this privilege upon destruction.
165 TOKEN_PRIVILEGES tp; 167 TOKEN_PRIVILEGES tp;
166 tp.PrivilegeCount = 1; 168 tp.PrivilegeCount = 1;
167 tp.Privileges[0].Luid = privilege_luid; 169 tp.Privileges[0].Luid = privilege_luid;
168 tp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED; 170 tp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
169 DWORD return_length; 171 DWORD return_length;
170 if (!::AdjustTokenPrivileges(token_, FALSE, &tp, sizeof(TOKEN_PRIVILEGES), 172 if (!::AdjustTokenPrivileges(token_, FALSE, &tp, sizeof(TOKEN_PRIVILEGES),
dominich 2012/09/06 17:26:12 prefer the positive conditional first.
gab 2012/09/07 20:56:44 Done.
171 &previous_privileges_, &return_length)) { 173 &previous_privileges_, &return_length)) {
172 token_.Close(); 174 token_.Close();
173 } else { 175 } else {
174 is_enabled_ = true; 176 is_enabled_ = true;
175 } 177 }
176 } 178 }
177 179
178 ScopedTokenPrivilege::~ScopedTokenPrivilege() { 180 ScopedTokenPrivilege::~ScopedTokenPrivilege() {
179 if (is_enabled_ && previous_privileges_.PrivilegeCount != 0) { 181 if (is_enabled_ && previous_privileges_.PrivilegeCount != 0) {
180 ::AdjustTokenPrivileges(token_, FALSE, &previous_privileges_, 182 ::AdjustTokenPrivileges(token_, FALSE, &previous_privileges_,
181 sizeof(TOKEN_PRIVILEGES), NULL, NULL); 183 sizeof(TOKEN_PRIVILEGES), NULL, NULL);
182 } 184 }
183 } 185 }
184 186
185 } // namespace installer 187 } // namespace installer
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698