OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/browser/extensions/api/enterprise_device_attributes/enterprise_
device_attributes_api.h" |
| 6 |
| 7 #include "base/values.h" |
| 8 #include "chrome/browser/app_mode/app_mode_utils.h" |
| 9 #include "chrome/browser/browser_process.h" |
| 10 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h" |
| 11 #include "chrome/browser/chromeos/profiles/profile_helper.h" |
| 12 #include "chrome/browser/profiles/profile.h" |
| 13 #include "chrome/common/extensions/api/enterprise_device_attributes.h" |
| 14 #include "components/user_manager/user_manager.h" |
| 15 |
| 16 namespace extensions { |
| 17 |
| 18 namespace { |
| 19 |
| 20 // Checks for the current browser context if the user is affiliated and the |
| 21 // device is enterprise managed. |
| 22 bool IsPermittedToGetDeviceId(content::BrowserContext* context) { |
| 23 policy::BrowserPolicyConnectorChromeOS* connector = |
| 24 g_browser_process->platform_part()->browser_policy_connector_chromeos(); |
| 25 |
| 26 const user_manager::User* user = |
| 27 chromeos::ProfileHelper::Get()->GetUserByProfile( |
| 28 Profile::FromBrowserContext(context)); |
| 29 |
| 30 return connector->IsEnterpriseManaged() && |
| 31 connector->GetUserAffiliation(user->email()) == |
| 32 policy::USER_AFFILIATION_MANAGED; |
| 33 } |
| 34 |
| 35 // Returns the directory device id for the permitted extensions or an empty |
| 36 // string. |
| 37 std::string GetDirectoryDeviceId(content::BrowserContext* context) { |
| 38 return IsPermittedToGetDeviceId(context) |
| 39 ? g_browser_process->platform_part() |
| 40 ->browser_policy_connector_chromeos() |
| 41 ->GetDirectoryApiID() |
| 42 : std::string(); |
| 43 } |
| 44 |
| 45 } // namespace |
| 46 |
| 47 EnterpriseDeviceAttributesGetDirectoryDeviceIdFunction:: |
| 48 EnterpriseDeviceAttributesGetDirectoryDeviceIdFunction() {} |
| 49 |
| 50 EnterpriseDeviceAttributesGetDirectoryDeviceIdFunction:: |
| 51 ~EnterpriseDeviceAttributesGetDirectoryDeviceIdFunction() {} |
| 52 |
| 53 ExtensionFunction::ResponseAction |
| 54 EnterpriseDeviceAttributesGetDirectoryDeviceIdFunction::Run() { |
| 55 const std::string device_id = GetDirectoryDeviceId(browser_context()); |
| 56 return RespondNow(ArgumentList( |
| 57 api::enterprise_device_attributes::GetDirectoryDeviceId::Results::Create( |
| 58 device_id))); |
| 59 } |
| 60 |
| 61 } // namespace extensions |
OLD | NEW |