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

Unified Diff: base/win/win_util.cc

Issue 2581353002: Use the Windows MDM API to check if the machine is being managed. (Closed)
Patch Set: Fix tests 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « base/win/win_util.h ('k') | chrome/browser/chrome_browser_main.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/win/win_util.cc
diff --git a/base/win/win_util.cc b/base/win/win_util.cc
index a1b7f8985590dd709c89ba6cb1b579e14222e0ce..c2b0869a15cab4ed88e906fd77c43594f95c1400 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,40 @@ bool IsEnrolledToDomain() {
return g_domain_state == ENROLLED;
}
+bool IsDeviceRegisteredWithManagement() {
+ static auto is_device_registered_with_management = []() {
grt (UTC plus 2) 2017/02/14 21:20:13 auto -> bool
Roger Tawa OOO till Jul 10th 2017/02/15 19:11:27 Done.
+ using IsDeviceRegisteredWithManagementFunction =
+ decltype(&::IsDeviceRegisteredWithManagement);
+
+ IsDeviceRegisteredWithManagementFunction
+ is_device_registered_with_management_function = nullptr;
+ if (!is_device_registered_with_management_function) {
grt (UTC plus 2) 2017/02/14 21:20:13 remove this check and move the definition of is_de
Roger Tawa OOO till Jul 10th 2017/02/15 19:11:27 Doh! Good catch, not sure how that line got there
+ HMODULE mdm_dll = ::LoadLibrary(L"MDMRegistration.dll");
grt (UTC plus 2) 2017/02/14 21:20:13 ? if (!mdm_dll) return false;
Roger Tawa OOO till Jul 10th 2017/02/15 19:11:27 Done.
+ 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;
}
« no previous file with comments | « base/win/win_util.h ('k') | chrome/browser/chrome_browser_main.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698