device_cloud_policy_manager_chromeos.h revision 868fa2fe829687343ffae624259930155e16dbd8
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/scoped_ptr.h" 15#include "chrome/browser/chromeos/policy/enrollment_status_chromeos.h" 16#include "chrome/browser/policy/cloud/cloud_policy_client.h" 17#include "chrome/browser/policy/cloud/cloud_policy_manager.h" 18#include "chrome/browser/policy/cloud/cloud_policy_store.h" 19 20namespace chromeos { 21namespace attestation { 22class AttestationPolicyObserver; 23} 24} 25 26class PrefRegistrySimple; 27class PrefService; 28 29namespace policy { 30 31class DeviceCloudPolicyStoreChromeOS; 32class DeviceManagementService; 33class EnrollmentHandlerChromeOS; 34class EnterpriseInstallAttributes; 35 36// CloudPolicyManager specialization for device policy on Chrome OS. The most 37// significant addition is support for device enrollment. 38class DeviceCloudPolicyManagerChromeOS : public CloudPolicyManager { 39 public: 40 typedef std::bitset<32> AllowedDeviceModes; 41 typedef base::Callback<void(EnrollmentStatus)> EnrollmentCallback; 42 43 DeviceCloudPolicyManagerChromeOS( 44 scoped_ptr<DeviceCloudPolicyStoreChromeOS> store, 45 EnterpriseInstallAttributes* install_attributes); 46 virtual ~DeviceCloudPolicyManagerChromeOS(); 47 48 // Establishes the connection to the cloud, updating policy as necessary. 49 void Connect( 50 PrefService* local_state, 51 DeviceManagementService* device_management_service, 52 scoped_ptr<CloudPolicyClient::StatusProvider> device_status_provider); 53 54 // Starts enrollment or re-enrollment. Once the enrollment process completes, 55 // |callback| is invoked and gets passed the status of the operation. 56 // |allowed_modes| specifies acceptable DEVICE_MODE_* constants for 57 // enrollment. 58 void StartEnrollment(const std::string& auth_token, 59 bool is_auto_enrollment, 60 const AllowedDeviceModes& allowed_modes, 61 const EnrollmentCallback& callback); 62 63 // Cancels a pending enrollment operation, if any. 64 void CancelEnrollment(); 65 66 // Gets/Sets the device requisition. 67 std::string GetDeviceRequisition() const; 68 void SetDeviceRequisition(const std::string& requisition); 69 70 // Checks whether enterprise enrollment should be a regular step during OOBE. 71 bool ShouldAutoStartEnrollment() const; 72 73 // Checks whether the user can cancel enrollment. 74 bool CanExitEnrollment() const; 75 76 // CloudPolicyManager: 77 virtual void Shutdown() OVERRIDE; 78 79 // CloudPolicyStore::Observer: 80 virtual void OnStoreLoaded(CloudPolicyStore* store) OVERRIDE; 81 82 // Pref registration helper. 83 static void RegisterPrefs(PrefRegistrySimple* registry); 84 85 // Returns the device serial number, or an empty string if not available. 86 static std::string GetMachineID(); 87 88 // Returns the machine model, or an empty string if not available. 89 static std::string GetMachineModel(); 90 91 private: 92 // Creates a new CloudPolicyClient. 93 scoped_ptr<CloudPolicyClient> CreateClient(); 94 95 // Starts policy refreshes if |store_| indicates a managed device and the 96 // necessary dependencies have been provided via Initialize(). 97 void StartIfManaged(); 98 99 // Handles completion signaled by |enrollment_handler_|. 100 void EnrollmentCompleted(const EnrollmentCallback& callback, 101 EnrollmentStatus status); 102 103 // Points to the same object as the base CloudPolicyManager::store(), but with 104 // actual device policy specific type. 105 scoped_ptr<DeviceCloudPolicyStoreChromeOS> device_store_; 106 EnterpriseInstallAttributes* install_attributes_; 107 108 DeviceManagementService* device_management_service_; 109 scoped_ptr<CloudPolicyClient::StatusProvider> device_status_provider_; 110 111 // PrefService instance to read the policy refresh rate from. 112 PrefService* local_state_; 113 114 // Non-null if there is an enrollment operation pending. 115 scoped_ptr<EnrollmentHandlerChromeOS> enrollment_handler_; 116 117 scoped_ptr<chromeos::attestation::AttestationPolicyObserver> 118 attestation_policy_observer_; 119 120 DISALLOW_COPY_AND_ASSIGN(DeviceCloudPolicyManagerChromeOS); 121}; 122 123} // namespace policy 124 125#endif // CHROME_BROWSER_CHROMEOS_POLICY_DEVICE_CLOUD_POLICY_MANAGER_CHROMEOS_H_ 126