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 | |
Thiemo Nagel
2015/09/22 15:32:24
Please remove blank line.
peletskyi
2015/09/22 16:08:42
Done.
| |
16 namespace extensions { | 17 namespace extensions { |
17 | 18 |
18 namespace { | 19 namespace { |
19 | 20 |
20 // Checks for the current browser context if the user is affiliated and the | 21 // Checks for the current browser context if the user is affiliated. |
21 // device is enterprise managed. | |
22 bool IsPermittedToGetDeviceId(content::BrowserContext* context) { | 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 = | 23 const user_manager::User* user = |
27 chromeos::ProfileHelper::Get()->GetUserByProfile( | 24 chromeos::ProfileHelper::Get()->GetUserByProfile( |
28 Profile::FromBrowserContext(context)); | 25 Profile::FromBrowserContext(context)); |
29 | 26 return user->is_affiliated(); |
30 return connector->IsEnterpriseManaged() && | |
31 connector->GetUserAffiliation(user->email()) == | |
32 policy::USER_AFFILIATION_MANAGED; | |
33 } | 27 } |
34 | 28 |
35 // Returns the directory device id for the permitted extensions or an empty | 29 // Returns the directory device id for the permitted extensions or an empty |
36 // string. | 30 // string. |
37 std::string GetDirectoryDeviceId(content::BrowserContext* context) { | 31 std::string GetDirectoryDeviceId(content::BrowserContext* context) { |
38 return IsPermittedToGetDeviceId(context) | 32 return IsPermittedToGetDeviceId(context) |
39 ? g_browser_process->platform_part() | 33 ? g_browser_process->platform_part() |
40 ->browser_policy_connector_chromeos() | 34 ->browser_policy_connector_chromeos() |
41 ->GetDirectoryApiID() | 35 ->GetDirectoryApiID() |
42 : std::string(); | 36 : std::string(); |
43 } | 37 } |
44 | 38 |
45 } // namespace | 39 } // namespace |
46 | 40 |
47 EnterpriseDeviceAttributesGetDirectoryDeviceIdFunction:: | 41 EnterpriseDeviceAttributesGetDirectoryDeviceIdFunction:: |
48 EnterpriseDeviceAttributesGetDirectoryDeviceIdFunction() {} | 42 EnterpriseDeviceAttributesGetDirectoryDeviceIdFunction() {} |
49 | 43 |
50 EnterpriseDeviceAttributesGetDirectoryDeviceIdFunction:: | 44 EnterpriseDeviceAttributesGetDirectoryDeviceIdFunction:: |
51 ~EnterpriseDeviceAttributesGetDirectoryDeviceIdFunction() {} | 45 ~EnterpriseDeviceAttributesGetDirectoryDeviceIdFunction() {} |
52 | 46 |
53 ExtensionFunction::ResponseAction | 47 ExtensionFunction::ResponseAction |
54 EnterpriseDeviceAttributesGetDirectoryDeviceIdFunction::Run() { | 48 EnterpriseDeviceAttributesGetDirectoryDeviceIdFunction::Run() { |
55 const std::string device_id = GetDirectoryDeviceId(browser_context()); | 49 const std::string device_id = GetDirectoryDeviceId(browser_context()); |
56 return RespondNow(ArgumentList( | 50 return RespondNow(ArgumentList( |
57 api::enterprise_device_attributes::GetDirectoryDeviceId::Results::Create( | 51 api::enterprise_device_attributes::GetDirectoryDeviceId::Results::Create( |
58 device_id))); | 52 device_id))); |
59 } | 53 } |
60 | 54 |
61 } // namespace extensions | 55 } // namespace extensions |
OLD | NEW |