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

Side by Side Diff: base/win/win_util.cc

Issue 2667513003: Remove some LazyInstance use in base/ (Closed)
Patch Set: no message_window Created 3 years, 10 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
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 #include "base/win/win_util.h" 5 #include "base/win/win_util.h"
6 6
7 #include <aclapi.h> 7 #include <aclapi.h>
8 #include <cfgmgr32.h> 8 #include <cfgmgr32.h>
9 #include <powrprof.h> 9 #include <powrprof.h>
10 #include <shobjidl.h> // Must be before propkey. 10 #include <shobjidl.h> // Must be before propkey.
(...skipping 14 matching lines...) Expand all
25 #include <tpcshrd.h> 25 #include <tpcshrd.h>
26 #include <uiviewsettingsinterop.h> 26 #include <uiviewsettingsinterop.h>
27 #include <windows.ui.viewmanagement.h> 27 #include <windows.ui.viewmanagement.h>
28 #include <winstring.h> 28 #include <winstring.h>
29 #include <wrl/wrappers/corewrappers.h> 29 #include <wrl/wrappers/corewrappers.h>
30 30
31 #include <memory> 31 #include <memory>
32 32
33 #include "base/base_switches.h" 33 #include "base/base_switches.h"
34 #include "base/command_line.h" 34 #include "base/command_line.h"
35 #include "base/lazy_instance.h"
36 #include "base/logging.h" 35 #include "base/logging.h"
37 #include "base/macros.h" 36 #include "base/macros.h"
38 #include "base/strings/string_util.h" 37 #include "base/strings/string_util.h"
39 #include "base/strings/stringprintf.h" 38 #include "base/strings/stringprintf.h"
40 #include "base/strings/utf_string_conversions.h" 39 #include "base/strings/utf_string_conversions.h"
41 #include "base/threading/thread_restrictions.h" 40 #include "base/threading/thread_restrictions.h"
42 #include "base/win/registry.h" 41 #include "base/win/registry.h"
43 #include "base/win/scoped_comptr.h" 42 #include "base/win/scoped_comptr.h"
44 #include "base/win/scoped_handle.h" 43 #include "base/win/scoped_handle.h"
45 #include "base/win/scoped_propvariant.h" 44 #include "base/win/scoped_propvariant.h"
(...skipping 14 matching lines...) Expand all
60 HRESULT result = property_store->SetValue(property_key, property_value.get()); 59 HRESULT result = property_store->SetValue(property_key, property_value.get());
61 if (result == S_OK) 60 if (result == S_OK)
62 result = property_store->Commit(); 61 result = property_store->Commit();
63 return SUCCEEDED(result); 62 return SUCCEEDED(result);
64 } 63 }
65 64
66 void __cdecl ForceCrashOnSigAbort(int) { 65 void __cdecl ForceCrashOnSigAbort(int) {
67 *((volatile int*)0) = 0x1337; 66 *((volatile int*)0) = 0x1337;
68 } 67 }
69 68
70 typedef decltype(GetProcessMitigationPolicy)* GetProcessMitigationPolicyType;
71
72 class LazyIsUser32AndGdi32Available {
73 public:
74 LazyIsUser32AndGdi32Available() : value_(!IsWin32kSyscallsDisabled()) {}
75
76 ~LazyIsUser32AndGdi32Available() {}
77
78 bool value() { return value_; }
79
80 private:
81 static bool IsWin32kSyscallsDisabled() {
82 // Can't disable win32k prior to windows 8.
83 if (base::win::GetVersion() < base::win::VERSION_WIN8)
84 return false;
85
86 GetProcessMitigationPolicyType get_process_mitigation_policy_func =
87 reinterpret_cast<GetProcessMitigationPolicyType>(GetProcAddress(
88 GetModuleHandle(L"kernel32.dll"), "GetProcessMitigationPolicy"));
89
90 if (!get_process_mitigation_policy_func)
91 return false;
92
93 PROCESS_MITIGATION_SYSTEM_CALL_DISABLE_POLICY policy = {};
94 if (get_process_mitigation_policy_func(GetCurrentProcess(),
95 ProcessSystemCallDisablePolicy,
96 &policy, sizeof(policy))) {
97 return policy.DisallowWin32kSystemCalls != 0;
98 }
99
100 return false;
101 }
102
103 const bool value_;
104
105 DISALLOW_COPY_AND_ASSIGN(LazyIsUser32AndGdi32Available);
106 };
107
108 // Returns the current platform role. We use the PowerDeterminePlatformRoleEx 69 // Returns the current platform role. We use the PowerDeterminePlatformRoleEx
109 // API for that. 70 // API for that.
110 POWER_PLATFORM_ROLE GetPlatformRole() { 71 POWER_PLATFORM_ROLE GetPlatformRole() {
111 return PowerDeterminePlatformRoleEx(POWER_PLATFORM_ROLE_V2); 72 return PowerDeterminePlatformRoleEx(POWER_PLATFORM_ROLE_V2);
112 } 73 }
113 74
114 } // namespace 75 } // namespace
115 76
116 // Uses the Windows 10 WRL API's to query the current system state. The API's 77 // Uses the Windows 10 WRL API's to query the current system state. The API's
117 // we are using in the function below are supported in Win32 apps as per msdn. 78 // we are using in the function below are supported in Win32 apps as per msdn.
(...skipping 415 matching lines...) Expand 10 before | Expand all | Expand 10 after
533 } 494 }
534 495
535 return g_domain_state == ENROLLED; 496 return g_domain_state == ENROLLED;
536 } 497 }
537 498
538 void SetDomainStateForTesting(bool state) { 499 void SetDomainStateForTesting(bool state) {
539 g_domain_state = state ? ENROLLED : NOT_ENROLLED; 500 g_domain_state = state ? ENROLLED : NOT_ENROLLED;
540 } 501 }
541 502
542 bool IsUser32AndGdi32Available() { 503 bool IsUser32AndGdi32Available() {
543 static base::LazyInstance<LazyIsUser32AndGdi32Available>::Leaky available = 504 static auto is_user32_and_gdi32_available = []() {
544 LAZY_INSTANCE_INITIALIZER; 505 // If win32k syscalls aren't disabled, then user32 and gdi32 are available.
545 return available.Get().value(); 506
507 // Can't disable win32k prior to windows 8.
508 if (base::win::GetVersion() < base::win::VERSION_WIN8)
509 return true;
510
511 typedef decltype(
512 GetProcessMitigationPolicy)* GetProcessMitigationPolicyType;
513 GetProcessMitigationPolicyType get_process_mitigation_policy_func =
514 reinterpret_cast<GetProcessMitigationPolicyType>(GetProcAddress(
515 GetModuleHandle(L"kernel32.dll"), "GetProcessMitigationPolicy"));
516
517 if (!get_process_mitigation_policy_func)
518 return true;
519
520 PROCESS_MITIGATION_SYSTEM_CALL_DISABLE_POLICY policy = {};
521 if (get_process_mitigation_policy_func(GetCurrentProcess(),
522 ProcessSystemCallDisablePolicy,
523 &policy, sizeof(policy))) {
524 return policy.DisallowWin32kSystemCalls == 0;
525 }
526
527 return true;
528 }();
529 return is_user32_and_gdi32_available;
546 } 530 }
547 531
548 bool GetLoadedModulesSnapshot(HANDLE process, std::vector<HMODULE>* snapshot) { 532 bool GetLoadedModulesSnapshot(HANDLE process, std::vector<HMODULE>* snapshot) {
549 DCHECK(snapshot); 533 DCHECK(snapshot);
550 DCHECK_EQ(0u, snapshot->size()); 534 DCHECK_EQ(0u, snapshot->size());
551 snapshot->resize(128); 535 snapshot->resize(128);
552 536
553 // We will retry at least once after first determining |bytes_required|. If 537 // We will retry at least once after first determining |bytes_required|. If
554 // the list of modules changes after we receive |bytes_required| we may retry 538 // the list of modules changes after we receive |bytes_required| we may retry
555 // more than once. 539 // more than once.
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
618 awareness == PROCESS_PER_MONITOR_DPI_AWARE) 602 awareness == PROCESS_PER_MONITOR_DPI_AWARE)
619 per_monitor_dpi_aware = PerMonitorDpiAware::PER_MONITOR_DPI_AWARE; 603 per_monitor_dpi_aware = PerMonitorDpiAware::PER_MONITOR_DPI_AWARE;
620 } 604 }
621 } 605 }
622 } 606 }
623 return per_monitor_dpi_aware == PerMonitorDpiAware::PER_MONITOR_DPI_AWARE; 607 return per_monitor_dpi_aware == PerMonitorDpiAware::PER_MONITOR_DPI_AWARE;
624 } 608 }
625 609
626 } // namespace win 610 } // namespace win
627 } // namespace base 611 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698