Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/ownership/owner_settings_service.h" | 5 #include "chrome/browser/chromeos/ownership/owner_settings_service.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
| 11 #include "base/command_line.h" | 11 #include "base/command_line.h" |
| 12 #include "base/prefs/pref_service.h" | 12 #include "base/prefs/pref_service.h" |
| 13 #include "chrome/browser/chrome_notification_types.h" | 13 #include "chrome/browser/chrome_notification_types.h" |
| 14 #include "chrome/browser/chromeos/profiles/profile_helper.h" | 14 #include "chrome/browser/chromeos/profiles/profile_helper.h" |
| 15 #include "chrome/browser/chromeos/settings/cros_settings.h" | 15 #include "chrome/browser/chromeos/settings/cros_settings.h" |
| 16 #include "chrome/browser/chromeos/settings/session_manager_operation.h" | 16 #include "chrome/browser/chromeos/settings/session_manager_operation.h" |
| 17 #include "chrome/browser/profiles/profile.h" | 17 #include "chrome/browser/profiles/profile.h" |
| 18 #include "chromeos/dbus/dbus_thread_manager.h" | 18 #include "chromeos/dbus/dbus_thread_manager.h" |
| 19 #include "chromeos/tpm_token_loader.h" | |
| 19 #include "components/policy/core/common/cloud/cloud_policy_constants.h" | 20 #include "components/policy/core/common/cloud/cloud_policy_constants.h" |
| 20 #include "content/public/browser/browser_thread.h" | 21 #include "content/public/browser/browser_thread.h" |
| 21 #include "content/public/browser/notification_details.h" | 22 #include "content/public/browser/notification_details.h" |
| 22 #include "content/public/browser/notification_service.h" | 23 #include "content/public/browser/notification_service.h" |
| 23 #include "content/public/browser/notification_source.h" | 24 #include "content/public/browser/notification_source.h" |
| 24 #include "content/public/common/content_switches.h" | 25 #include "content/public/common/content_switches.h" |
| 25 #include "crypto/nss_util.h" | 26 #include "crypto/nss_util.h" |
| 26 #include "crypto/nss_util_internal.h" | 27 #include "crypto/nss_util_internal.h" |
| 27 #include "crypto/rsa_private_key.h" | 28 #include "crypto/rsa_private_key.h" |
| 28 #include "crypto/scoped_nss_types.h" | 29 #include "crypto/scoped_nss_types.h" |
| (...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 234 | 235 |
| 235 OwnerSettingsService::OwnerSettingsService( | 236 OwnerSettingsService::OwnerSettingsService( |
| 236 Profile* profile, | 237 Profile* profile, |
| 237 const scoped_refptr<OwnerKeyUtil>& owner_key_util) | 238 const scoped_refptr<OwnerKeyUtil>& owner_key_util) |
| 238 : profile_(profile), | 239 : profile_(profile), |
| 239 owner_key_util_(owner_key_util), | 240 owner_key_util_(owner_key_util), |
| 240 waiting_for_profile_creation_(true), | 241 waiting_for_profile_creation_(true), |
| 241 waiting_for_tpm_token_(true), | 242 waiting_for_tpm_token_(true), |
| 242 weak_factory_(this) { | 243 weak_factory_(this) { |
| 243 if (TPMTokenLoader::IsInitialized()) { | 244 if (TPMTokenLoader::IsInitialized()) { |
| 244 waiting_for_tpm_token_ = !TPMTokenLoader::Get()->IsTPMTokenReady(); | 245 TPMTokenLoader::TPMTokenStatus tpm_token_status = |
| 245 TPMTokenLoader::Get()->AddObserver(this); | 246 TPMTokenLoader::Get()->IsTPMTokenEnabled( |
| 247 base::Bind(&OwnerSettingsService::OnTPMTokenReady, as_weak_ptr())); | |
| 248 waiting_for_tpm_token_ = | |
| 249 tpm_token_status == TPMTokenLoader::TPM_TOKEN_STATUS_UNDETERMINED; | |
| 246 } | 250 } |
| 247 | 251 |
| 248 if (DBusThreadManager::IsInitialized() && | 252 if (DBusThreadManager::IsInitialized() && |
| 249 DBusThreadManager::Get()->GetSessionManagerClient()) { | 253 DBusThreadManager::Get()->GetSessionManagerClient()) { |
| 250 DBusThreadManager::Get()->GetSessionManagerClient()->AddObserver(this); | 254 DBusThreadManager::Get()->GetSessionManagerClient()->AddObserver(this); |
| 251 } | 255 } |
| 252 | 256 |
| 253 registrar_.Add(this, | 257 registrar_.Add(this, |
| 254 chrome::NOTIFICATION_PROFILE_CREATED, | 258 chrome::NOTIFICATION_PROFILE_CREATED, |
| 255 content::Source<Profile>(profile_)); | 259 content::Source<Profile>(profile_)); |
| 256 } | 260 } |
| 257 | 261 |
| 258 OwnerSettingsService::~OwnerSettingsService() { | 262 OwnerSettingsService::~OwnerSettingsService() { |
| 259 DCHECK(thread_checker_.CalledOnValidThread()); | 263 DCHECK(thread_checker_.CalledOnValidThread()); |
| 260 if (TPMTokenLoader::IsInitialized()) | |
| 261 TPMTokenLoader::Get()->RemoveObserver(this); | |
| 262 | |
| 263 if (DBusThreadManager::IsInitialized() && | 264 if (DBusThreadManager::IsInitialized() && |
| 264 DBusThreadManager::Get()->GetSessionManagerClient()) { | 265 DBusThreadManager::Get()->GetSessionManagerClient()) { |
| 265 DBusThreadManager::Get()->GetSessionManagerClient()->RemoveObserver(this); | 266 DBusThreadManager::Get()->GetSessionManagerClient()->RemoveObserver(this); |
| 266 } | 267 } |
| 267 } | 268 } |
| 268 | 269 |
| 269 bool OwnerSettingsService::IsOwner() { | 270 bool OwnerSettingsService::IsOwner() { |
| 270 DCHECK(thread_checker_.CalledOnValidThread()); | 271 DCHECK(thread_checker_.CalledOnValidThread()); |
| 271 return private_key_ && private_key_->key(); | 272 return private_key_ && private_key_->key(); |
| 272 } | 273 } |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 352 Profile* profile = content::Source<Profile>(source).ptr(); | 353 Profile* profile = content::Source<Profile>(source).ptr(); |
| 353 if (profile != profile_) { | 354 if (profile != profile_) { |
| 354 NOTREACHED(); | 355 NOTREACHED(); |
| 355 return; | 356 return; |
| 356 } | 357 } |
| 357 | 358 |
| 358 waiting_for_profile_creation_ = false; | 359 waiting_for_profile_creation_ = false; |
| 359 ReloadPrivateKey(); | 360 ReloadPrivateKey(); |
| 360 } | 361 } |
| 361 | 362 |
| 362 void OwnerSettingsService::OnTPMTokenReady() { | 363 void OwnerSettingsService::OnTPMTokenReady(bool token_enabled) { |
|
stevenjb
2014/09/11 18:16:55
nit: (bool /* unused token_enabled */)
pneubeck (no reviews)
2014/09/11 18:49:11
Done.
| |
| 363 DCHECK(thread_checker_.CalledOnValidThread()); | 364 DCHECK(thread_checker_.CalledOnValidThread()); |
| 364 waiting_for_tpm_token_ = false; | 365 waiting_for_tpm_token_ = false; |
| 365 | 366 |
| 366 // TPMTokenLoader initializes the TPM and NSS database which is necessary to | 367 // TPMTokenLoader initializes the TPM and NSS database which is necessary to |
| 367 // determine ownership. Force a reload once we know these are initialized. | 368 // determine ownership. Force a reload once we know these are initialized. |
| 368 ReloadPrivateKey(); | 369 ReloadPrivateKey(); |
| 369 } | 370 } |
| 370 | 371 |
| 371 void OwnerSettingsService::OwnerKeySet(bool success) { | 372 void OwnerSettingsService::OwnerKeySet(bool success) { |
| 372 DCHECK(thread_checker_.CalledOnValidThread()); | 373 DCHECK(thread_checker_.CalledOnValidThread()); |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 507 DeviceSettingsService* OwnerSettingsService::GetDeviceSettingsService() { | 508 DeviceSettingsService* OwnerSettingsService::GetDeviceSettingsService() { |
| 508 DCHECK(thread_checker_.CalledOnValidThread()); | 509 DCHECK(thread_checker_.CalledOnValidThread()); |
| 509 if (g_device_settings_service_for_testing) | 510 if (g_device_settings_service_for_testing) |
| 510 return g_device_settings_service_for_testing; | 511 return g_device_settings_service_for_testing; |
| 511 if (DeviceSettingsService::IsInitialized()) | 512 if (DeviceSettingsService::IsInitialized()) |
| 512 return DeviceSettingsService::Get(); | 513 return DeviceSettingsService::Get(); |
| 513 return NULL; | 514 return NULL; |
| 514 } | 515 } |
| 515 | 516 |
| 516 } // namespace chromeos | 517 } // namespace chromeos |
| OLD | NEW |