Chromium Code Reviews| Index: base/win/win_util.cc |
| diff --git a/base/win/win_util.cc b/base/win/win_util.cc |
| index a1b7f8985590dd709c89ba6cb1b579e14222e0ce..d380821c71889ee9d9f5287040395e1bd50fbff6 100644 |
| --- a/base/win/win_util.cc |
| +++ b/base/win/win_util.cc |
| @@ -10,6 +10,7 @@ |
| #include <shobjidl.h> // Must be before propkey. |
| #include <initguid.h> |
| #include <inspectable.h> |
| +#include <mdmregistration.h> |
| #include <propkey.h> |
| #include <propvarutil.h> |
| #include <psapi.h> |
| @@ -496,6 +497,39 @@ bool IsEnrolledToDomain() { |
| return g_domain_state == ENROLLED; |
| } |
| +bool IsDeviceRegisteredWithManagement() { |
| + static bool is_device_registered_with_management = []() { |
| + HMODULE mdm_dll = ::LoadLibrary(L"MDMRegistration.dll"); |
|
S. Ganesh
2017/03/01 03:04:01
I noticed here that the DLL is not being freed. In
Will Harris
2017/03/01 18:01:09
perhaps just use base::ScopedNativeLibrary here
|
| + if (!mdm_dll) |
| + return false; |
| + |
| + using IsDeviceRegisteredWithManagementFunction = |
| + decltype(&::IsDeviceRegisteredWithManagement); |
| + IsDeviceRegisteredWithManagementFunction |
| + is_device_registered_with_management_function = |
| + reinterpret_cast<IsDeviceRegisteredWithManagementFunction>( |
| + ::GetProcAddress(mdm_dll, "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; |
| +} |
| + |
| +bool IsEnterpriseManaged() { |
| + // TODO(rogerta): this function should really be: |
| + // |
| + // return IsEnrolledToDomain() || IsDeviceRegisteredWithManagement(); |
| + // |
| + // However, for now it is decided to collect some UMA metrics about |
| + // IsDeviceRegisteredWithMdm() before changing chrome's behavior. |
| + return IsEnrolledToDomain(); |
| +} |
| + |
| void SetDomainStateForTesting(bool state) { |
| g_domain_state = state ? ENROLLED : NOT_ENROLLED; |
| } |