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

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: Created 5 years, 5 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..9cf096efc5c9bebc5dc22c83ab887a0376596f71
--- /dev/null
+++ b/chrome/browser/extensions/api/enterprise_device_attributes/enterprise_device_attributes_api.cc
@@ -0,0 +1,58 @@
+// 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 "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() {
+}
+
+bool EnterpriseDeviceAttributesGetDirectoryDeviceIdFunction::RunAsync() {
+ std::string directoryDeviceId = GetDirectoryDeviceId(browser_context());
pneubeck (no reviews) 2015/07/23 12:53:21 s/directoryDeviceId/directory_device_id/ s/std::st
Polina Bondarenko 2015/07/24 16:47:58 Done, renamed to device_id.
+ scoped_ptr<base::Value> result(new base::StringValue(directoryDeviceId));
pneubeck (no reviews) 2015/07/23 12:53:21 please use the generated result wrappers. they sho
Polina Bondarenko 2015/07/24 16:47:58 Done, but the ListValue is returned now, is it ok?
+ SetResult(result.release());
+ SendResponse(true);
pneubeck (no reviews) 2015/07/23 12:53:21 once you changed to the other base class, you'll r
Polina Bondarenko 2015/07/24 16:47:58 Done.
+ return true;
+}
+
+} // namespace extensions

Powered by Google App Engine
This is Rietveld 408576698