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 <string>
9#include <vector>
10
11#include "base/basictypes.h"
12#include "base/compiler_specific.h"
13#include "base/memory/ref_counted.h"
14#include "base/memory/scoped_ptr.h"
15#include "chrome/browser/chromeos/policy/server_backed_state_keys_broker.h"
16#include "components/policy/core/common/cloud/cloud_policy_client.h"
17#include "components/policy/core/common/cloud/cloud_policy_manager.h"
18
19namespace base {
20class SequencedTaskRunner;
21}
22
23namespace chromeos {
24namespace attestation {
25class AttestationPolicyObserver;
26}
27}
28
29class PrefRegistrySimple;
30class PrefService;
31
32namespace policy {
33
34class DeviceCloudPolicyStoreChromeOS;
35
36// CloudPolicyManager specialization for device policy on Chrome OS.
37class DeviceCloudPolicyManagerChromeOS : public CloudPolicyManager {
38 public:
39  // |task_runner| is the runner for policy refresh tasks.
40  DeviceCloudPolicyManagerChromeOS(
41      scoped_ptr<DeviceCloudPolicyStoreChromeOS> store,
42      const scoped_refptr<base::SequencedTaskRunner>& task_runner,
43      ServerBackedStateKeysBroker* state_keys_broker);
44  virtual ~DeviceCloudPolicyManagerChromeOS();
45
46  // Initializes state keys and requisition information.
47  void Initialize(PrefService* local_state);
48
49  // TODO(davidyu): Move these two functions to a more appropriate place. See
50  // http://crbug.com/383695.
51  // Gets/Sets the device requisition.
52  std::string GetDeviceRequisition() const;
53  void SetDeviceRequisition(const std::string& requisition);
54  bool IsRemoraRequisition() const;
55  bool IsSharkRequisition() const;
56
57  // CloudPolicyManager:
58  virtual void Shutdown() OVERRIDE;
59
60  // Pref registration helper.
61  static void RegisterPrefs(PrefRegistrySimple* registry);
62
63  // Returns the device serial number, or an empty string if not available.
64  static std::string GetMachineID();
65
66  // Returns the machine model, or an empty string if not available.
67  static std::string GetMachineModel();
68
69  // Returns the robot 'email address' associated with the device robot
70  // account (sometimes called a service account) associated with this device
71  // during enterprise enrollment.
72  std::string GetRobotAccountId();
73
74  // Starts the connection via |client_to_connect|.
75  void StartConnection(scoped_ptr<CloudPolicyClient> client_to_connect,
76                       scoped_ptr<CloudPolicyClient::StatusProvider>
77                           device_status_provider);
78
79  DeviceCloudPolicyStoreChromeOS* device_store() {
80    return device_store_.get();
81  }
82
83 private:
84  // Saves the state keys received from |session_manager_client_|.
85  void OnStateKeysUpdated();
86
87  // Initializes requisition settings at OOBE with values from VPD.
88  void InitializeRequisition();
89
90  // Points to the same object as the base CloudPolicyManager::store(), but with
91  // actual device policy specific type.
92  scoped_ptr<DeviceCloudPolicyStoreChromeOS> device_store_;
93  ServerBackedStateKeysBroker* state_keys_broker_;
94
95  ServerBackedStateKeysBroker::Subscription state_keys_update_subscription_;
96
97  // PrefService instance to read the policy refresh rate from.
98  PrefService* local_state_;
99
100  scoped_ptr<chromeos::attestation::AttestationPolicyObserver>
101      attestation_policy_observer_;
102
103  // TODO(davidyu): Currently we need to keep this object alive while
104  // CloudPolicyClient is in use. We should have CPC take over the
105  // ownership of this object instead. See http://crbug.com/383696.
106  scoped_ptr<CloudPolicyClient::StatusProvider> device_status_provider_;
107
108  DISALLOW_COPY_AND_ASSIGN(DeviceCloudPolicyManagerChromeOS);
109};
110
111}  // namespace policy
112
113#endif  // CHROME_BROWSER_CHROMEOS_POLICY_DEVICE_CLOUD_POLICY_MANAGER_CHROMEOS_H_
114