OLD | NEW |
---|---|
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 #include "chrome/browser/chromeos/settings/device_settings_service.h" | 5 #include "chrome/browser/chromeos/settings/device_settings_service.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/location.h" | 10 #include "base/location.h" |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
122 } | 122 } |
123 | 123 |
124 scoped_refptr<PublicKey> DeviceSettingsService::GetPublicKey() { | 124 scoped_refptr<PublicKey> DeviceSettingsService::GetPublicKey() { |
125 return public_key_; | 125 return public_key_; |
126 } | 126 } |
127 | 127 |
128 void DeviceSettingsService::Load() { | 128 void DeviceSettingsService::Load() { |
129 EnqueueLoad(false); | 129 EnqueueLoad(false); |
130 } | 130 } |
131 | 131 |
132 void DeviceSettingsService::LoadImmediately() { | |
133 loading_immediately_ = true; | |
Andrew T Wilson (Slow)
2017/02/23 12:05:48
Can we get rid of this data member and instead pas
Sergey Poromov
2017/02/28 14:01:17
Done.
| |
134 std::unique_ptr<SessionManagerOperation> operation(new LoadSettingsOperation( | |
emaxx
2017/02/22 17:24:33
Should the same check for "device_mode_ == policy:
Sergey Poromov
2017/02/28 14:01:17
Expect so, but needs review from tnagel@ for Activ
emaxx
2017/02/28 14:31:31
Yes, please ask Thiemo to pay special attention to
Thiemo Nagel
2017/02/28 15:41:05
Yes!
| |
135 true /*force_key_load*/, true /*cloud_validations*/, | |
136 true /*force_immediate_load*/, | |
137 base::Bind(&DeviceSettingsService::HandleCompletedOperation, | |
138 weak_factory_.GetWeakPtr(), base::Closure()))); | |
139 operation->Start(session_manager_client_, owner_key_util_, public_key_); | |
140 } | |
141 | |
132 void DeviceSettingsService::Store( | 142 void DeviceSettingsService::Store( |
133 std::unique_ptr<em::PolicyFetchResponse> policy, | 143 std::unique_ptr<em::PolicyFetchResponse> policy, |
134 const base::Closure& callback) { | 144 const base::Closure& callback) { |
135 // On Active Directory managed devices policy is written only by authpolicyd. | 145 // On Active Directory managed devices policy is written only by authpolicyd. |
136 CHECK(device_mode_ != policy::DEVICE_MODE_ENTERPRISE_AD); | 146 CHECK(device_mode_ != policy::DEVICE_MODE_ENTERPRISE_AD); |
137 Enqueue(linked_ptr<SessionManagerOperation>(new StoreSettingsOperation( | 147 Enqueue(linked_ptr<SessionManagerOperation>(new StoreSettingsOperation( |
138 base::Bind(&DeviceSettingsService::HandleCompletedOperation, | 148 base::Bind(&DeviceSettingsService::HandleCompletedOperation, |
139 weak_factory_.GetWeakPtr(), callback), | 149 weak_factory_.GetWeakPtr(), callback), |
140 std::move(policy)))); | 150 std::move(policy)))); |
141 } | 151 } |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
226 StartNextOperation(); | 236 StartNextOperation(); |
227 } | 237 } |
228 | 238 |
229 void DeviceSettingsService::EnqueueLoad(bool request_key_load) { | 239 void DeviceSettingsService::EnqueueLoad(bool request_key_load) { |
230 bool cloud_validations = true; | 240 bool cloud_validations = true; |
231 if (device_mode_ == policy::DEVICE_MODE_ENTERPRISE_AD) { | 241 if (device_mode_ == policy::DEVICE_MODE_ENTERPRISE_AD) { |
232 request_key_load = false; | 242 request_key_load = false; |
233 cloud_validations = false; | 243 cloud_validations = false; |
234 } | 244 } |
235 linked_ptr<SessionManagerOperation> operation(new LoadSettingsOperation( | 245 linked_ptr<SessionManagerOperation> operation(new LoadSettingsOperation( |
236 request_key_load, cloud_validations, | 246 request_key_load, cloud_validations, false /*force_immediate_load*/, |
Thiemo Nagel
2017/02/28 15:41:05
Nit: pls add blanks: /* force_immediate_load */
| |
237 base::Bind(&DeviceSettingsService::HandleCompletedOperation, | 247 base::Bind(&DeviceSettingsService::HandleCompletedOperation, |
238 weak_factory_.GetWeakPtr(), base::Closure()))); | 248 weak_factory_.GetWeakPtr(), base::Closure()))); |
239 Enqueue(operation); | 249 Enqueue(operation); |
240 } | 250 } |
241 | 251 |
242 void DeviceSettingsService::EnsureReload(bool request_key_load) { | 252 void DeviceSettingsService::EnsureReload(bool request_key_load) { |
243 if (!pending_operations_.empty()) | 253 if (!pending_operations_.empty()) |
244 pending_operations_.front()->RestartLoad(request_key_load); | 254 pending_operations_.front()->RestartLoad(request_key_load); |
245 else | 255 else |
246 EnqueueLoad(request_key_load); | 256 EnqueueLoad(request_key_load); |
247 } | 257 } |
248 | 258 |
249 void DeviceSettingsService::StartNextOperation() { | 259 void DeviceSettingsService::StartNextOperation() { |
250 if (!pending_operations_.empty() && session_manager_client_ && | 260 if (!pending_operations_.empty() && session_manager_client_ && |
251 owner_key_util_.get()) { | 261 owner_key_util_.get()) { |
252 pending_operations_.front()->Start( | 262 pending_operations_.front()->Start( |
253 session_manager_client_, owner_key_util_, public_key_); | 263 session_manager_client_, owner_key_util_, public_key_); |
254 } | 264 } |
255 } | 265 } |
256 | 266 |
257 void DeviceSettingsService::HandleCompletedOperation( | 267 void DeviceSettingsService::HandleCompletedOperation( |
258 const base::Closure& callback, | 268 const base::Closure& callback, |
259 SessionManagerOperation* operation, | 269 SessionManagerOperation* operation, |
260 Status status) { | 270 Status status) { |
261 DCHECK_EQ(operation, pending_operations_.front().get()); | 271 if (!loading_immediately_) |
272 DCHECK_EQ(operation, pending_operations_.front().get()); | |
262 | 273 |
263 store_status_ = status; | 274 store_status_ = status; |
264 if (status == STORE_SUCCESS) { | 275 if (status == STORE_SUCCESS) { |
265 policy_data_ = std::move(operation->policy_data()); | 276 policy_data_ = std::move(operation->policy_data()); |
266 device_settings_ = std::move(operation->device_settings()); | 277 device_settings_ = std::move(operation->device_settings()); |
267 load_retries_left_ = kMaxLoadRetries; | 278 load_retries_left_ = kMaxLoadRetries; |
268 } else if (status != STORE_KEY_UNAVAILABLE) { | 279 } else if (status != STORE_KEY_UNAVAILABLE) { |
269 LOG(ERROR) << "Session manager operation failed: " << status; | 280 LOG(ERROR) << "Session manager operation failed: " << status; |
270 // Validation errors can be temporary if the rtc has gone on holiday for a | 281 // Validation errors can be temporary if the rtc has gone on holiday for a |
271 // short while. So we will retry such loads for up to 10 minutes. | 282 // short while. So we will retry such loads for up to 10 minutes. |
(...skipping 20 matching lines...) Expand all Loading... | |
292 NotifyOwnershipStatusChanged(); | 303 NotifyOwnershipStatusChanged(); |
293 } | 304 } |
294 NotifyDeviceSettingsUpdated(); | 305 NotifyDeviceSettingsUpdated(); |
295 RunPendingOwnershipStatusCallbacks(); | 306 RunPendingOwnershipStatusCallbacks(); |
296 | 307 |
297 // The completion callback happens after the notification so clients can | 308 // The completion callback happens after the notification so clients can |
298 // filter self-triggered updates. | 309 // filter self-triggered updates. |
299 if (!callback.is_null()) | 310 if (!callback.is_null()) |
300 callback.Run(); | 311 callback.Run(); |
301 | 312 |
302 // Only remove the pending operation here, so new operations triggered by any | 313 if (!loading_immediately_) { |
emaxx
2017/02/22 17:24:33
Could we have a separate method for the async oper
Andrew T Wilson (Slow)
2017/02/23 12:05:48
Yes, I'd either do this, or else bind a boolean in
Sergey Poromov
2017/02/28 14:01:17
Done.
Sergey Poromov
2017/02/28 14:01:17
Done.
| |
303 // of the callbacks above are queued up properly. | 314 // Only remove the pending operation here, so new operations triggered by |
304 pending_operations_.pop_front(); | 315 // any of the callbacks above are queued up properly. |
316 pending_operations_.pop_front(); | |
305 | 317 |
306 StartNextOperation(); | 318 StartNextOperation(); |
319 } | |
320 loading_immediately_ = false; | |
307 } | 321 } |
308 | 322 |
309 void DeviceSettingsService::HandleError(Status status, | 323 void DeviceSettingsService::HandleError(Status status, |
310 const base::Closure& callback) { | 324 const base::Closure& callback) { |
311 store_status_ = status; | 325 store_status_ = status; |
312 LOG(ERROR) << "Session manager operation failed: " << status; | 326 LOG(ERROR) << "Session manager operation failed: " << status; |
313 NotifyDeviceSettingsUpdated(); | 327 NotifyDeviceSettingsUpdated(); |
314 | 328 |
315 // The completion callback happens after the notification so clients can | 329 // The completion callback happens after the notification so clients can |
316 // filter self-triggered updates. | 330 // filter self-triggered updates. |
(...skipping 28 matching lines...) Expand all Loading... | |
345 DeviceSettingsService::Initialize(); | 359 DeviceSettingsService::Initialize(); |
346 } | 360 } |
347 | 361 |
348 ScopedTestDeviceSettingsService::~ScopedTestDeviceSettingsService() { | 362 ScopedTestDeviceSettingsService::~ScopedTestDeviceSettingsService() { |
349 // Clean pending operations. | 363 // Clean pending operations. |
350 DeviceSettingsService::Get()->UnsetSessionManager(); | 364 DeviceSettingsService::Get()->UnsetSessionManager(); |
351 DeviceSettingsService::Shutdown(); | 365 DeviceSettingsService::Shutdown(); |
352 } | 366 } |
353 | 367 |
354 } // namespace chromeos | 368 } // namespace chromeos |
OLD | NEW |