Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(532)

Side by Side Diff: chrome/browser/chromeos/login/session_manager_operation.h

Issue 10828032: Add DeviceSettingsService. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
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_LOGIN_SESSION_MANAGER_OPERATION_H_
6 #define CHROME_BROWSER_CHROMEOS_LOGIN_SESSION_MANAGER_OPERATION_H_
7
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/login/device_settings_service.h"
13
14 namespace enterprise_management {
15 class ChromeDeviceSettingsProto;
16 class PolicyData;
17 }
18
19 namespace chromeos {
20
21 class OwnerKeyUtil;
22 class SessionManagerClient;
23
24 // Handles a single transaction with session manager. This is a virtual base
25 // class that contains common infrastructure for key and policy loading. There
26 // are subclasses for loading, storing and signing policy blobs.
27 class SessionManagerOperation {
28 public:
29 typedef base::Callback<void(SessionManagerOperation*,
30 DeviceSettingsService::Status)>
31 Callback;
32
33 // Creates a new load operation.
34 SessionManagerOperation(scoped_refptr<OwnerKeyUtil> owner_key_util,
35 const Callback& callback);
36 virtual ~SessionManagerOperation();
37
38 // Runs the operation. The result is reported through |callback_|.
39 virtual void Run() = 0;
40
41 // Restarts a load operation (if that part is already in progress).
42 virtual void RestartLoad(bool key_changed);
43
44 // Accessors for recovering the loaded policy data after completion.
45 scoped_ptr<enterprise_management::PolicyData>& policy_data() {
46 return policy_data_;
47 }
48 scoped_ptr<enterprise_management::ChromeDeviceSettingsProto>&
49 device_settings() {
50 return device_settings_;
51 }
52
53 // Owner key as configured/loaded from disk.
54 scoped_refptr<OwnerKey> owner_key() {
55 return owner_key_;
56 }
57
58 // Whether the load operation is underway.
59 bool is_loading() const {
60 return is_loading_;
61 }
62
63 void set_owner_key(scoped_refptr<OwnerKey> owner_key) {
64 owner_key_ = owner_key;
65 }
66
67 void set_force_key_load(bool force_key_load) {
68 force_key_load_ = force_key_load;
69 }
70
71 void set_session_manager_client(
72 SessionManagerClient* session_manager_client) {
73 session_manager_client_ = session_manager_client;
74 }
75
76 protected:
77 // Ensures the owner key is loaded.
78 void EnsureOwnerKey(const base::Closure& callback);
79
80 // Starts a load operation.
81 void StartLoading();
82
83 // Reports the result status of the operation. Once this gets called, the
84 // operation should not perform further processing or trigger callbacks.
85 void ReportResult(DeviceSettingsService::Status status);
86
87 SessionManagerClient* session_manager_client() {
88 return session_manager_client_;
89 }
90
91 private:
92 // Loads the owner key from disk. Must be run on a thread that can do I/O.
93 static scoped_refptr<OwnerKey> LoadOwnerKey(
94 scoped_refptr<OwnerKeyUtil> util,
95 scoped_refptr<OwnerKey> current_key);
96
97 // Stores the owner key loaded by LoadOwnerKey and calls |callback|.
98 void StoreOwnerKey(const base::Closure& callback,
99 scoped_refptr<OwnerKey> new_key);
100
101 // Triggers a device settings load.
102 void RetrieveDeviceSettings();
103
104 // Validates device settings after retrieval from session_manager.
105 void ValidateDeviceSettings(const std::string& policy_blob);
106
107 // Extracts status and device settings from the validator and reports them.
108 void ReportValidatorStatus(policy::DeviceCloudPolicyValidator* validator);
109
110 SessionManagerClient* session_manager_client_;
111 scoped_refptr<OwnerKeyUtil> owner_key_util_;
112
113 base::WeakPtrFactory<SessionManagerOperation> weak_factory_;
114
115 Callback callback_;
116
117 scoped_refptr<OwnerKey> owner_key_;
118 bool force_key_load_;
119
120 bool is_loading_;
121 scoped_ptr<enterprise_management::PolicyData> policy_data_;
122 scoped_ptr<enterprise_management::ChromeDeviceSettingsProto> device_settings_;
123
124 DISALLOW_COPY_AND_ASSIGN(SessionManagerOperation);
125 };
126
127 // This operation loads the public owner key from disk if appropriate, fetches
128 // the policy blob from session manager, and validates the loaded policy blob.
129 class LoadSettingsOperation : public SessionManagerOperation {
130 public:
131 // Creates a new load operation.
132 LoadSettingsOperation(scoped_refptr<OwnerKeyUtil> owner_key_util,
133 const Callback& callback);
134 virtual ~LoadSettingsOperation();
135
136 // SessionManagerOperation:
137 virtual void Run() OVERRIDE;
138
139 private:
140 DISALLOW_COPY_AND_ASSIGN(LoadSettingsOperation);
141 };
142
143 // Stores a pre-generated policy blob and reloads the device settings from
144 // session_manager.
145 class StoreSettingsOperation : public SessionManagerOperation {
146 public:
147 // Creates a new store operation.
148 StoreSettingsOperation(scoped_refptr<OwnerKeyUtil> owner_key_util,
149 const Callback& callback,
150 const std::string& policy_blob);
151 virtual ~StoreSettingsOperation();
152
153 // SessionManagerOperation:
154 virtual void Run() OVERRIDE;
155
156 private:
157 // Handles the result of the store operation and triggers the load.
158 void HandleStoreResult(bool success);
159
160 std::string policy_blob_;
161
162 base::WeakPtrFactory<StoreSettingsOperation> weak_factory_;
163
164 DISALLOW_COPY_AND_ASSIGN(StoreSettingsOperation);
165 };
166
167 // Signs device settings and stores the resulting blob to session_manager.
168 class SignAndStoreSettingsOperation : public SessionManagerOperation {
169 public:
170 // Creates a new sign-and-store operation.
171 SignAndStoreSettingsOperation(
172 scoped_refptr<OwnerKeyUtil> owner_key_util,
173 const Callback& callback,
174 scoped_ptr<enterprise_management::ChromeDeviceSettingsProto> settings,
175 const std::string& username);
176 virtual ~SignAndStoreSettingsOperation();
177
178 // SessionManagerOperation:
179 virtual void Run() OVERRIDE;
180
181 private:
182 // Given an owner key, starts the signing operation.
183 void StartSigning();
184
185 // Builds the policy blob and signs it using the owner key.
186 static std::string AssembleAndSignPolicy(
187 scoped_ptr<enterprise_management::ChromeDeviceSettingsProto> settings,
188 const std::string& username,
189 scoped_refptr<OwnerKey> owner_key);
190
191 // Stores the signed device settings blob.
192 void StoreDeviceSettingsBlob(std::string device_settings_blob);
193
194 // Handles the result of the store operation and triggers the load.
195 void HandleStoreResult(bool success);
196
197 scoped_ptr<enterprise_management::ChromeDeviceSettingsProto> settings_;
198 std::string username_;
199
200 base::WeakPtrFactory<SignAndStoreSettingsOperation> weak_factory_;
201
202 DISALLOW_COPY_AND_ASSIGN(SignAndStoreSettingsOperation);
203 };
204
205 } // namespace
206
207 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_SESSION_MANAGER_OPERATION_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698