| 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 // This file declares util functions for setup project. | 5 // This file declares util functions for setup project. |
| 6 | 6 |
| 7 #include "chrome/installer/setup/setup_util.h" | 7 #include "chrome/installer/setup/setup_util.h" |
| 8 | 8 |
| 9 #include <windows.h> | 9 #include <windows.h> |
| 10 | 10 |
| (...skipping 434 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 445 // The following status values represent failed uninstalls: | 445 // The following status values represent failed uninstalls: |
| 446 // 15: CHROME_NOT_INSTALLED | 446 // 15: CHROME_NOT_INSTALLED |
| 447 // 20: UNINSTALL_FAILED | 447 // 20: UNINSTALL_FAILED |
| 448 // 21: UNINSTALL_CANCELLED | 448 // 21: UNINSTALL_CANCELLED |
| 449 return (install_status == UNINSTALL_SUCCESSFUL || | 449 return (install_status == UNINSTALL_SUCCESSFUL || |
| 450 install_status == UNINSTALL_REQUIRES_REBOOT); | 450 install_status == UNINSTALL_REQUIRES_REBOOT); |
| 451 } | 451 } |
| 452 | 452 |
| 453 ScopedTokenPrivilege::ScopedTokenPrivilege(const wchar_t* privilege_name) | 453 ScopedTokenPrivilege::ScopedTokenPrivilege(const wchar_t* privilege_name) |
| 454 : is_enabled_(false) { | 454 : is_enabled_(false) { |
| 455 HANDLE temp_handle; |
| 455 if (!::OpenProcessToken(::GetCurrentProcess(), | 456 if (!::OpenProcessToken(::GetCurrentProcess(), |
| 456 TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, | 457 TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, |
| 457 token_.Receive())) { | 458 &temp_handle)) { |
| 458 return; | 459 return; |
| 459 } | 460 } |
| 461 token_.Set(temp_handle); |
| 460 | 462 |
| 461 LUID privilege_luid; | 463 LUID privilege_luid; |
| 462 if (!::LookupPrivilegeValue(NULL, privilege_name, &privilege_luid)) { | 464 if (!::LookupPrivilegeValue(NULL, privilege_name, &privilege_luid)) { |
| 463 token_.Close(); | 465 token_.Close(); |
| 464 return; | 466 return; |
| 465 } | 467 } |
| 466 | 468 |
| 467 // Adjust the token's privileges to enable |privilege_name|. If this privilege | 469 // Adjust the token's privileges to enable |privilege_name|. If this privilege |
| 468 // was already enabled, |previous_privileges_|.PrivilegeCount will be set to 0 | 470 // was already enabled, |previous_privileges_|.PrivilegeCount will be set to 0 |
| 469 // and we then know not to disable this privilege upon destruction. | 471 // and we then know not to disable this privilege upon destruction. |
| (...skipping 12 matching lines...) Expand all Loading... |
| 482 } | 484 } |
| 483 | 485 |
| 484 ScopedTokenPrivilege::~ScopedTokenPrivilege() { | 486 ScopedTokenPrivilege::~ScopedTokenPrivilege() { |
| 485 if (is_enabled_ && previous_privileges_.PrivilegeCount != 0) { | 487 if (is_enabled_ && previous_privileges_.PrivilegeCount != 0) { |
| 486 ::AdjustTokenPrivileges(token_, FALSE, &previous_privileges_, | 488 ::AdjustTokenPrivileges(token_, FALSE, &previous_privileges_, |
| 487 sizeof(TOKEN_PRIVILEGES), NULL, NULL); | 489 sizeof(TOKEN_PRIVILEGES), NULL, NULL); |
| 488 } | 490 } |
| 489 } | 491 } |
| 490 | 492 |
| 491 } // namespace installer | 493 } // namespace installer |
| OLD | NEW |