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

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: Oops. 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)>
pastarmovj 2012/07/30 12:19:19 Maybe put Callback on this line?
Mattias Nissler (ping if slow) 2012/07/31 13:02:15 Done.
31 Callback;
32
33 // Creates a new load operation.
34 explicit SessionManagerOperation(const Callback& callback);
35 virtual ~SessionManagerOperation();
36
37 // Starts the operation.
38 void Start(SessionManagerClient* session_manager_client,
39 scoped_refptr<OwnerKeyUtil> owner_key_util,
40 scoped_refptr<OwnerKey> owner_key);
41
42 // Restarts a load operation (if that part is already in progress).
43 void RestartLoad(bool key_changed);
44
45 // Accessors for recovering the loaded policy data after completion.
46 scoped_ptr<enterprise_management::PolicyData>& policy_data() {
47 return policy_data_;
48 }
49 scoped_ptr<enterprise_management::ChromeDeviceSettingsProto>&
50 device_settings() {
51 return device_settings_;
52 }
53
54 // Owner key as configured/loaded from disk.
55 scoped_refptr<OwnerKey> owner_key() {
56 return owner_key_;
57 }
58
59 // Whether the load operation is underway.
60 bool is_loading() const {
61 return is_loading_;
62 }
63
64 void set_force_key_load(bool force_key_load) {
65 force_key_load_ = force_key_load;
66 }
67
68 protected:
69 // Runs the operation. The result is reported through |callback_|.
70 virtual void Run() = 0;
71
72 // Ensures the owner key is loaded.
73 void EnsureOwnerKey(const base::Closure& callback);
74
75 // Starts a load operation.
76 void StartLoading();
77
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);
81
82 SessionManagerClient* session_manager_client() {
83 return session_manager_client_;
84 }
85
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);
91
92 // Stores the owner key loaded by LoadOwnerKey and calls |callback|.
93 void StoreOwnerKey(const base::Closure& callback,
94 scoped_refptr<OwnerKey> new_key);
95
96 // Triggers a device settings load.
97 void RetrieveDeviceSettings();
98
99 // Validates device settings after retrieval from session_manager.
100 void ValidateDeviceSettings(const std::string& policy_blob);
101
102 // Extracts status and device settings from the validator and reports them.
103 void ReportValidatorStatus(policy::DeviceCloudPolicyValidator* validator);
104
105 SessionManagerClient* session_manager_client_;
106 scoped_refptr<OwnerKeyUtil> owner_key_util_;
107
108 base::WeakPtrFactory<SessionManagerOperation> weak_factory_;
109
110 Callback callback_;
111
112 scoped_refptr<OwnerKey> owner_key_;
113 bool force_key_load_;
114
115 bool is_loading_;
116 scoped_ptr<enterprise_management::PolicyData> policy_data_;
117 scoped_ptr<enterprise_management::ChromeDeviceSettingsProto> device_settings_;
118
119 DISALLOW_COPY_AND_ASSIGN(SessionManagerOperation);
120 };
121
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();
129
130 protected:
131 // SessionManagerOperation:
132 virtual void Run() OVERRIDE;
133
134 private:
135 DISALLOW_COPY_AND_ASSIGN(LoadSettingsOperation);
136 };
137
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(const Callback& callback,
144 const std::string& policy_blob);
145 virtual ~StoreSettingsOperation();
146
147 protected:
148 // SessionManagerOperation:
149 virtual void Run() OVERRIDE;
150
151 private:
152 // Handles the result of the store operation and triggers the load.
153 void HandleStoreResult(bool success);
154
155 std::string policy_blob_;
156
157 base::WeakPtrFactory<StoreSettingsOperation> weak_factory_;
158
159 DISALLOW_COPY_AND_ASSIGN(StoreSettingsOperation);
160 };
161
162 // Signs device settings and stores the resulting blob to session_manager.
163 class SignAndStoreSettingsOperation : public SessionManagerOperation {
pastarmovj 2012/07/30 12:19:19 Could this one inherit the StoreSettingsOperation
Mattias Nissler (ping if slow) 2012/07/31 13:02:15 Some aspects are identical, others are different (
164 public:
165 // Creates a new sign-and-store operation.
166 SignAndStoreSettingsOperation(
167 const Callback& callback,
168 scoped_ptr<enterprise_management::ChromeDeviceSettingsProto> settings,
169 const std::string& username);
170 virtual ~SignAndStoreSettingsOperation();
171
172 // SessionManagerOperation:
173 virtual void Run() OVERRIDE;
174
175 private:
176 // Given an owner key, starts the signing operation.
177 void StartSigning();
178
179 // Builds the policy blob and signs it using the owner key.
180 static std::string AssembleAndSignPolicy(
181 scoped_ptr<enterprise_management::ChromeDeviceSettingsProto> settings,
182 const std::string& username,
183 scoped_refptr<OwnerKey> owner_key);
184
185 // Stores the signed device settings blob.
186 void StoreDeviceSettingsBlob(std::string device_settings_blob);
187
188 // Handles the result of the store operation and triggers the load.
189 void HandleStoreResult(bool success);
190
191 scoped_ptr<enterprise_management::ChromeDeviceSettingsProto> settings_;
192 std::string username_;
193
194 base::WeakPtrFactory<SignAndStoreSettingsOperation> weak_factory_;
195
196 DISALLOW_COPY_AND_ASSIGN(SignAndStoreSettingsOperation);
197 };
198
199 } // namespace
200
201 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_SESSION_MANAGER_OPERATION_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698