Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef CHROME_INSTALLER_UTIL_SCOPED_TOKEN_PRIVILEGE_H_ | |
| 6 #define CHROME_INSTALLER_UTIL_SCOPED_TOKEN_PRIVILEGE_H_ | |
| 7 | |
| 8 #include <windows.h> | |
| 9 | |
| 10 #include "base/macros.h" | |
| 11 #include "base/win/scoped_handle.h" | |
| 12 | |
| 13 // This class is available for Windows only and will enable the privilege | |
|
grt (UTC plus 2)
2017/06/09 08:35:28
nit: put this in the "installer" namespace as it w
alito
2017/06/09 17:20:50
Done.
| |
| 14 // defined by |privilege_name| on the current process' token. The privilege will | |
| 15 // be disabled upon the ScopedTokenPrivilege's destruction (unless it was | |
| 16 // already enabled when the ScopedTokenPrivilege object was constructed). | |
| 17 // Some privileges might require admin rights to be enabled (check is_enabled() | |
| 18 // to know whether |privilege_name| was successfully enabled). | |
| 19 class ScopedTokenPrivilege { | |
| 20 public: | |
| 21 explicit ScopedTokenPrivilege(const wchar_t* privilege_name); | |
| 22 ~ScopedTokenPrivilege(); | |
| 23 | |
| 24 // Always returns true unless the privilege could not be enabled. | |
| 25 bool is_enabled() const { return is_enabled_; } | |
| 26 | |
| 27 private: | |
| 28 // Always true unless the privilege could not be enabled. | |
| 29 bool is_enabled_; | |
| 30 | |
| 31 // A scoped handle to the current process' token. This will be closed | |
| 32 // preemptively should enabling the privilege fail in the constructor. | |
| 33 base::win::ScopedHandle token_; | |
| 34 | |
| 35 // The previous state of the privilege this object is responsible for. As set | |
| 36 // by AdjustTokenPrivileges() upon construction. | |
| 37 TOKEN_PRIVILEGES previous_privileges_; | |
| 38 | |
| 39 DISALLOW_IMPLICIT_CONSTRUCTORS(ScopedTokenPrivilege); | |
| 40 }; | |
| 41 | |
| 42 #endif // CHROME_INSTALLER_UTIL_SCOPED_TOKEN_PRIVILEGE_H_ | |
| OLD | NEW |