browser_policy_connector_chromeos.h revision 6e8cce623b6e4fe0c9e4af605d675dd9d0338c38
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 ConsumerManagementService; 28class DeviceCloudPolicyInitializer; 29class DeviceCloudPolicyInvalidator; 30class DeviceCloudPolicyManagerChromeOS; 31class DeviceLocalAccountPolicyService; 32class DeviceManagementService; 33class EnterpriseInstallAttributes; 34class NetworkConfigurationUpdater; 35class ProxyPolicyProvider; 36class ServerBackedStateKeysBroker; 37 38// Extends ChromeBrowserPolicyConnector with the setup specific to ChromeOS. 39class BrowserPolicyConnectorChromeOS : public ChromeBrowserPolicyConnector { 40 public: 41 BrowserPolicyConnectorChromeOS(); 42 43 virtual ~BrowserPolicyConnectorChromeOS(); 44 45 virtual void Init( 46 PrefService* local_state, 47 scoped_refptr<net::URLRequestContextGetter> request_context) OVERRIDE; 48 49 // Destroys the |device_cloud_policy_invalidator_|. This cannot wait until 50 // Shutdown() because that method is only called during 51 // BrowserProcessImpl::StartTearDown() but the invalidator may be observing 52 // the global DeviceOAuth2TokenService that is destroyed earlier by 53 // ChromeBrowserMainPartsChromeos::PostMainMessageLoopRun(). 54 void ShutdownInvalidator(); 55 56 virtual void Shutdown() OVERRIDE; 57 58 // Returns true if this device is managed by an enterprise (as opposed to 59 // a local owner). 60 bool IsEnterpriseManaged(); 61 62 // Returns the enterprise domain if device is managed. 63 std::string GetEnterpriseDomain(); 64 65 // Returns the device mode. For ChromeOS this function will return the mode 66 // stored in the lockbox, or DEVICE_MODE_CONSUMER if the lockbox has been 67 // locked empty, or DEVICE_MODE_UNKNOWN if the device has not been owned yet. 68 // For other OSes the function will always return DEVICE_MODE_CONSUMER. 69 DeviceMode GetDeviceMode(); 70 71 // Works out the user affiliation by checking the given |user_name| against 72 // the installation attributes. 73 UserAffiliation GetUserAffiliation(const std::string& user_name); 74 75 AppPackUpdater* GetAppPackUpdater(); 76 77 DeviceCloudPolicyManagerChromeOS* GetDeviceCloudPolicyManager() { 78 return device_cloud_policy_manager_; 79 } 80 81 DeviceCloudPolicyInitializer* GetDeviceCloudPolicyInitializer() { 82 return device_cloud_policy_initializer_.get(); 83 } 84 85 DeviceLocalAccountPolicyService* GetDeviceLocalAccountPolicyService() { 86 return device_local_account_policy_service_.get(); 87 } 88 89 EnterpriseInstallAttributes* GetInstallAttributes() { 90 return install_attributes_.get(); 91 } 92 93 ServerBackedStateKeysBroker* GetStateKeysBroker() { 94 return state_keys_broker_.get(); 95 } 96 97 // The browser-global PolicyService is created before Profiles are ready, to 98 // provide managed values for the local state PrefService. It includes a 99 // policy provider that forwards policies from a delegate policy provider. 100 // This call can be used to set the user policy provider as that delegate 101 // once the Profile is ready, so that user policies can also affect local 102 // state preferences. 103 // Only one user policy provider can be set as a delegate at a time, and any 104 // previously set delegate is removed. Passing NULL removes the current 105 // delegate, if there is one. 106 void SetUserPolicyDelegate(ConfigurationPolicyProvider* user_policy_provider); 107 108 // Returns the device management service for consumer management. 109 DeviceManagementService* GetDeviceManagementServiceForConsumer() const { 110 return consumer_device_management_service_.get(); 111 } 112 113 ConsumerManagementService* GetConsumerManagementService() const { 114 return consumer_management_service_.get(); 115 } 116 117 // Sets the install attributes for testing. Must be called before the browser 118 // is created. RemoveInstallAttributesForTesting must be called after the test 119 // to free the attributes. 120 static void SetInstallAttributesForTesting( 121 EnterpriseInstallAttributes* attributes); 122 static void RemoveInstallAttributesForTesting(); 123 124 // Registers device refresh rate pref. 125 static void RegisterPrefs(PrefRegistrySimple* registry); 126 127 private: 128 // Set the timezone as soon as the policies are available. 129 void SetTimezoneIfPolicyAvailable(); 130 131 void OnDeviceCloudPolicyManagerConnected(); 132 133 // Components of the device cloud policy implementation. 134 scoped_ptr<ServerBackedStateKeysBroker> state_keys_broker_; 135 scoped_ptr<EnterpriseInstallAttributes> install_attributes_; 136 DeviceCloudPolicyManagerChromeOS* device_cloud_policy_manager_; 137 scoped_ptr<DeviceCloudPolicyInitializer> device_cloud_policy_initializer_; 138 scoped_ptr<DeviceLocalAccountPolicyService> 139 device_local_account_policy_service_; 140 scoped_ptr<DeviceCloudPolicyInvalidator> device_cloud_policy_invalidator_; 141 142 // This policy provider is used on Chrome OS to feed user policy into the 143 // global PolicyService instance. This works by installing the cloud policy 144 // provider of the primary profile as the delegate of the ProxyPolicyProvider, 145 // after login. 146 // The provider is owned by the base class; this field is just a typed weak 147 // pointer to get to the ProxyPolicyProvider at SetUserPolicyDelegate(). 148 ProxyPolicyProvider* global_user_cloud_policy_provider_; 149 150 scoped_ptr<AppPackUpdater> app_pack_updater_; 151 scoped_ptr<NetworkConfigurationUpdater> network_configuration_updater_; 152 153 scoped_ptr<DeviceManagementService> consumer_device_management_service_; 154 scoped_ptr<ConsumerManagementService> consumer_management_service_; 155 156 base::WeakPtrFactory<BrowserPolicyConnectorChromeOS> weak_ptr_factory_; 157 158 DISALLOW_COPY_AND_ASSIGN(BrowserPolicyConnectorChromeOS); 159}; 160 161} // namespace policy 162 163#endif // CHROME_BROWSER_CHROMEOS_POLICY_BROWSER_POLICY_CONNECTOR_CHROMEOS_H_ 164