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