diff options
author | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2018-10-24 11:30:15 +0200 |
---|---|---|
committer | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2018-10-30 12:56:19 +0000 |
commit | 6036726eb981b6c4b42047513b9d3f4ac865daac (patch) | |
tree | 673593e70678e7789766d1f732eb51f613a2703b /chromium/base/win/win_util.cc | |
parent | 466052c4e7c052268fd931888cd58961da94c586 (diff) |
BASELINE: Update Chromium to 70.0.3538.78
Change-Id: Ie634710bf039e26c1957f4ae45e101bd4c434ae7
Reviewed-by: Michael BrĂ¼ning <michael.bruning@qt.io>
Diffstat (limited to 'chromium/base/win/win_util.cc')
-rw-r--r-- | chromium/base/win/win_util.cc | 94 |
1 files changed, 54 insertions, 40 deletions
diff --git a/chromium/base/win/win_util.cc b/chromium/base/win/win_util.cc index 01b75441168..7f9cc50a3f4 100644 --- a/chromium/base/win/win_util.cc +++ b/chromium/base/win/win_util.cc @@ -14,13 +14,11 @@ #include <mdmregistration.h> #include <objbase.h> #include <propkey.h> -#include <propvarutil.h> #include <psapi.h> #include <roapi.h> #include <sddl.h> #include <setupapi.h> #include <shellscalingapi.h> -#include <shlwapi.h> #include <signal.h> #include <stddef.h> #include <stdlib.h> @@ -45,11 +43,13 @@ #include "base/strings/utf_string_conversions.h" #include "base/threading/thread_restrictions.h" #include "base/win/core_winrt_util.h" +#include "base/win/propvarutil.h" #include "base/win/registry.h" #include "base/win/scoped_co_mem.h" #include "base/win/scoped_handle.h" #include "base/win/scoped_hstring.h" #include "base/win/scoped_propvariant.h" +#include "base/win/shlwapi.h" #include "base/win/win_client_metrics.h" #include "base/win/windows_version.h" @@ -121,6 +121,36 @@ bool SetProcessDpiAwarenessWrapper(PROCESS_DPI_AWARENESS value) { return false; } +bool* GetDomainEnrollmentStateStorage() { + static bool state = IsOS(OS_DOMAINMEMBER); + return &state; +} + +bool* GetRegisteredWithManagementStateStorage() { + static bool state = []() { + ScopedNativeLibrary library( + FilePath(FILE_PATH_LITERAL("MDMRegistration.dll"))); + if (!library.is_valid()) + return false; + + using IsDeviceRegisteredWithManagementFunction = + decltype(&::IsDeviceRegisteredWithManagement); + IsDeviceRegisteredWithManagementFunction + is_device_registered_with_management_function = + reinterpret_cast<IsDeviceRegisteredWithManagementFunction>( + library.GetFunctionPointer("IsDeviceRegisteredWithManagement")); + if (!is_device_registered_with_management_function) + return false; + + BOOL is_managed = FALSE; + HRESULT hr = + is_device_registered_with_management_function(&is_managed, 0, nullptr); + return SUCCEEDED(hr) && is_managed; + }(); + + return &state; +} + } // namespace // Uses the Windows 10 WRL API's to query the current system state. The API's @@ -529,44 +559,12 @@ bool IsDeviceUsedAsATablet(std::string* reason) { return is_tablet; } -enum DomainEnrollmentState {UNKNOWN = -1, NOT_ENROLLED, ENROLLED}; -static volatile long int g_domain_state = UNKNOWN; - bool IsEnrolledToDomain() { - // Doesn't make any sense to retry inside a user session because joining a - // domain will only kick in on a restart. - if (g_domain_state == UNKNOWN) { - ::InterlockedCompareExchange(&g_domain_state, - IsOS(OS_DOMAINMEMBER) ? - ENROLLED : NOT_ENROLLED, - UNKNOWN); - } - - return g_domain_state == ENROLLED; + return *GetDomainEnrollmentStateStorage(); } bool IsDeviceRegisteredWithManagement() { - static bool is_device_registered_with_management = []() { - ScopedNativeLibrary library( - FilePath(FILE_PATH_LITERAL("MDMRegistration.dll"))); - if (!library.is_valid()) - return false; - - using IsDeviceRegisteredWithManagementFunction = - decltype(&::IsDeviceRegisteredWithManagement); - IsDeviceRegisteredWithManagementFunction - is_device_registered_with_management_function = - reinterpret_cast<IsDeviceRegisteredWithManagementFunction>( - library.GetFunctionPointer("IsDeviceRegisteredWithManagement")); - if (!is_device_registered_with_management_function) - return false; - - BOOL is_managed = false; - HRESULT hr = - is_device_registered_with_management_function(&is_managed, 0, nullptr); - return SUCCEEDED(hr) && is_managed; - }(); - return is_device_registered_with_management; + return *GetRegisteredWithManagementStateStorage(); } bool IsEnterpriseManaged() { @@ -579,10 +577,6 @@ bool IsEnterpriseManaged() { return IsEnrolledToDomain(); } -void SetDomainStateForTesting(bool state) { - g_domain_state = state ? ENROLLED : NOT_ENROLLED; -} - bool IsUser32AndGdi32Available() { static auto is_user32_and_gdi32_available = []() { // If win32k syscalls aren't disabled, then user32 and gdi32 are available. @@ -705,5 +699,25 @@ void EnableHighDPISupport() { } } +ScopedDomainStateForTesting::ScopedDomainStateForTesting(bool state) + : initial_state_(IsEnrolledToDomain()) { + *GetDomainEnrollmentStateStorage() = state; +} + +ScopedDomainStateForTesting::~ScopedDomainStateForTesting() { + *GetDomainEnrollmentStateStorage() = initial_state_; +} + +ScopedDeviceRegisteredWithManagementForTesting:: + ScopedDeviceRegisteredWithManagementForTesting(bool state) + : initial_state_(IsDeviceRegisteredWithManagement()) { + *GetRegisteredWithManagementStateStorage() = state; +} + +ScopedDeviceRegisteredWithManagementForTesting:: + ~ScopedDeviceRegisteredWithManagementForTesting() { + *GetRegisteredWithManagementStateStorage() = initial_state_; +} + } // namespace win } // namespace base |