device_cloud_policy_manager_chromeos.h revision 2a99a7e74a7f215066514fe81d2bfa6639d9eddd
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 20class PrefService; 21 22namespace policy { 23 24class DeviceCloudPolicyStoreChromeOS; 25class DeviceManagementService; 26class EnrollmentHandlerChromeOS; 27class EnterpriseInstallAttributes; 28 29// CloudPolicyManager specialization for device policy on Chrome OS. The most 30// significant addition is support for device enrollment. 31class DeviceCloudPolicyManagerChromeOS : public CloudPolicyManager { 32 public: 33 typedef std::bitset<32> AllowedDeviceModes; 34 typedef base::Callback<void(EnrollmentStatus)> EnrollmentCallback; 35 36 DeviceCloudPolicyManagerChromeOS( 37 scoped_ptr<DeviceCloudPolicyStoreChromeOS> store, 38 EnterpriseInstallAttributes* install_attributes); 39 virtual ~DeviceCloudPolicyManagerChromeOS(); 40 41 // Establishes the connection to the cloud, updating policy as necessary. 42 void Connect( 43 PrefService* local_state, 44 DeviceManagementService* device_management_service, 45 scoped_ptr<CloudPolicyClient::StatusProvider> device_status_provider); 46 47 // Starts enrollment or re-enrollment. Once the enrollment process completes, 48 // |callback| is invoked and gets passed the status of the operation. 49 // |allowed_modes| specifies acceptable DEVICE_MODE_* constants for 50 // enrollment. 51 void StartEnrollment(const std::string& auth_token, 52 bool is_auto_enrollment, 53 const AllowedDeviceModes& allowed_modes, 54 const EnrollmentCallback& callback); 55 56 // Cancels a pending enrollment operation, if any. 57 void CancelEnrollment(); 58 59 // CloudPolicyStore::Observer: 60 virtual void OnStoreLoaded(CloudPolicyStore* store) OVERRIDE; 61 62 // Returns the device serial number, or an empty string if not available. 63 static std::string GetMachineID(); 64 65 // Returns the machine model, or an empty string if not available. 66 static std::string GetMachineModel(); 67 68 private: 69 // Creates a new CloudPolicyClient. 70 scoped_ptr<CloudPolicyClient> CreateClient(); 71 72 // Starts policy refreshes if |store_| indicates a managed device and the 73 // necessary dependencies have been provided via Initialize(). 74 void StartIfManaged(); 75 76 // Handles completion signaled by |enrollment_handler_|. 77 void EnrollmentCompleted(const EnrollmentCallback& callback, 78 EnrollmentStatus status); 79 80 // Points to the same object as the base CloudPolicyManager::store(), but with 81 // actual device policy specific type. 82 scoped_ptr<DeviceCloudPolicyStoreChromeOS> device_store_; 83 EnterpriseInstallAttributes* install_attributes_; 84 85 DeviceManagementService* device_management_service_; 86 scoped_ptr<CloudPolicyClient::StatusProvider> device_status_provider_; 87 88 // PrefService instance to read the policy refresh rate from. 89 PrefService* local_state_; 90 91 // Non-null if there is an enrollment operation pending. 92 scoped_ptr<EnrollmentHandlerChromeOS> enrollment_handler_; 93 94 DISALLOW_COPY_AND_ASSIGN(DeviceCloudPolicyManagerChromeOS); 95}; 96 97} // namespace policy 98 99#endif // CHROME_BROWSER_CHROMEOS_POLICY_DEVICE_CLOUD_POLICY_MANAGER_CHROMEOS_H_ 100