device_cloud_policy_manager_chromeos.h revision d0247b1b59f9c528cb6df88b4f2b9afaf80d181e
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 "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"
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  DeviceCloudPolicyManagerChromeOS(
50      scoped_ptr<DeviceCloudPolicyStoreChromeOS> store,
51      const scoped_refptr<base::SequencedTaskRunner>& task_runner,
52      EnterpriseInstallAttributes* install_attributes);
53  virtual ~DeviceCloudPolicyManagerChromeOS();
54
55  // Establishes the connection to the cloud, updating policy as necessary.
56  void Connect(
57      PrefService* local_state,
58      DeviceManagementService* device_management_service,
59      scoped_ptr<CloudPolicyClient::StatusProvider> device_status_provider);
60
61  // Starts enrollment or re-enrollment. Once the enrollment process completes,
62  // |callback| is invoked and gets passed the status of the operation.
63  // |allowed_modes| specifies acceptable DEVICE_MODE_* constants for
64  // enrollment.
65  void StartEnrollment(const std::string& auth_token,
66                       bool is_auto_enrollment,
67                       const AllowedDeviceModes& allowed_modes,
68                       const EnrollmentCallback& callback);
69
70  // Cancels a pending enrollment operation, if any.
71  void CancelEnrollment();
72
73  // Gets/Sets the device requisition.
74  std::string GetDeviceRequisition() const;
75  void SetDeviceRequisition(const std::string& requisition);
76
77  // Checks whether enterprise enrollment should be a regular step during OOBE.
78  bool ShouldAutoStartEnrollment() const;
79
80  // Checks whether the user can cancel enrollment.
81  bool CanExitEnrollment() const;
82
83  // CloudPolicyManager:
84  virtual void Shutdown() OVERRIDE;
85
86  // CloudPolicyStore::Observer:
87  virtual void OnStoreLoaded(CloudPolicyStore* store) OVERRIDE;
88
89  // Pref registration helper.
90  static void RegisterPrefs(PrefRegistrySimple* registry);
91
92  // Returns the device serial number, or an empty string if not available.
93  static std::string GetMachineID();
94
95  // Returns the machine model, or an empty string if not available.
96  static std::string GetMachineModel();
97
98  // Returns the robot 'email address' associated with the device robot
99  // account (sometimes called a service account) associated with this device
100  // during enterprise enrollment.
101  std::string GetRobotAccountId();
102
103 private:
104  // Creates a new CloudPolicyClient.
105  scoped_ptr<CloudPolicyClient> CreateClient();
106
107  // Starts policy refreshes if |store_| indicates a managed device and the
108  // necessary dependencies have been provided via Initialize().
109  void StartIfManaged();
110
111  // Handles completion signaled by |enrollment_handler_|.
112  void EnrollmentCompleted(const EnrollmentCallback& callback,
113                           EnrollmentStatus status);
114
115  // Points to the same object as the base CloudPolicyManager::store(), but with
116  // actual device policy specific type.
117  scoped_ptr<DeviceCloudPolicyStoreChromeOS> device_store_;
118  EnterpriseInstallAttributes* install_attributes_;
119
120  DeviceManagementService* device_management_service_;
121  scoped_ptr<CloudPolicyClient::StatusProvider> device_status_provider_;
122
123  // PrefService instance to read the policy refresh rate from.
124  PrefService* local_state_;
125
126  // Non-null if there is an enrollment operation pending.
127  scoped_ptr<EnrollmentHandlerChromeOS> enrollment_handler_;
128
129  scoped_ptr<chromeos::attestation::AttestationPolicyObserver>
130      attestation_policy_observer_;
131
132  DISALLOW_COPY_AND_ASSIGN(DeviceCloudPolicyManagerChromeOS);
133};
134
135}  // namespace policy
136
137#endif  // CHROME_BROWSER_CHROMEOS_POLICY_DEVICE_CLOUD_POLICY_MANAGER_CHROMEOS_H_
138