Revert of Add button to add new FSP services to Files app. (patchset #8 id:140001...
[chromium-blink-merge.git] / chrome / browser / chromeos / policy / device_cloud_policy_manager_chromeos.h
blob2035c5ee79b93625b29ad2be2e0eea6498c53f77
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;
41 // CloudPolicyManager specialization for device policy on Chrome OS.
42 class DeviceCloudPolicyManagerChromeOS : public CloudPolicyManager {
43 public:
44 class Observer {
45 public:
46 // Invoked when the device cloud policy manager connects.
47 virtual void OnDeviceCloudPolicyManagerConnected() = 0;
48 // Invoked when the device cloud policy manager disconnects.
49 virtual void OnDeviceCloudPolicyManagerDisconnected() = 0;
52 using UnregisterCallback = base::Callback<void(bool)>;
54 // |task_runner| is the runner for policy refresh, heartbeat, and status
55 // upload tasks.
56 DeviceCloudPolicyManagerChromeOS(
57 scoped_ptr<DeviceCloudPolicyStoreChromeOS> store,
58 const scoped_refptr<base::SequencedTaskRunner>& task_runner,
59 ServerBackedStateKeysBroker* state_keys_broker);
60 ~DeviceCloudPolicyManagerChromeOS() override;
62 // Initializes state keys and requisition information.
63 void Initialize(PrefService* local_state);
65 void AddDeviceCloudPolicyManagerObserver(Observer* observer);
66 void RemoveDeviceCloudPolicyManagerObserver(Observer* observer);
68 // TODO(davidyu): Move these two functions to a more appropriate place. See
69 // http://crbug.com/383695.
70 // Gets/Sets the device requisition.
71 std::string GetDeviceRequisition() const;
72 void SetDeviceRequisition(const std::string& requisition);
73 bool IsRemoraRequisition() const;
74 bool IsSharkRequisition() const;
76 // CloudPolicyManager:
77 void Shutdown() override;
79 // Pref registration helper.
80 static void RegisterPrefs(PrefRegistrySimple* registry);
82 // Returns the device serial number, or an empty string if not available.
83 static std::string GetMachineID();
85 // Returns the machine model, or an empty string if not available.
86 static std::string GetMachineModel();
88 // Returns the robot 'email address' associated with the device robot
89 // account (sometimes called a service account) associated with this device
90 // during enterprise enrollment.
91 std::string GetRobotAccountId();
93 // Starts the connection via |client_to_connect|.
94 void StartConnection(scoped_ptr<CloudPolicyClient> client_to_connect,
95 EnterpriseInstallAttributes* install_attributes);
97 // Sends the unregister request. |callback| is invoked with a boolean
98 // parameter indicating the result when done.
99 virtual void Unregister(const UnregisterCallback& callback);
101 // Disconnects the manager.
102 virtual void Disconnect();
104 DeviceCloudPolicyStoreChromeOS* device_store() {
105 return device_store_.get();
108 bool HasStatusUploaderForTest() { return status_uploader_; }
110 private:
111 // Saves the state keys received from |session_manager_client_|.
112 void OnStateKeysUpdated();
114 // Initializes requisition settings at OOBE with values from VPD.
115 void InitializeRequisition();
117 void NotifyConnected();
118 void NotifyDisconnected();
120 // Factory function to create the StatusUploader.
121 void CreateStatusUploader();
123 // Points to the same object as the base CloudPolicyManager::store(), but with
124 // actual device policy specific type.
125 scoped_ptr<DeviceCloudPolicyStoreChromeOS> device_store_;
126 ServerBackedStateKeysBroker* state_keys_broker_;
128 // Helper object that handles updating the server with our current device
129 // state.
130 scoped_ptr<StatusUploader> status_uploader_;
132 // Helper object that handles sending heartbeats over the GCM channel to
133 // the server, to monitor connectivity.
134 scoped_ptr<HeartbeatScheduler> heartbeat_scheduler_;
136 // The TaskRunner used to do device status uploads.
137 scoped_refptr<base::SequencedTaskRunner> task_runner_;
139 ServerBackedStateKeysBroker::Subscription state_keys_update_subscription_;
141 // PrefService instance to read the policy refresh rate from.
142 PrefService* local_state_;
144 scoped_ptr<chromeos::attestation::AttestationPolicyObserver>
145 attestation_policy_observer_;
147 ObserverList<Observer, true> observers_;
149 DISALLOW_COPY_AND_ASSIGN(DeviceCloudPolicyManagerChromeOS);
152 } // namespace policy
154 #endif // CHROME_BROWSER_CHROMEOS_POLICY_DEVICE_CLOUD_POLICY_MANAGER_CHROMEOS_H_