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

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 missing rename from enterprise-user to entprise-managed 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
Index: base/win/win_util.cc
diff --git a/base/win/win_util.cc b/base/win/win_util.cc
index a1b7f8985590dd709c89ba6cb1b579e14222e0ce..69a779ae363905499603398b05c276e22dd1a091 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,37 @@ bool IsEnrolledToDomain() {
return g_domain_state == ENROLLED;
}
+bool IsDeviceRegisteredWithMdm() {
+ static auto is_device_registered_with_mdm = []() {
+ using IsDeviceRegisteredWithManagementFunction =
+ decltype(&IsDeviceRegisteredWithManagement);
+
+ static IsDeviceRegisteredWithManagementFunction fn = nullptr;
grt (UTC plus 2) 2017/02/10 12:12:26 "Names should be descriptive; avoid abbreviation."
Roger Tawa OOO till Jul 10th 2017/02/13 20:30:06 Done.
+ if (!fn) {
+ HMODULE mdm_dll = ::LoadLibrary(L"MDMRegistration.dll");
grt (UTC plus 2) 2017/02/10 12:12:26 while presence of the library will almost certainl
Roger Tawa OOO till Jul 10th 2017/02/13 20:30:06 Let me double check. A larger question is whether
+ fn = reinterpret_cast<IsDeviceRegisteredWithManagementFunction>(
+ ::GetProcAddress(mdm_dll, "IsDeviceRegisteredWithManagement"));
+ if (!fn)
+ return false;
+ }
+
+ BOOL is_managed = false;
+ HRESULT hr = fn(&is_managed, 0, nullptr);
+ return SUCCEEDED(hr) && is_managed;
+ }();
+ return is_device_registered_with_mdm;
+}
+
+bool IsEnterpriseManaged() {
+ // TODO(rogerta): this function should really be:
+ //
+ // return IsEnrolledToDomain() || IsDeviceRegisteredWithMdm();
+ //
+ // However, for now it is decided to collected some UMA metrics about
grt (UTC plus 2) 2017/02/10 12:12:26 nit: "collect"
Roger Tawa OOO till Jul 10th 2017/02/13 20:30:06 Done.
+ // IsDeviceRegisteredWithMdm() before changing chrome behavior.
grt (UTC plus 2) 2017/02/10 12:12:26 nit: "Chrome's"
Roger Tawa OOO till Jul 10th 2017/02/13 20:30:06 Done.
+ return IsEnrolledToDomain();
+}
+
void SetDomainStateForTesting(bool state) {
g_domain_state = state ? ENROLLED : NOT_ENROLLED;
}

Powered by Google App Engine
This is Rietveld 408576698