Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / chrome / browser / chromeos / policy / device_cloud_policy_manager_chromeos.h
blobbc72ac1fd43185ff8a0bec56fbcd84d380813558
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_
8 #include <string>
9 #include <vector>
11 #include "base/basictypes.h"
12 #include "base/callback_forward.h"
13 #include "base/compiler_specific.h"
14 #include "base/memory/ref_counted.h"
15 #include "base/memory/scoped_ptr.h"
16 #include "base/observer_list.h"
17 #include "chrome/browser/chromeos/policy/server_backed_state_keys_broker.h"
18 #include "components/policy/core/common/cloud/cloud_policy_client.h"
19 #include "components/policy/core/common/cloud/cloud_policy_manager.h"
21 namespace base {
22 class SequencedTaskRunner;
25 namespace chromeos {
26 namespace attestation {
27 class AttestationPolicyObserver;
31 class PrefRegistrySimple;
32 class PrefService;
34 namespace policy {
36 class DeviceCloudPolicyStoreChromeOS;
37 class EnterpriseInstallAttributes;
38 class HeartbeatScheduler;
39 class StatusUploader;
40 class SystemLogUploader;
42 // CloudPolicyManager specialization for device policy on Chrome OS.
43 class DeviceCloudPolicyManagerChromeOS : public CloudPolicyManager {
44 public:
45 class Observer {
46 public:
47 // Invoked when the device cloud policy manager connects.
48 virtual void OnDeviceCloudPolicyManagerConnected() = 0;
49 // Invoked when the device cloud policy manager disconnects.
50 virtual void OnDeviceCloudPolicyManagerDisconnected() = 0;
53 using UnregisterCallback = base::Callback<void(bool)>;
55 // |task_runner| is the runner for policy refresh, heartbeat, and status
56 // upload tasks.
57 DeviceCloudPolicyManagerChromeOS(
58 scoped_ptr<DeviceCloudPolicyStoreChromeOS> store,
59 const scoped_refptr<base::SequencedTaskRunner>& task_runner,
60 ServerBackedStateKeysBroker* state_keys_broker);
61 ~DeviceCloudPolicyManagerChromeOS() override;
63 // Initializes state keys and requisition information.
64 void Initialize(PrefService* local_state);
66 void AddDeviceCloudPolicyManagerObserver(Observer* observer);
67 void RemoveDeviceCloudPolicyManagerObserver(Observer* observer);
69 // TODO(davidyu): Move these two functions to a more appropriate place. See
70 // http://crbug.com/383695.
71 // Gets/Sets the device requisition.
72 std::string GetDeviceRequisition() const;
73 void SetDeviceRequisition(const std::string& requisition);
74 bool IsRemoraRequisition() const;
75 bool IsSharkRequisition() const;
77 // CloudPolicyManager:
78 void Shutdown() override;
80 // Pref registration helper.
81 static void RegisterPrefs(PrefRegistrySimple* registry);
83 // Returns the device serial number, or an empty string if not available.
84 static std::string GetMachineID();
86 // Returns the machine model, or an empty string if not available.
87 static std::string GetMachineModel();
89 // Returns the robot 'email address' associated with the device robot
90 // account (sometimes called a service account) associated with this device
91 // during enterprise enrollment.
92 std::string GetRobotAccountId();
94 // Starts the connection via |client_to_connect|.
95 void StartConnection(scoped_ptr<CloudPolicyClient> client_to_connect,
96 EnterpriseInstallAttributes* install_attributes);
98 // Sends the unregister request. |callback| is invoked with a boolean
99 // parameter indicating the result when done.
100 virtual void Unregister(const UnregisterCallback& callback);
102 // Disconnects the manager.
103 virtual void Disconnect();
105 DeviceCloudPolicyStoreChromeOS* device_store() {
106 return device_store_.get();
109 // Return the StatusUploader used to communicate device status to the
110 // policy server.
111 StatusUploader* GetStatusUploader() const { return status_uploader_.get(); }
113 private:
114 // Saves the state keys received from |session_manager_client_|.
115 void OnStateKeysUpdated();
117 // Initializes requisition settings at OOBE with values from VPD.
118 void InitializeRequisition();
120 void NotifyConnected();
121 void NotifyDisconnected();
123 // Factory function to create the StatusUploader.
124 void CreateStatusUploader();
126 // Points to the same object as the base CloudPolicyManager::store(), but with
127 // actual device policy specific type.
128 scoped_ptr<DeviceCloudPolicyStoreChromeOS> device_store_;
129 ServerBackedStateKeysBroker* state_keys_broker_;
131 // Helper object that handles updating the server with our current device
132 // state.
133 scoped_ptr<StatusUploader> status_uploader_;
135 // Helper object that handles uploading system logs to the server.
136 scoped_ptr<SystemLogUploader> syslog_uploader_;
138 // Helper object that handles sending heartbeats over the GCM channel to
139 // the server, to monitor connectivity.
140 scoped_ptr<HeartbeatScheduler> heartbeat_scheduler_;
142 // The TaskRunner used to do device status and log uploads.
143 scoped_refptr<base::SequencedTaskRunner> task_runner_;
145 ServerBackedStateKeysBroker::Subscription state_keys_update_subscription_;
147 // PrefService instance to read the policy refresh rate from.
148 PrefService* local_state_;
150 scoped_ptr<chromeos::attestation::AttestationPolicyObserver>
151 attestation_policy_observer_;
153 base::ObserverList<Observer, true> observers_;
155 DISALLOW_COPY_AND_ASSIGN(DeviceCloudPolicyManagerChromeOS);
158 } // namespace policy
160 #endif // CHROME_BROWSER_CHROMEOS_POLICY_DEVICE_CLOUD_POLICY_MANAGER_CHROMEOS_H_