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

Side by Side Diff: chrome/browser/chromeos/settings/device_settings_service.h

Issue 399613003: SignAndStore method is moved out from DeviceSettingsService to OwnerSettingsService. It's still cal… (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Deleted inclusion of dbus_thread_manager.h. Created 6 years, 5 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
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CHROME_BROWSER_CHROMEOS_SETTINGS_DEVICE_SETTINGS_SERVICE_H_ 5 #ifndef CHROME_BROWSER_CHROMEOS_SETTINGS_DEVICE_SETTINGS_SERVICE_H_
6 #define CHROME_BROWSER_CHROMEOS_SETTINGS_DEVICE_SETTINGS_SERVICE_H_ 6 #define CHROME_BROWSER_CHROMEOS_SETTINGS_DEVICE_SETTINGS_SERVICE_H_
7 7
8 #include <deque> 8 #include <deque>
9 #include <string> 9 #include <string>
10 #include <vector> 10 #include <vector>
11 11
12 #include "base/basictypes.h" 12 #include "base/basictypes.h"
13 #include "base/callback.h" 13 #include "base/callback.h"
14 #include "base/compiler_specific.h" 14 #include "base/compiler_specific.h"
15 #include "base/memory/ref_counted.h" 15 #include "base/memory/ref_counted.h"
16 #include "base/memory/scoped_ptr.h" 16 #include "base/memory/scoped_ptr.h"
17 #include "base/observer_list.h" 17 #include "base/observer_list.h"
18 #include "chrome/browser/chromeos/policy/proto/chrome_device_policy.pb.h"
18 #include "chromeos/dbus/session_manager_client.h" 19 #include "chromeos/dbus/session_manager_client.h"
19 #include "components/policy/core/common/cloud/cloud_policy_validator.h" 20 #include "components/policy/core/common/cloud/cloud_policy_validator.h"
20 #include "crypto/scoped_nss_types.h" 21 #include "crypto/scoped_nss_types.h"
21 #include "policy/proto/device_management_backend.pb.h" 22 #include "policy/proto/device_management_backend.pb.h"
22 23
23 namespace crypto { 24 namespace crypto {
24 class RSAPrivateKey; 25 class RSAPrivateKey;
25 } 26 }
26 27
27 namespace enterprise_management {
28 class ChromeDeviceSettingsProto;
29 }
30
31 namespace chromeos { 28 namespace chromeos {
32 29
33 class OwnerKeyUtil; 30 class OwnerKeyUtil;
34 class PublicKey; 31 class PublicKey;
35 class SessionManagerOperation; 32 class SessionManagerOperation;
36 33
37 // Deals with the low-level interface to Chromium OS device settings. Device 34 // Deals with the low-level interface to Chromium OS device settings. Device
38 // settings are stored in a protobuf that's protected by a cryptographic 35 // settings are stored in a protobuf that's protected by a cryptographic
39 // signature generated by a key in the device owner's possession. Key and 36 // signature generated by a key in the device owner's possession. Key and
40 // settings are brokered by the session_manager daemon. 37 // settings are brokered by the session_manager daemon.
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
96 virtual bool IsOwner() = 0; 93 virtual bool IsOwner() = 0;
97 94
98 // Determines whether current user is owner or not, responds via 95 // Determines whether current user is owner or not, responds via
99 // |callback|. 96 // |callback|.
100 virtual void IsOwnerAsync(const IsOwnerCallback& callback) = 0; 97 virtual void IsOwnerAsync(const IsOwnerCallback& callback) = 0;
101 98
102 // Assembles and signs |policy|, responds via |callback|. 99 // Assembles and signs |policy|, responds via |callback|.
103 virtual bool AssembleAndSignPolicyAsync( 100 virtual bool AssembleAndSignPolicyAsync(
104 scoped_ptr<enterprise_management::PolicyData> policy, 101 scoped_ptr<enterprise_management::PolicyData> policy,
105 const AssembleAndSignPolicyCallback& callback) = 0; 102 const AssembleAndSignPolicyCallback& callback) = 0;
103
104 // Signs |settings| with the private half of the owner key and sends
105 // the resulting policy blob to session manager for storage. The
106 // result of the operation is reported through |callback|. If
107 // successful, the updated device settings are present in
108 // policy_data() and device_settings() when the callback runs.
109 virtual void SignAndStoreAsync(
110 scoped_ptr<enterprise_management::ChromeDeviceSettingsProto> settings,
111 const base::Closure& callback) = 0;
112
113 // Sets the management related settings in PolicyData. Note that if
114 // |management_mode| is NOT_MANAGED, |request_token| and |device_id|
115 // should be empty strings. The result of the operation is reported
116 // through |callback|.
117 virtual void SetManagementSettingsAsync(
118 enterprise_management::PolicyData::ManagementMode management_mode,
119 const std::string& request_token,
120 const std::string& device_id,
121 const base::Closure& callback) = 0;
106 }; 122 };
107 123
108 // Manage singleton instance. 124 // Manage singleton instance.
109 static void Initialize(); 125 static void Initialize();
110 static bool IsInitialized(); 126 static bool IsInitialized();
111 static void Shutdown(); 127 static void Shutdown();
112 static DeviceSettingsService* Get(); 128 static DeviceSettingsService* Get();
113 129
114 // Creates a device settings service instance. This is meant for unit tests, 130 // Creates a device settings service instance. This is meant for unit tests,
115 // production code uses the singleton returned by Get() above. 131 // production code uses the singleton returned by Get() above.
116 DeviceSettingsService(); 132 DeviceSettingsService();
117 virtual ~DeviceSettingsService(); 133 virtual ~DeviceSettingsService();
118 134
119 // To be called on startup once threads are initialized and DBus is ready. 135 // To be called on startup once threads are initialized and DBus is ready.
120 void SetSessionManager(SessionManagerClient* session_manager_client, 136 void SetSessionManager(SessionManagerClient* session_manager_client,
121 scoped_refptr<OwnerKeyUtil> owner_key_util); 137 scoped_refptr<OwnerKeyUtil> owner_key_util);
122 138
123 // Prevents the service from making further calls to session_manager_client 139 // Prevents the service from making further calls to session_manager_client
124 // and stops any pending operations. 140 // and stops any pending operations.
125 void UnsetSessionManager(); 141 void UnsetSessionManager();
126 142
143 SessionManagerClient* session_manager_client() const {
144 return session_manager_client_;
145 }
146
127 // Returns the currently active device settings. Returns NULL if the device 147 // Returns the currently active device settings. Returns NULL if the device
128 // settings have not been retrieved from session_manager yet. 148 // settings have not been retrieved from session_manager yet.
129 const enterprise_management::PolicyData* policy_data() { 149 const enterprise_management::PolicyData* policy_data() {
130 return policy_data_.get(); 150 return policy_data_.get();
131 } 151 }
132 const enterprise_management::ChromeDeviceSettingsProto* 152 const enterprise_management::ChromeDeviceSettingsProto*
133 device_settings() const { 153 device_settings() const {
134 return device_settings_.get(); 154 return device_settings_.get();
135 } 155 }
136 156
(...skipping 11 matching lines...) Expand all
148 168
149 // Signs |settings| with the private half of the owner key and sends the 169 // Signs |settings| with the private half of the owner key and sends the
150 // resulting policy blob to session manager for storage. The result of the 170 // resulting policy blob to session manager for storage. The result of the
151 // operation is reported through |callback|. If successful, the updated device 171 // operation is reported through |callback|. If successful, the updated device
152 // settings are present in policy_data() and device_settings() when the 172 // settings are present in policy_data() and device_settings() when the
153 // callback runs. 173 // callback runs.
154 void SignAndStore( 174 void SignAndStore(
155 scoped_ptr<enterprise_management::ChromeDeviceSettingsProto> new_settings, 175 scoped_ptr<enterprise_management::ChromeDeviceSettingsProto> new_settings,
156 const base::Closure& callback); 176 const base::Closure& callback);
157 177
158 // Sets the management related settings in PolicyData. Note that if
159 // |management_mode| is NOT_MANAGED, |request_token| and |device_id| should be
160 // empty strings.
161 void SetManagementSettings( 178 void SetManagementSettings(
pastarmovj 2014/07/18 11:20:16 I think you should preserve at least the first sen
ygorshenin1 2014/07/18 11:48:47 Done.
162 enterprise_management::PolicyData::ManagementMode management_mode, 179 enterprise_management::PolicyData::ManagementMode management_mode,
163 const std::string& request_token, 180 const std::string& request_token,
164 const std::string& device_id, 181 const std::string& device_id,
165 const base::Closure& callback); 182 const base::Closure& callback);
166 183
167 // Stores a policy blob to session_manager. The result of the operation is 184 // Stores a policy blob to session_manager. The result of the operation is
168 // reported through |callback|. If successful, the updated device settings are 185 // reported through |callback|. If successful, the updated device settings are
169 // present in policy_data() and device_settings() when the callback runs. 186 // present in policy_data() and device_settings() when the callback runs.
170 void Store(scoped_ptr<enterprise_management::PolicyFetchResponse> policy, 187 void Store(scoped_ptr<enterprise_management::PolicyFetchResponse> policy,
171 const base::Closure& callback); 188 const base::Closure& callback);
(...skipping 18 matching lines...) Expand all
190 // Adds an observer. 207 // Adds an observer.
191 void AddObserver(Observer* observer); 208 void AddObserver(Observer* observer);
192 // Removes an observer. 209 // Removes an observer.
193 void RemoveObserver(Observer* observer); 210 void RemoveObserver(Observer* observer);
194 211
195 // SessionManagerClient::Observer: 212 // SessionManagerClient::Observer:
196 virtual void OwnerKeySet(bool success) OVERRIDE; 213 virtual void OwnerKeySet(bool success) OVERRIDE;
197 virtual void PropertyChangeComplete(bool success) OVERRIDE; 214 virtual void PropertyChangeComplete(bool success) OVERRIDE;
198 215
199 private: 216 private:
217 friend class OwnerSettingsService;
218
200 // Enqueues a new operation. Takes ownership of |operation| and starts it 219 // Enqueues a new operation. Takes ownership of |operation| and starts it
201 // right away if there is no active operation currently. 220 // right away if there is no active operation currently.
202 void Enqueue(SessionManagerOperation* operation); 221 void Enqueue(SessionManagerOperation* operation);
203 222
204 // Enqueues a load operation. 223 // Enqueues a load operation.
205 void EnqueueLoad(bool force_key_load); 224 void EnqueueLoad(bool force_key_load);
206 225
207 void EnqueueSignAndStore(scoped_ptr<enterprise_management::PolicyData> policy,
208 const base::Closure& callback);
209
210 // Makes sure there's a reload operation so changes to the settings (and key, 226 // Makes sure there's a reload operation so changes to the settings (and key,
211 // in case force_key_load is set) are getting picked up. 227 // in case force_key_load is set) are getting picked up.
212 void EnsureReload(bool force_key_load); 228 void EnsureReload(bool force_key_load);
213 229
214 // Runs the next pending operation. 230 // Runs the next pending operation.
215 void StartNextOperation(); 231 void StartNextOperation();
216 232
217 // Updates status, policy data and owner key from a finished operation. 233 // Updates status, policy data and owner key from a finished operation.
218 // Starts the next pending operation if available. 234 // Starts the next pending operation if available.
219 void HandleCompletedOperation(const base::Closure& callback, 235 void HandleCompletedOperation(const base::Closure& callback,
220 SessionManagerOperation* operation, 236 SessionManagerOperation* operation,
221 Status status); 237 Status status);
222 238
223 // Updates status and invokes the callback immediately. 239 // Updates status and invokes the callback immediately.
224 void HandleError(Status status, const base::Closure& callback); 240 void HandleError(Status status, const base::Closure& callback);
225 241
226 // Assembles PolicyData based on |settings| and the current |policy_data_| 242 // Called by OwnerSettingsService when sign-and-store operation completes.
227 // and |username_|. 243 void OnSignAndStoreOperationCompleted(Status status);
228 scoped_ptr<enterprise_management::PolicyData> AssemblePolicy(
229 const enterprise_management::ChromeDeviceSettingsProto& settings) const;
230 244
231 // Returns the current management mode. 245 void set_policy_data(
232 enterprise_management::PolicyData::ManagementMode GetManagementMode() const; 246 scoped_ptr<enterprise_management::PolicyData> policy_data) {
247 policy_data_ = policy_data.Pass();
248 }
233 249
234 // Returns true if it is okay to transfer from the current mode to the new 250 void set_device_settings(scoped_ptr<
235 // mode. This function should be called in SetManagementMode(). 251 enterprise_management::ChromeDeviceSettingsProto> device_settings) {
236 bool CheckManagementModeTransition( 252 device_settings_ = device_settings.Pass();
237 enterprise_management::PolicyData::ManagementMode new_mode) const; 253 }
238 254
239 SessionManagerClient* session_manager_client_; 255 SessionManagerClient* session_manager_client_;
240 scoped_refptr<OwnerKeyUtil> owner_key_util_; 256 scoped_refptr<OwnerKeyUtil> owner_key_util_;
241 257
242 Status store_status_; 258 Status store_status_;
243 259
244 std::vector<OwnershipStatusCallback> pending_ownership_status_callbacks_; 260 std::vector<OwnershipStatusCallback> pending_ownership_status_callbacks_;
245 261
246 std::string username_; 262 std::string username_;
247 scoped_refptr<PublicKey> public_key_; 263 scoped_refptr<PublicKey> public_key_;
(...skipping 23 matching lines...) Expand all
271 ScopedTestDeviceSettingsService(); 287 ScopedTestDeviceSettingsService();
272 ~ScopedTestDeviceSettingsService(); 288 ~ScopedTestDeviceSettingsService();
273 289
274 private: 290 private:
275 DISALLOW_COPY_AND_ASSIGN(ScopedTestDeviceSettingsService); 291 DISALLOW_COPY_AND_ASSIGN(ScopedTestDeviceSettingsService);
276 }; 292 };
277 293
278 } // namespace chromeos 294 } // namespace chromeos
279 295
280 #endif // CHROME_BROWSER_CHROMEOS_SETTINGS_DEVICE_SETTINGS_SERVICE_H_ 296 #endif // CHROME_BROWSER_CHROMEOS_SETTINGS_DEVICE_SETTINGS_SERVICE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698