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

Side by Side Diff: remoting/host/win/elevation_helpers.cc

Issue 2961333002: Fix field trials not working in utility processes. (Closed)
Patch Set: review comment Created 3 years, 5 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
OLDNEW
(Empty)
1 // Copyright 2016 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 #include "remoting/host/win/elevation_helpers.h"
6
7 #include <windows.h>
8
9 #include "base/logging.h"
10 #include "base/win/scoped_handle.h"
11
12 namespace {
13
14 void GetCurrentProcessToken(base::win::ScopedHandle* scoped_handle) {
15 DCHECK(scoped_handle);
16
17 HANDLE process_token;
18 OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, &process_token);
19 scoped_handle->Set(process_token);
20 DCHECK(scoped_handle->IsValid());
21 }
22
23 } // namespace
24
25 namespace remoting {
26
27 bool IsProcessElevated() {
28 base::win::ScopedHandle scoped_process_token;
29 GetCurrentProcessToken(&scoped_process_token);
30
31 // Unlike TOKEN_ELEVATION_TYPE which returns TokenElevationTypeDefault when
32 // UAC is turned off, TOKEN_ELEVATION returns whether the process is elevated.
33 DWORD size;
34 TOKEN_ELEVATION elevation;
35 if (!GetTokenInformation(scoped_process_token.Get(), TokenElevation,
36 &elevation, sizeof(elevation), &size)) {
37 PLOG(ERROR) << "GetTokenInformation() failed";
38 return false;
39 }
40 return elevation.TokenIsElevated != 0;
41 }
42
43 bool CurrentProcessHasUiAccess() {
44 base::win::ScopedHandle scoped_process_token;
45 GetCurrentProcessToken(&scoped_process_token);
46
47 DWORD size;
48 DWORD uiaccess_value = 0;
49 if (!GetTokenInformation(scoped_process_token.Get(), TokenUIAccess,
50 &uiaccess_value, sizeof(uiaccess_value), &size)) {
51 PLOG(ERROR) << "GetTokenInformation() failed";
52 return false;
53 }
54 return uiaccess_value != 0;
55 }
56
57 } // namespace remoting
OLDNEW
« base/process/process_info_win.cc ('K') | « remoting/host/win/elevation_helpers.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698