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

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

Issue 654263003: Implemented OwnerSettingsService::Set() method. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Merge with https://codereview.chromium.org/666363002/. Created 6 years, 1 month 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
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/linked_ptr.h"
15 #include "base/memory/ref_counted.h" 16 #include "base/memory/ref_counted.h"
16 #include "base/memory/scoped_ptr.h" 17 #include "base/memory/scoped_ptr.h"
17 #include "base/observer_list.h" 18 #include "base/observer_list.h"
18 #include "chrome/browser/chromeos/policy/proto/chrome_device_policy.pb.h" 19 #include "chrome/browser/chromeos/policy/proto/chrome_device_policy.pb.h"
19 #include "chromeos/dbus/session_manager_client.h" 20 #include "chromeos/dbus/session_manager_client.h"
20 #include "components/ownership/owner_settings_service.h" 21 #include "components/ownership/owner_settings_service.h"
21 #include "components/policy/core/common/cloud/cloud_policy_validator.h" 22 #include "components/policy/core/common/cloud/cloud_policy_validator.h"
22 #include "crypto/scoped_nss_types.h" 23 #include "crypto/scoped_nss_types.h"
23 #include "policy/proto/device_management_backend.pb.h" 24 #include "policy/proto/device_management_backend.pb.h"
24 25
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 // Signs |settings| with the private half of the owner key and sends the 132 // Signs |settings| with the private half of the owner key and sends the
132 // resulting policy blob to session manager for storage. The result of the 133 // resulting policy blob to session manager for storage. The result of the
133 // operation is reported through |callback|. If successful, the updated device 134 // operation is reported through |callback|. If successful, the updated device
134 // settings are present in policy_data() and device_settings() when the 135 // settings are present in policy_data() and device_settings() when the
135 // callback runs. 136 // callback runs.
136 void SignAndStore( 137 void SignAndStore(
137 scoped_ptr<enterprise_management::ChromeDeviceSettingsProto> new_settings, 138 scoped_ptr<enterprise_management::ChromeDeviceSettingsProto> new_settings,
138 const base::Closure& callback); 139 const base::Closure& callback);
139 140
140 // Sets the management related settings in PolicyData. 141 // Sets the management related settings in PolicyData.
142 //
143 // TODO (ygorshenin@, crbug.com/230018): move this to the
144 // OwnerSettingsService.
141 void SetManagementSettings( 145 void SetManagementSettings(
142 enterprise_management::PolicyData::ManagementMode management_mode, 146 enterprise_management::PolicyData::ManagementMode management_mode,
143 const std::string& request_token, 147 const std::string& request_token,
144 const std::string& device_id, 148 const std::string& device_id,
145 const base::Closure& callback); 149 const base::Closure& callback);
146 150
147 // Stores a policy blob to session_manager. The result of the operation is 151 // Stores a policy blob to session_manager. The result of the operation is
148 // reported through |callback|. If successful, the updated device settings are 152 // reported through |callback|. If successful, the updated device settings are
149 // present in policy_data() and device_settings() when the callback runs. 153 // present in policy_data() and device_settings() when the callback runs.
150 void Store(scoped_ptr<enterprise_management::PolicyFetchResponse> policy, 154 void Store(scoped_ptr<enterprise_management::PolicyFetchResponse> policy,
(...skipping 11 matching lines...) Expand all
162 bool HasPrivateOwnerKey(); 166 bool HasPrivateOwnerKey();
163 167
164 // Sets the identity of the user that's interacting with the service. This is 168 // Sets the identity of the user that's interacting with the service. This is
165 // relevant only for writing settings through SignAndStore(). 169 // relevant only for writing settings through SignAndStore().
166 void InitOwner(const std::string& username, 170 void InitOwner(const std::string& username,
167 const base::WeakPtr<ownership::OwnerSettingsService>& 171 const base::WeakPtr<ownership::OwnerSettingsService>&
168 owner_settings_service); 172 owner_settings_service);
169 173
170 const std::string& GetUsername() const; 174 const std::string& GetUsername() const;
171 175
176 ownership::OwnerSettingsService* GetOwnerSettingsService() const;
177
172 // Adds an observer. 178 // Adds an observer.
173 void AddObserver(Observer* observer); 179 void AddObserver(Observer* observer);
174 // Removes an observer. 180 // Removes an observer.
175 void RemoveObserver(Observer* observer); 181 void RemoveObserver(Observer* observer);
176 182
177 // SessionManagerClient::Observer: 183 // SessionManagerClient::Observer:
178 virtual void OwnerKeySet(bool success) override; 184 virtual void OwnerKeySet(bool success) override;
179 virtual void PropertyChangeComplete(bool success) override; 185 virtual void PropertyChangeComplete(bool success) override;
180 186
181 private: 187 private:
182 friend class OwnerSettingsServiceChromeOS; 188 friend class OwnerSettingsServiceChromeOS;
183 189
184 // Enqueues a new operation. Takes ownership of |operation| and starts it 190 // Enqueues a new operation. Takes ownership of |operation| and starts it
185 // right away if there is no active operation currently. 191 // right away if there is no active operation currently.
186 void Enqueue(SessionManagerOperation* operation); 192 void Enqueue(const linked_ptr<SessionManagerOperation>& operation);
187 193
188 // Enqueues a load operation. 194 // Enqueues a load operation.
189 void EnqueueLoad(bool force_key_load); 195 void EnqueueLoad(bool force_key_load);
190 196
197 // Enqueues a sign and store operation.
198 void EnqueueSignAndStore(scoped_ptr<enterprise_management::PolicyData> policy,
199 const base::Closure& callback);
200
191 // Makes sure there's a reload operation so changes to the settings (and key, 201 // Makes sure there's a reload operation so changes to the settings (and key,
192 // in case force_key_load is set) are getting picked up. 202 // in case force_key_load is set) are getting picked up.
193 void EnsureReload(bool force_key_load); 203 void EnsureReload(bool force_key_load);
194 204
195 // Runs the next pending operation. 205 // Runs the next pending operation.
196 void StartNextOperation(); 206 void StartNextOperation();
197 207
198 // Updates status, policy data and owner key from a finished operation. 208 // Updates status, policy data and owner key from a finished operation.
199 // Starts the next pending operation if available. 209 // Starts the next pending operation if available.
200 void HandleCompletedOperation(const base::Closure& callback, 210 void HandleCompletedOperation(const base::Closure& callback,
201 SessionManagerOperation* operation, 211 SessionManagerOperation* operation,
202 Status status); 212 Status status);
203 213
204 // Updates status and invokes the callback immediately. 214 // Updates status and invokes the callback immediately.
205 void HandleError(Status status, const base::Closure& callback); 215 void HandleError(Status status, const base::Closure& callback);
206 216
207 // Called by OwnerSettingsService when sign-and-store operation completes.
208 void OnSignAndStoreOperationCompleted(Status status);
209
210 void set_policy_data(
211 scoped_ptr<enterprise_management::PolicyData> policy_data) {
212 policy_data_ = policy_data.Pass();
213 }
214
215 void set_device_settings(scoped_ptr<
216 enterprise_management::ChromeDeviceSettingsProto> device_settings) {
217 device_settings_ = device_settings.Pass();
218 }
219
220 SessionManagerClient* session_manager_client_; 217 SessionManagerClient* session_manager_client_;
221 scoped_refptr<ownership::OwnerKeyUtil> owner_key_util_; 218 scoped_refptr<ownership::OwnerKeyUtil> owner_key_util_;
222 219
223 Status store_status_; 220 Status store_status_;
224 221
225 std::vector<OwnershipStatusCallback> pending_ownership_status_callbacks_; 222 std::vector<OwnershipStatusCallback> pending_ownership_status_callbacks_;
226 223
227 std::string username_; 224 std::string username_;
228 scoped_refptr<ownership::PublicKey> public_key_; 225 scoped_refptr<ownership::PublicKey> public_key_;
229 base::WeakPtr<ownership::OwnerSettingsService> owner_settings_service_; 226 base::WeakPtr<ownership::OwnerSettingsService> owner_settings_service_;
230 227
231 scoped_ptr<enterprise_management::PolicyData> policy_data_; 228 scoped_ptr<enterprise_management::PolicyData> policy_data_;
232 scoped_ptr<enterprise_management::ChromeDeviceSettingsProto> device_settings_; 229 scoped_ptr<enterprise_management::ChromeDeviceSettingsProto> device_settings_;
233 230
234 // The queue of pending operations. The first operation on the queue is 231 // The queue of pending operations. The first operation on the queue is
235 // currently active; it gets removed and destroyed once it completes. 232 // currently active; it gets removed and destroyed once it completes.
236 std::deque<SessionManagerOperation*> pending_operations_; 233 std::deque<linked_ptr<SessionManagerOperation>> pending_operations_;
237 234
238 ObserverList<Observer, true> observers_; 235 ObserverList<Observer> observers_;
239 236
240 // For recoverable load errors how many retries are left before we give up. 237 // For recoverable load errors how many retries are left before we give up.
241 int load_retries_left_; 238 int load_retries_left_;
242 239
243 base::WeakPtrFactory<DeviceSettingsService> weak_factory_; 240 base::WeakPtrFactory<DeviceSettingsService> weak_factory_;
244 241
245 DISALLOW_COPY_AND_ASSIGN(DeviceSettingsService); 242 DISALLOW_COPY_AND_ASSIGN(DeviceSettingsService);
246 }; 243 };
247 244
248 // Helper class for tests. Initializes the DeviceSettingsService singleton on 245 // Helper class for tests. Initializes the DeviceSettingsService singleton on
249 // construction and tears it down again on destruction. 246 // construction and tears it down again on destruction.
250 class ScopedTestDeviceSettingsService { 247 class ScopedTestDeviceSettingsService {
251 public: 248 public:
252 ScopedTestDeviceSettingsService(); 249 ScopedTestDeviceSettingsService();
253 ~ScopedTestDeviceSettingsService(); 250 ~ScopedTestDeviceSettingsService();
254 251
255 private: 252 private:
256 DISALLOW_COPY_AND_ASSIGN(ScopedTestDeviceSettingsService); 253 DISALLOW_COPY_AND_ASSIGN(ScopedTestDeviceSettingsService);
257 }; 254 };
258 255
259 } // namespace chromeos 256 } // namespace chromeos
260 257
261 #endif // CHROME_BROWSER_CHROMEOS_SETTINGS_DEVICE_SETTINGS_SERVICE_H_ 258 #endif // CHROME_BROWSER_CHROMEOS_SETTINGS_DEVICE_SETTINGS_SERVICE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698