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

Side by Side Diff: chrome/installer/util/scoped_token_privilege.h

Issue 2925383002: Move ScopedTokenPrivilege to chrome/installer/util (Closed)
Patch Set: Addressed Greg's comments. Created 3 years, 6 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
« no previous file with comments | « chrome/installer/util/BUILD.gn ('k') | chrome/installer/util/scoped_token_privilege.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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 namespace installer {
14
15 // This class is available for Windows only and will enable the privilege
16 // defined by |privilege_name| on the current process' token. The privilege will
17 // be disabled upon the ScopedTokenPrivilege's destruction (unless it was
18 // already enabled when the ScopedTokenPrivilege object was constructed).
19 // Some privileges might require admin rights to be enabled (check is_enabled()
20 // to know whether |privilege_name| was successfully enabled).
21 class ScopedTokenPrivilege {
22 public:
23 explicit ScopedTokenPrivilege(const wchar_t* privilege_name);
24 ~ScopedTokenPrivilege();
25
26 // Always returns true unless the privilege could not be enabled.
27 bool is_enabled() const { return is_enabled_; }
28
29 private:
30 // Always true unless the privilege could not be enabled.
31 bool is_enabled_;
32
33 // A scoped handle to the current process' token. This will be closed
34 // preemptively should enabling the privilege fail in the constructor.
35 base::win::ScopedHandle token_;
36
37 // The previous state of the privilege this object is responsible for. As set
38 // by AdjustTokenPrivileges() upon construction.
39 TOKEN_PRIVILEGES previous_privileges_;
40
41 DISALLOW_IMPLICIT_CONSTRUCTORS(ScopedTokenPrivilege);
42 };
43
44 } // namespace installer
45
46 #endif // CHROME_INSTALLER_UTIL_SCOPED_TOKEN_PRIVILEGE_H_
OLDNEW
« no previous file with comments | « chrome/installer/util/BUILD.gn ('k') | chrome/installer/util/scoped_token_privilege.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698