browser_policy_connector_chromeos.h revision 5c02ac1a9c1b504631c0a3d2b6e737b5d738bae1
1// Copyright 2014 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#ifndef CHROME_BROWSER_CHROMEOS_POLICY_BROWSER_POLICY_CONNECTOR_CHROMEOS_H_ 6#define CHROME_BROWSER_CHROMEOS_POLICY_BROWSER_POLICY_CONNECTOR_CHROMEOS_H_ 7 8#include <string> 9 10#include "base/basictypes.h" 11#include "base/memory/ref_counted.h" 12#include "base/memory/scoped_ptr.h" 13#include "base/memory/weak_ptr.h" 14#include "chrome/browser/policy/chrome_browser_policy_connector.h" 15#include "components/policy/core/common/cloud/cloud_policy_constants.h" 16 17class PrefRegistrySimple; 18class PrefService; 19 20namespace net { 21class URLRequestContextGetter; 22} 23 24namespace policy { 25 26class AppPackUpdater; 27class DeviceCloudPolicyManagerChromeOS; 28class DeviceLocalAccountPolicyService; 29class DeviceManagementService; 30class EnterpriseInstallAttributes; 31class NetworkConfigurationUpdater; 32class ProxyPolicyProvider; 33 34// Extends ChromeBrowserPolicyConnector with the setup specific to ChromeOS. 35class BrowserPolicyConnectorChromeOS : public ChromeBrowserPolicyConnector { 36 public: 37 BrowserPolicyConnectorChromeOS(); 38 39 virtual ~BrowserPolicyConnectorChromeOS(); 40 41 virtual void Init( 42 PrefService* local_state, 43 scoped_refptr<net::URLRequestContextGetter> request_context) OVERRIDE; 44 45 virtual void Shutdown() OVERRIDE; 46 47 // Returns true if this device is managed by an enterprise (as opposed to 48 // a local owner). 49 bool IsEnterpriseManaged(); 50 51 // Returns the enterprise domain if device is managed. 52 std::string GetEnterpriseDomain(); 53 54 // Returns the device mode. For ChromeOS this function will return the mode 55 // stored in the lockbox, or DEVICE_MODE_CONSUMER if the lockbox has been 56 // locked empty, or DEVICE_MODE_UNKNOWN if the device has not been owned yet. 57 // For other OSes the function will always return DEVICE_MODE_CONSUMER. 58 DeviceMode GetDeviceMode(); 59 60 // Works out the user affiliation by checking the given |user_name| against 61 // the installation attributes. 62 UserAffiliation GetUserAffiliation(const std::string& user_name); 63 64 AppPackUpdater* GetAppPackUpdater(); 65 66 DeviceCloudPolicyManagerChromeOS* GetDeviceCloudPolicyManager() { 67 return device_cloud_policy_manager_; 68 } 69 70 DeviceLocalAccountPolicyService* GetDeviceLocalAccountPolicyService() { 71 return device_local_account_policy_service_.get(); 72 } 73 74 EnterpriseInstallAttributes* GetInstallAttributes() { 75 return install_attributes_.get(); 76 } 77 78 // The browser-global PolicyService is created before Profiles are ready, to 79 // provide managed values for the local state PrefService. It includes a 80 // policy provider that forwards policies from a delegate policy provider. 81 // This call can be used to set the user policy provider as that delegate 82 // once the Profile is ready, so that user policies can also affect local 83 // state preferences. 84 // Only one user policy provider can be set as a delegate at a time, and any 85 // previously set delegate is removed. Passing NULL removes the current 86 // delegate, if there is one. 87 void SetUserPolicyDelegate(ConfigurationPolicyProvider* user_policy_provider); 88 89 // Returns the device management service for consumer management. 90 DeviceManagementService* consumer_device_management_service() const { 91 return consumer_device_management_service_.get(); 92 } 93 94 // Sets the install attributes for testing. Must be called before the browser 95 // is created. RemoveInstallAttributesForTesting must be called after the test 96 // to free the attributes. 97 static void SetInstallAttributesForTesting( 98 EnterpriseInstallAttributes* attributes); 99 static void RemoveInstallAttributesForTesting(); 100 101 // Registers device refresh rate pref. 102 static void RegisterPrefs(PrefRegistrySimple* registry); 103 104 private: 105 // Set the timezone as soon as the policies are available. 106 void SetTimezoneIfPolicyAvailable(); 107 108 // Components of the device cloud policy implementation. 109 scoped_ptr<EnterpriseInstallAttributes> install_attributes_; 110 DeviceCloudPolicyManagerChromeOS* device_cloud_policy_manager_; 111 scoped_ptr<DeviceLocalAccountPolicyService> 112 device_local_account_policy_service_; 113 114 // This policy provider is used on Chrome OS to feed user policy into the 115 // global PolicyService instance. This works by installing the cloud policy 116 // provider of the primary profile as the delegate of the ProxyPolicyProvider, 117 // after login. 118 // The provider is owned by the base class; this field is just a typed weak 119 // pointer to get to the ProxyPolicyProvider at SetUserPolicyDelegate(). 120 ProxyPolicyProvider* global_user_cloud_policy_provider_; 121 122 scoped_ptr<AppPackUpdater> app_pack_updater_; 123 scoped_ptr<NetworkConfigurationUpdater> network_configuration_updater_; 124 125 scoped_ptr<DeviceManagementService> consumer_device_management_service_; 126 127 base::WeakPtrFactory<BrowserPolicyConnectorChromeOS> weak_ptr_factory_; 128 129 DISALLOW_COPY_AND_ASSIGN(BrowserPolicyConnectorChromeOS); 130}; 131 132} // namespace policy 133 134#endif // CHROME_BROWSER_CHROMEOS_POLICY_BROWSER_POLICY_CONNECTOR_CHROMEOS_H_ 135