device_cloud_policy_manager_chromeos.h revision a1401311d1ab56c4ed0a474bd38c108f75cb0cd9
1// Copyright (c) 2012 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_DEVICE_CLOUD_POLICY_MANAGER_CHROMEOS_H_ 6#define CHROME_BROWSER_CHROMEOS_POLICY_DEVICE_CLOUD_POLICY_MANAGER_CHROMEOS_H_ 7 8#include <bitset> 9#include <string> 10 11#include "base/basictypes.h" 12#include "base/callback.h" 13#include "base/compiler_specific.h" 14#include "base/memory/ref_counted.h" 15#include "base/memory/scoped_ptr.h" 16#include "chrome/browser/chromeos/policy/enrollment_status_chromeos.h" 17#include "components/policy/core/common/cloud/cloud_policy_client.h" 18#include "components/policy/core/common/cloud/cloud_policy_manager.h" 19#include "components/policy/core/common/cloud/cloud_policy_store.h" 20 21namespace base { 22class SequencedTaskRunner; 23} 24 25namespace chromeos { 26namespace attestation { 27class AttestationPolicyObserver; 28} 29} 30 31class PrefRegistrySimple; 32class PrefService; 33 34namespace policy { 35 36class DeviceCloudPolicyStoreChromeOS; 37class DeviceManagementService; 38class EnrollmentHandlerChromeOS; 39class EnterpriseInstallAttributes; 40 41// CloudPolicyManager specialization for device policy on Chrome OS. The most 42// significant addition is support for device enrollment. 43class DeviceCloudPolicyManagerChromeOS : public CloudPolicyManager { 44 public: 45 typedef std::bitset<32> AllowedDeviceModes; 46 typedef base::Callback<void(EnrollmentStatus)> EnrollmentCallback; 47 48 // |task_runner| is the runner for policy refresh tasks. 49 // |background_task_runner| is used to execute long-running background tasks 50 // that may involve file I/O. 51 DeviceCloudPolicyManagerChromeOS( 52 scoped_ptr<DeviceCloudPolicyStoreChromeOS> store, 53 const scoped_refptr<base::SequencedTaskRunner>& task_runner, 54 const scoped_refptr<base::SequencedTaskRunner>& background_task_runner, 55 EnterpriseInstallAttributes* install_attributes); 56 virtual ~DeviceCloudPolicyManagerChromeOS(); 57 58 // Establishes the connection to the cloud, updating policy as necessary. 59 void Connect( 60 PrefService* local_state, 61 DeviceManagementService* device_management_service, 62 scoped_ptr<CloudPolicyClient::StatusProvider> device_status_provider); 63 64 // Starts enrollment or re-enrollment. Once the enrollment process completes, 65 // |callback| is invoked and gets passed the status of the operation. 66 // |allowed_modes| specifies acceptable DEVICE_MODE_* constants for 67 // enrollment. 68 void StartEnrollment(const std::string& auth_token, 69 bool is_auto_enrollment, 70 const AllowedDeviceModes& allowed_modes, 71 const EnrollmentCallback& callback); 72 73 // Cancels a pending enrollment operation, if any. 74 void CancelEnrollment(); 75 76 // Gets/Sets the device requisition. 77 std::string GetDeviceRequisition() const; 78 void SetDeviceRequisition(const std::string& requisition); 79 80 // Checks whether enterprise enrollment should be a regular step during OOBE. 81 bool ShouldAutoStartEnrollment() const; 82 83 // Checks whether the user can cancel enrollment. 84 bool CanExitEnrollment() const; 85 86 // CloudPolicyManager: 87 virtual void Shutdown() OVERRIDE; 88 89 // CloudPolicyStore::Observer: 90 virtual void OnStoreLoaded(CloudPolicyStore* store) OVERRIDE; 91 92 // Pref registration helper. 93 static void RegisterPrefs(PrefRegistrySimple* registry); 94 95 // Returns the device serial number, or an empty string if not available. 96 static std::string GetMachineID(); 97 98 // Returns the machine model, or an empty string if not available. 99 static std::string GetMachineModel(); 100 101 // Returns the stable device state key. 102 static std::string GetDeviceStateKey(); 103 104 // Returns the robot 'email address' associated with the device robot 105 // account (sometimes called a service account) associated with this device 106 // during enterprise enrollment. 107 std::string GetRobotAccountId(); 108 109 private: 110 // Creates a new CloudPolicyClient. 111 scoped_ptr<CloudPolicyClient> CreateClient(); 112 113 // Starts policy refreshes if |store_| indicates a managed device and the 114 // necessary dependencies have been provided via Initialize(). 115 void StartIfManaged(); 116 117 // Handles completion signaled by |enrollment_handler_|. 118 void EnrollmentCompleted(const EnrollmentCallback& callback, 119 EnrollmentStatus status); 120 121 // Starts the connection via |client_to_connect|. 122 void StartConnection(scoped_ptr<CloudPolicyClient> client_to_connect); 123 124 // Initializes requisition settings at OOBE with values from VPD. 125 void InitalizeRequisition(); 126 127 // Gets the device restore mode as stored in |local_state_|. 128 std::string GetRestoreMode() const; 129 130 // Points to the same object as the base CloudPolicyManager::store(), but with 131 // actual device policy specific type. 132 scoped_ptr<DeviceCloudPolicyStoreChromeOS> device_store_; 133 scoped_refptr<base::SequencedTaskRunner> background_task_runner_; 134 EnterpriseInstallAttributes* install_attributes_; 135 136 DeviceManagementService* device_management_service_; 137 scoped_ptr<CloudPolicyClient::StatusProvider> device_status_provider_; 138 139 // PrefService instance to read the policy refresh rate from. 140 PrefService* local_state_; 141 142 // Non-null if there is an enrollment operation pending. 143 scoped_ptr<EnrollmentHandlerChromeOS> enrollment_handler_; 144 145 scoped_ptr<chromeos::attestation::AttestationPolicyObserver> 146 attestation_policy_observer_; 147 148 DISALLOW_COPY_AND_ASSIGN(DeviceCloudPolicyManagerChromeOS); 149}; 150 151} // namespace policy 152 153#endif // CHROME_BROWSER_CHROMEOS_POLICY_DEVICE_CLOUD_POLICY_MANAGER_CHROMEOS_H_ 154