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 |