Revert 168224 - Update V8 to version 3.15.4.
[chromium-blink-merge.git] / chrome / browser / chromeos / settings / session_manager_operation.h
blob3c68509e6a5485bd9769fcad5850adc7ee4c9c98
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_SETTINGS_SESSION_MANAGER_OPERATION_H_
6 #define CHROME_BROWSER_CHROMEOS_SETTINGS_SESSION_MANAGER_OPERATION_H_
8 #include "base/basictypes.h"
9 #include "base/callback.h"
10 #include "base/memory/ref_counted.h"
11 #include "base/memory/scoped_ptr.h"
12 #include "chrome/browser/chromeos/settings/device_settings_service.h"
14 namespace enterprise_management {
15 class ChromeDeviceSettingsProto;
16 class PolicyData;
17 class PolicyFetchResponse;
20 namespace chromeos {
22 class OwnerKeyUtil;
23 class SessionManagerClient;
25 // Handles a single transaction with session manager. This is a virtual base
26 // class that contains common infrastructure for key and policy loading. There
27 // are subclasses for loading, storing and signing policy blobs.
28 class SessionManagerOperation {
29 public:
30 typedef base::Callback<void(SessionManagerOperation*,
31 DeviceSettingsService::Status)> Callback;
33 // Creates a new load operation.
34 explicit SessionManagerOperation(const Callback& callback);
35 virtual ~SessionManagerOperation();
37 // Starts the operation.
38 void Start(SessionManagerClient* session_manager_client,
39 scoped_refptr<OwnerKeyUtil> owner_key_util,
40 scoped_refptr<OwnerKey> owner_key);
42 // Restarts a load operation (if that part is already in progress).
43 void RestartLoad(bool key_changed);
45 // Accessors for recovering the loaded policy data after completion.
46 scoped_ptr<enterprise_management::PolicyData>& policy_data() {
47 return policy_data_;
49 scoped_ptr<enterprise_management::ChromeDeviceSettingsProto>&
50 device_settings() {
51 return device_settings_;
54 // Owner key as configured/loaded from disk.
55 scoped_refptr<OwnerKey> owner_key() {
56 return owner_key_;
59 // Whether the load operation is underway.
60 bool is_loading() const {
61 return is_loading_;
64 void set_force_key_load(bool force_key_load) {
65 force_key_load_ = force_key_load;
68 protected:
69 // Runs the operation. The result is reported through |callback_|.
70 virtual void Run() = 0;
72 // Ensures the owner key is loaded.
73 void EnsureOwnerKey(const base::Closure& callback);
75 // Starts a load operation.
76 void StartLoading();
78 // Reports the result status of the operation. Once this gets called, the
79 // operation should not perform further processing or trigger callbacks.
80 void ReportResult(DeviceSettingsService::Status status);
82 SessionManagerClient* session_manager_client() {
83 return session_manager_client_;
86 private:
87 // Loads the owner key from disk. Must be run on a thread that can do I/O.
88 static scoped_refptr<OwnerKey> LoadOwnerKey(
89 scoped_refptr<OwnerKeyUtil> util,
90 scoped_refptr<OwnerKey> current_key);
92 // Stores the owner key loaded by LoadOwnerKey and calls |callback|.
93 void StoreOwnerKey(const base::Closure& callback,
94 scoped_refptr<OwnerKey> new_key);
96 // Triggers a device settings load.
97 void RetrieveDeviceSettings();
99 // Validates device settings after retrieval from session_manager.
100 void ValidateDeviceSettings(const std::string& policy_blob);
102 // Extracts status and device settings from the validator and reports them.
103 void ReportValidatorStatus(policy::DeviceCloudPolicyValidator* validator);
105 SessionManagerClient* session_manager_client_;
106 scoped_refptr<OwnerKeyUtil> owner_key_util_;
108 base::WeakPtrFactory<SessionManagerOperation> weak_factory_;
110 Callback callback_;
112 scoped_refptr<OwnerKey> owner_key_;
113 bool force_key_load_;
115 bool is_loading_;
116 scoped_ptr<enterprise_management::PolicyData> policy_data_;
117 scoped_ptr<enterprise_management::ChromeDeviceSettingsProto> device_settings_;
119 DISALLOW_COPY_AND_ASSIGN(SessionManagerOperation);
122 // This operation loads the public owner key from disk if appropriate, fetches
123 // the policy blob from session manager, and validates the loaded policy blob.
124 class LoadSettingsOperation : public SessionManagerOperation {
125 public:
126 // Creates a new load operation.
127 explicit LoadSettingsOperation(const Callback& callback);
128 virtual ~LoadSettingsOperation();
130 protected:
131 // SessionManagerOperation:
132 virtual void Run() OVERRIDE;
134 private:
135 DISALLOW_COPY_AND_ASSIGN(LoadSettingsOperation);
138 // Stores a pre-generated policy blob and reloads the device settings from
139 // session_manager.
140 class StoreSettingsOperation : public SessionManagerOperation {
141 public:
142 // Creates a new store operation.
143 StoreSettingsOperation(
144 const Callback& callback,
145 scoped_ptr<enterprise_management::PolicyFetchResponse> policy);
146 virtual ~StoreSettingsOperation();
148 protected:
149 // SessionManagerOperation:
150 virtual void Run() OVERRIDE;
152 private:
153 // Handles the result of the store operation and triggers the load.
154 void HandleStoreResult(bool success);
156 scoped_ptr<enterprise_management::PolicyFetchResponse> policy_;
158 base::WeakPtrFactory<StoreSettingsOperation> weak_factory_;
160 DISALLOW_COPY_AND_ASSIGN(StoreSettingsOperation);
163 // Signs device settings and stores the resulting blob to session_manager.
164 class SignAndStoreSettingsOperation : public SessionManagerOperation {
165 public:
166 // Creates a new sign-and-store operation.
167 SignAndStoreSettingsOperation(
168 const Callback& callback,
169 scoped_ptr<enterprise_management::ChromeDeviceSettingsProto> new_settings,
170 const std::string& username);
171 virtual ~SignAndStoreSettingsOperation();
173 // SessionManagerOperation:
174 virtual void Run() OVERRIDE;
176 private:
177 // Given an owner key, starts the signing operation.
178 void StartSigning();
180 // Builds the policy blob and signs it using the owner key.
181 static std::string AssembleAndSignPolicy(
182 scoped_ptr<enterprise_management::ChromeDeviceSettingsProto> settings,
183 const std::string& username,
184 scoped_refptr<OwnerKey> owner_key);
186 // Stores the signed device settings blob.
187 void StoreDeviceSettingsBlob(std::string device_settings_blob);
189 // Handles the result of the store operation and triggers the load.
190 void HandleStoreResult(bool success);
192 scoped_ptr<enterprise_management::ChromeDeviceSettingsProto> new_settings_;
193 std::string username_;
195 base::WeakPtrFactory<SignAndStoreSettingsOperation> weak_factory_;
197 DISALLOW_COPY_AND_ASSIGN(SignAndStoreSettingsOperation);
200 } // namespace
202 #endif // CHROME_BROWSER_CHROMEOS_SETTINGS_SESSION_MANAGER_OPERATION_H_