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 "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
10 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
11 #include "base/time/time.h" | 11 #include "base/time/time.h" |
12 #include "chrome/browser/chrome_notification_types.h" | 12 #include "chrome/browser/chrome_notification_types.h" |
13 #include "chrome/browser/chrome_notification_types.h" | |
14 #include "chrome/browser/chromeos/login/user.h" | |
15 #include "chrome/browser/chromeos/login/user_manager.h" | |
13 #include "chrome/browser/chromeos/policy/proto/chrome_device_policy.pb.h" | 16 #include "chrome/browser/chromeos/policy/proto/chrome_device_policy.pb.h" |
14 #include "chrome/browser/chromeos/settings/owner_key_util.h" | 17 #include "chrome/browser/chromeos/settings/owner_key_util.h" |
15 #include "chrome/browser/chromeos/settings/session_manager_operation.h" | 18 #include "chrome/browser/chromeos/settings/session_manager_operation.h" |
16 #include "components/policy/core/common/cloud/cloud_policy_constants.h" | 19 #include "components/policy/core/common/cloud/cloud_policy_constants.h" |
17 #include "content/public/browser/browser_thread.h" | 20 #include "content/public/browser/browser_thread.h" |
18 #include "content/public/browser/notification_service.h" | 21 #include "content/public/browser/notification_service.h" |
19 #include "content/public/browser/notification_source.h" | 22 #include "content/public/browser/notification_source.h" |
20 #include "crypto/rsa_private_key.h" | 23 #include "crypto/rsa_private_key.h" |
21 | 24 |
22 namespace em = enterprise_management; | 25 namespace em = enterprise_management; |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
75 : session_manager_client_(NULL), | 78 : session_manager_client_(NULL), |
76 store_status_(STORE_SUCCESS), | 79 store_status_(STORE_SUCCESS), |
77 waiting_for_tpm_token_(true), | 80 waiting_for_tpm_token_(true), |
78 owner_key_loaded_with_tpm_token_(false), | 81 owner_key_loaded_with_tpm_token_(false), |
79 load_retries_left_(kMaxLoadRetries), | 82 load_retries_left_(kMaxLoadRetries), |
80 weak_factory_(this) { | 83 weak_factory_(this) { |
81 if (TPMTokenLoader::IsInitialized()) { | 84 if (TPMTokenLoader::IsInitialized()) { |
82 waiting_for_tpm_token_ = !TPMTokenLoader::Get()->IsTPMTokenReady(); | 85 waiting_for_tpm_token_ = !TPMTokenLoader::Get()->IsTPMTokenReady(); |
83 TPMTokenLoader::Get()->AddObserver(this); | 86 TPMTokenLoader::Get()->AddObserver(this); |
84 } | 87 } |
88 registrar_.Add(this, | |
89 chrome::NOTIFICATION_PROFILE_ADDED, | |
90 content::NotificationService::AllSources()); | |
85 } | 91 } |
86 | 92 |
87 DeviceSettingsService::~DeviceSettingsService() { | 93 DeviceSettingsService::~DeviceSettingsService() { |
88 DCHECK(pending_operations_.empty()); | 94 DCHECK(pending_operations_.empty()); |
89 if (TPMTokenLoader::IsInitialized()) | 95 if (TPMTokenLoader::IsInitialized()) |
90 TPMTokenLoader::Get()->RemoveObserver(this); | 96 TPMTokenLoader::Get()->RemoveObserver(this); |
91 } | 97 } |
92 | 98 |
93 void DeviceSettingsService::SetSessionManager( | 99 void DeviceSettingsService::SetSessionManager( |
94 SessionManagerClient* session_manager_client, | 100 SessionManagerClient* session_manager_client, |
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
272 } | 278 } |
273 | 279 |
274 void DeviceSettingsService::OnTPMTokenReady() { | 280 void DeviceSettingsService::OnTPMTokenReady() { |
275 waiting_for_tpm_token_ = false; | 281 waiting_for_tpm_token_ = false; |
276 | 282 |
277 // TPMTokenLoader initializes the TPM and NSS database which is necessary to | 283 // TPMTokenLoader initializes the TPM and NSS database which is necessary to |
278 // determine ownership. Force a reload once we know these are initialized. | 284 // determine ownership. Force a reload once we know these are initialized. |
279 EnsureReload(true); | 285 EnsureReload(true); |
280 } | 286 } |
281 | 287 |
288 void DeviceSettingsService::Observe( | |
289 int type, | |
290 const content::NotificationSource& source, | |
291 const content::NotificationDetails& details) { | |
292 if (type != chrome::NOTIFICATION_PROFILE_ADDED) { | |
293 NOTREACHED(); | |
294 return; | |
295 } | |
296 Profile* profile = content::Source<Profile>(source).ptr(); | |
Mattias Nissler (ping if slow)
2014/05/12 08:26:43
chrome/browser/chromeos/settings deliberately does
ygorshenin1
2014/05/12 08:35:43
You mean to directly pass NSS slot instead of user
Mattias Nissler (ping if slow)
2014/05/12 08:40:31
Yes, my idea was indeed to pass the NSS slot refer
ygorshenin1
2014/05/12 08:56:54
SignAndStore() is implicitly called from DeviceSet
ygorshenin1
2014/05/13 09:46:13
All User/Profile-related things are extracted into
| |
297 if (!profile || !UserManager::IsInitialized()) | |
298 return; | |
299 const User* user = UserManager::Get()->GetUserByProfile(profile); | |
300 if (user && user->email() == username_ && user->is_logged_in()) { | |
301 owner_key_ = NULL; | |
302 EnsureReload(true); | |
303 } | |
304 } | |
305 | |
282 void DeviceSettingsService::Enqueue(SessionManagerOperation* operation) { | 306 void DeviceSettingsService::Enqueue(SessionManagerOperation* operation) { |
283 pending_operations_.push_back(operation); | 307 pending_operations_.push_back(operation); |
284 if (pending_operations_.front() == operation) | 308 if (pending_operations_.front() == operation) |
285 StartNextOperation(); | 309 StartNextOperation(); |
286 } | 310 } |
287 | 311 |
288 void DeviceSettingsService::EnqueueLoad(bool force_key_load) { | 312 void DeviceSettingsService::EnqueueLoad(bool force_key_load) { |
289 SessionManagerOperation* operation = | 313 SessionManagerOperation* operation = |
290 new LoadSettingsOperation( | 314 new LoadSettingsOperation( |
291 base::Bind(&DeviceSettingsService::HandleCompletedOperation, | 315 base::Bind(&DeviceSettingsService::HandleCompletedOperation, |
292 weak_factory_.GetWeakPtr(), | 316 weak_factory_.GetWeakPtr(), |
293 base::Closure())); | 317 base::Closure())); |
294 operation->set_force_key_load(force_key_load); | 318 operation->set_force_key_load(force_key_load); |
319 operation->set_username(username_); | |
295 Enqueue(operation); | 320 Enqueue(operation); |
296 } | 321 } |
297 | 322 |
298 void DeviceSettingsService::EnsureReload(bool force_key_load) { | 323 void DeviceSettingsService::EnsureReload(bool force_key_load) { |
299 if (!pending_operations_.empty()) | 324 if (!pending_operations_.empty()) { |
325 pending_operations_.front()->set_username(username_); | |
300 pending_operations_.front()->RestartLoad(force_key_load); | 326 pending_operations_.front()->RestartLoad(force_key_load); |
301 else | 327 } else { |
302 EnqueueLoad(force_key_load); | 328 EnqueueLoad(force_key_load); |
329 } | |
303 } | 330 } |
304 | 331 |
305 void DeviceSettingsService::StartNextOperation() { | 332 void DeviceSettingsService::StartNextOperation() { |
306 if (!pending_operations_.empty() && | 333 if (!pending_operations_.empty() && |
307 session_manager_client_ && | 334 session_manager_client_ && |
308 owner_key_util_.get()) { | 335 owner_key_util_.get()) { |
309 pending_operations_.front()->Start(session_manager_client_, | 336 pending_operations_.front()->Start(session_manager_client_, |
310 owner_key_util_, owner_key_); | 337 owner_key_util_, owner_key_); |
311 } | 338 } |
312 } | 339 } |
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
474 DeviceSettingsService::Initialize(); | 501 DeviceSettingsService::Initialize(); |
475 } | 502 } |
476 | 503 |
477 ScopedTestDeviceSettingsService::~ScopedTestDeviceSettingsService() { | 504 ScopedTestDeviceSettingsService::~ScopedTestDeviceSettingsService() { |
478 // Clean pending operations. | 505 // Clean pending operations. |
479 DeviceSettingsService::Get()->UnsetSessionManager(); | 506 DeviceSettingsService::Get()->UnsetSessionManager(); |
480 DeviceSettingsService::Shutdown(); | 507 DeviceSettingsService::Shutdown(); |
481 } | 508 } |
482 | 509 |
483 } // namespace chromeos | 510 } // namespace chromeos |
OLD | NEW |