Chromium Code Reviews| 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 "components/user_manager/user_manager.h" | |
| 14 | |
| 15 namespace extensions { | |
| 16 | |
| 17 namespace { | |
| 18 | |
| 19 // Checks for the current browser context if the user is affiliated and the | |
| 20 // device is enterprise managed. | |
| 21 bool IsPermittedToGetDeviceId(content::BrowserContext* context) { | |
| 22 policy::BrowserPolicyConnectorChromeOS* connector = | |
| 23 g_browser_process->platform_part()->browser_policy_connector_chromeos(); | |
| 24 | |
| 25 const user_manager::User* user = chromeos::ProfileHelper::Get()-> | |
| 26 GetUserByProfile(Profile::FromBrowserContext(context)); | |
| 27 | |
| 28 return connector->IsEnterpriseManaged() && connector->GetUserAffiliation( | |
| 29 user->email()) == policy::USER_AFFILIATION_MANAGED; | |
| 30 } | |
| 31 | |
| 32 // Returns the directory device id for the permitted extensions or an empty | |
| 33 // string. | |
| 34 std::string GetDirectoryDeviceId(content::BrowserContext* context) { | |
| 35 return IsPermittedToGetDeviceId(context) ? g_browser_process-> | |
| 36 platform_part()->browser_policy_connector_chromeos()-> | |
| 37 GetDirectoryApiID() : std::string(); | |
| 38 } | |
| 39 | |
| 40 } // namespace | |
| 41 | |
| 42 EnterpriseDeviceAttributesGetDirectoryDeviceIdFunction:: | |
| 43 EnterpriseDeviceAttributesGetDirectoryDeviceIdFunction() { | |
| 44 } | |
| 45 | |
| 46 EnterpriseDeviceAttributesGetDirectoryDeviceIdFunction:: | |
| 47 ~EnterpriseDeviceAttributesGetDirectoryDeviceIdFunction() { | |
| 48 } | |
| 49 | |
| 50 bool EnterpriseDeviceAttributesGetDirectoryDeviceIdFunction::RunAsync() { | |
| 51 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.
| |
| 52 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?
| |
| 53 SetResult(result.release()); | |
| 54 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.
| |
| 55 return true; | |
| 56 } | |
| 57 | |
| 58 } // namespace extensions | |
| OLD | NEW |