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