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.
5 #ifndef CHROME_BROWSER_CHROMEOS_POLICY_DEVICE_CLOUD_POLICY_MANAGER_CHROMEOS_H_
6 #define CHROME_BROWSER_CHROMEOS_POLICY_DEVICE_CLOUD_POLICY_MANAGER_CHROMEOS_H_
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 "chrome/browser/policy/cloud/cloud_policy_client.h"
18 #include "chrome/browser/policy/cloud/cloud_policy_manager.h"
19 #include "chrome/browser/policy/cloud/cloud_policy_store.h"
22 class SequencedTaskRunner;
26 namespace attestation {
27 class AttestationPolicyObserver;
31 class PrefRegistrySimple;
36 class DeviceCloudPolicyStoreChromeOS;
37 class DeviceManagementService;
38 class EnrollmentHandlerChromeOS;
39 class EnterpriseInstallAttributes;
41 // CloudPolicyManager specialization for device policy on Chrome OS. The most
42 // significant addition is support for device enrollment.
43 class DeviceCloudPolicyManagerChromeOS : public CloudPolicyManager {
45 typedef std::bitset<32> AllowedDeviceModes;
46 typedef base::Callback<void(EnrollmentStatus)> EnrollmentCallback;
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();
58 // Establishes the connection to the cloud, updating policy as necessary.
60 PrefService* local_state,
61 DeviceManagementService* device_management_service,
62 scoped_ptr<CloudPolicyClient::StatusProvider> device_status_provider);
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
68 void StartEnrollment(const std::string& auth_token,
69 bool is_auto_enrollment,
70 const AllowedDeviceModes& allowed_modes,
71 const EnrollmentCallback& callback);
73 // Cancels a pending enrollment operation, if any.
74 void CancelEnrollment();
76 // Gets/Sets the device requisition.
77 std::string GetDeviceRequisition() const;
78 void SetDeviceRequisition(const std::string& requisition);
80 // Checks whether enterprise enrollment should be a regular step during OOBE.
81 bool ShouldAutoStartEnrollment() const;
83 // Checks whether the user can cancel enrollment.
84 bool CanExitEnrollment() const;
86 // CloudPolicyManager:
87 virtual void Shutdown() OVERRIDE;
89 // CloudPolicyStore::Observer:
90 virtual void OnStoreLoaded(CloudPolicyStore* store) OVERRIDE;
92 // Pref registration helper.
93 static void RegisterPrefs(PrefRegistrySimple* registry);
95 // Returns the device serial number, or an empty string if not available.
96 static std::string GetMachineID();
98 // Returns the machine model, or an empty string if not available.
99 static std::string GetMachineModel();
101 // Returns the robot 'email address' associated with the device robot
102 // account (sometimes called a service account) associated with this device
103 // during enterprise enrollment.
104 std::string GetRobotAccountId();
107 // Creates a new CloudPolicyClient.
108 scoped_ptr<CloudPolicyClient> CreateClient();
110 // Starts policy refreshes if |store_| indicates a managed device and the
111 // necessary dependencies have been provided via Initialize().
112 void StartIfManaged();
114 // Handles completion signaled by |enrollment_handler_|.
115 void EnrollmentCompleted(const EnrollmentCallback& callback,
116 EnrollmentStatus status);
118 // Points to the same object as the base CloudPolicyManager::store(), but with
119 // actual device policy specific type.
120 scoped_ptr<DeviceCloudPolicyStoreChromeOS> device_store_;
121 scoped_refptr<base::SequencedTaskRunner> background_task_runner_;
122 EnterpriseInstallAttributes* install_attributes_;
124 DeviceManagementService* device_management_service_;
125 scoped_ptr<CloudPolicyClient::StatusProvider> device_status_provider_;
127 // PrefService instance to read the policy refresh rate from.
128 PrefService* local_state_;
130 // Non-null if there is an enrollment operation pending.
131 scoped_ptr<EnrollmentHandlerChromeOS> enrollment_handler_;
133 scoped_ptr<chromeos::attestation::AttestationPolicyObserver>
134 attestation_policy_observer_;
136 DISALLOW_COPY_AND_ASSIGN(DeviceCloudPolicyManagerChromeOS);
139 } // namespace policy
141 #endif // CHROME_BROWSER_CHROMEOS_POLICY_DEVICE_CLOUD_POLICY_MANAGER_CHROMEOS_H_