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

Unified Diff: chrome/browser/extensions/api/enterprise_device_attributes/enterprise_device_attributes_api.cc

Issue 1240283002: Implementation of the device attributes API. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@extension_api
Patch Set: Fixed build. Created 5 years, 4 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: chrome/browser/extensions/api/enterprise_device_attributes/enterprise_device_attributes_api.cc
diff --git a/chrome/browser/extensions/api/enterprise_device_attributes/enterprise_device_attributes_api.cc b/chrome/browser/extensions/api/enterprise_device_attributes/enterprise_device_attributes_api.cc
new file mode 100644
index 0000000000000000000000000000000000000000..fe3bc1b2ab637f05a8276f74dedb83222245bf53
--- /dev/null
+++ b/chrome/browser/extensions/api/enterprise_device_attributes/enterprise_device_attributes_api.cc
@@ -0,0 +1,61 @@
+// Copyright (c) 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/extensions/api/enterprise_device_attributes/enterprise_device_attributes_api.h"
+
+#include "base/values.h"
+#include "chrome/browser/app_mode/app_mode_utils.h"
+#include "chrome/browser/browser_process.h"
+#include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h"
+#include "chrome/browser/chromeos/profiles/profile_helper.h"
+#include "chrome/browser/profiles/profile.h"
+#include "chrome/common/extensions/api/enterprise_device_attributes.h"
+#include "components/user_manager/user_manager.h"
+
+namespace extensions {
+
+namespace {
+
+// Checks for the current browser context if the user is affiliated and the
+// device is enterprise managed.
+bool IsPermittedToGetDeviceId(content::BrowserContext* context) {
+ policy::BrowserPolicyConnectorChromeOS* connector =
+ g_browser_process->platform_part()->browser_policy_connector_chromeos();
+
+ const user_manager::User* user =
+ chromeos::ProfileHelper::Get()->GetUserByProfile(
+ Profile::FromBrowserContext(context));
+
+ return connector->IsEnterpriseManaged() &&
+ connector->GetUserAffiliation(user->email()) ==
+ policy::USER_AFFILIATION_MANAGED;
+}
+
+// Returns the directory device id for the permitted extensions or an empty
+// string.
+std::string GetDirectoryDeviceId(content::BrowserContext* context) {
+ return IsPermittedToGetDeviceId(context)
+ ? g_browser_process->platform_part()
+ ->browser_policy_connector_chromeos()
+ ->GetDirectoryApiID()
+ : std::string();
+}
+
+} // namespace
+
+EnterpriseDeviceAttributesGetDirectoryDeviceIdFunction::
+ EnterpriseDeviceAttributesGetDirectoryDeviceIdFunction() {}
+
+EnterpriseDeviceAttributesGetDirectoryDeviceIdFunction::
+ ~EnterpriseDeviceAttributesGetDirectoryDeviceIdFunction() {}
+
+ExtensionFunction::ResponseAction
+EnterpriseDeviceAttributesGetDirectoryDeviceIdFunction::Run() {
+ const std::string device_id = GetDirectoryDeviceId(browser_context());
+ return RespondNow(ArgumentList(
+ api::enterprise_device_attributes::GetDirectoryDeviceId::Results::Create(
+ device_id)));
+}
+
+} // namespace extensions

Powered by Google App Engine
This is Rietveld 408576698