Chromium Code Reviews| 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 and the |
| 21 // device is enterprise managed. | 21 // device is enterprise managed. |
| 22 bool IsPermittedToGetDeviceId(content::BrowserContext* context) { | 22 bool IsPermittedToGetDeviceId(content::BrowserContext* context) { |
| 23 policy::BrowserPolicyConnectorChromeOS* connector = | 23 policy::BrowserPolicyConnectorChromeOS* connector = |
| 24 g_browser_process->platform_part()->browser_policy_connector_chromeos(); | 24 g_browser_process->platform_part()->browser_policy_connector_chromeos(); |
| 25 | |
| 26 const user_manager::User* user = | 25 const user_manager::User* user = |
| 27 chromeos::ProfileHelper::Get()->GetUserByProfile( | 26 chromeos::ProfileHelper::Get()->GetUserByProfile( |
| 28 Profile::FromBrowserContext(context)); | 27 Profile::FromBrowserContext(context)); |
| 29 | 28 |
| 30 return connector->IsEnterpriseManaged() && | 29 return connector->IsEnterpriseManaged() && user->is_affiliated(); |
|
Andrew T Wilson (Slow)
2015/09/16 15:02:06
Why do we need to call IsEnterpriseManaged() here?
peletskyi
2015/09/21 14:17:25
From my point of view connector->IsEnterpriseManag
| |
| 31 connector->GetUserAffiliation(user->email()) == | |
| 32 policy::USER_AFFILIATION_MANAGED; | |
| 33 } | 30 } |
| 34 | 31 |
| 35 // Returns the directory device id for the permitted extensions or an empty | 32 // Returns the directory device id for the permitted extensions or an empty |
| 36 // string. | 33 // string. |
| 37 std::string GetDirectoryDeviceId(content::BrowserContext* context) { | 34 std::string GetDirectoryDeviceId(content::BrowserContext* context) { |
| 38 return IsPermittedToGetDeviceId(context) | 35 return IsPermittedToGetDeviceId(context) |
| 39 ? g_browser_process->platform_part() | 36 ? g_browser_process->platform_part() |
| 40 ->browser_policy_connector_chromeos() | 37 ->browser_policy_connector_chromeos() |
| 41 ->GetDirectoryApiID() | 38 ->GetDirectoryApiID() |
| 42 : std::string(); | 39 : std::string(); |
| 43 } | 40 } |
| 44 | 41 |
| 45 } // namespace | 42 } // namespace |
| 46 | 43 |
| 47 EnterpriseDeviceAttributesGetDirectoryDeviceIdFunction:: | 44 EnterpriseDeviceAttributesGetDirectoryDeviceIdFunction:: |
| 48 EnterpriseDeviceAttributesGetDirectoryDeviceIdFunction() {} | 45 EnterpriseDeviceAttributesGetDirectoryDeviceIdFunction() {} |
| 49 | 46 |
| 50 EnterpriseDeviceAttributesGetDirectoryDeviceIdFunction:: | 47 EnterpriseDeviceAttributesGetDirectoryDeviceIdFunction:: |
| 51 ~EnterpriseDeviceAttributesGetDirectoryDeviceIdFunction() {} | 48 ~EnterpriseDeviceAttributesGetDirectoryDeviceIdFunction() {} |
| 52 | 49 |
| 53 ExtensionFunction::ResponseAction | 50 ExtensionFunction::ResponseAction |
| 54 EnterpriseDeviceAttributesGetDirectoryDeviceIdFunction::Run() { | 51 EnterpriseDeviceAttributesGetDirectoryDeviceIdFunction::Run() { |
| 55 const std::string device_id = GetDirectoryDeviceId(browser_context()); | 52 const std::string device_id = GetDirectoryDeviceId(browser_context()); |
| 56 return RespondNow(ArgumentList( | 53 return RespondNow(ArgumentList( |
| 57 api::enterprise_device_attributes::GetDirectoryDeviceId::Results::Create( | 54 api::enterprise_device_attributes::GetDirectoryDeviceId::Results::Create( |
| 58 device_id))); | 55 device_id))); |
| 59 } | 56 } |
| 60 | 57 |
| 61 } // namespace extensions | 58 } // namespace extensions |
| OLD | NEW |