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

Side by Side Diff: chrome/browser/chromeos/ownership/owner_settings_service.cc

Issue 419013003: Replace c/b/nss_context by a KeyedService. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Added Linux implementation. Created 6 years, 3 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 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/path_service.h" 12 #include "base/path_service.h"
13 #include "base/prefs/pref_service.h" 13 #include "base/prefs/pref_service.h"
14 #include "chrome/browser/chrome_notification_types.h" 14 #include "chrome/browser/chrome_notification_types.h"
15 #include "chrome/browser/chromeos/ownership/owner_settings_service_factory.h" 15 #include "chrome/browser/chromeos/ownership/owner_settings_service_factory.h"
16 #include "chrome/browser/chromeos/profiles/profile_helper.h" 16 #include "chrome/browser/chromeos/profiles/profile_helper.h"
17 #include "chrome/browser/chromeos/settings/cros_settings.h" 17 #include "chrome/browser/chromeos/settings/cros_settings.h"
18 #include "chrome/browser/chromeos/settings/session_manager_operation.h" 18 #include "chrome/browser/chromeos/settings/session_manager_operation.h"
19 #include "chrome/browser/profiles/profile.h" 19 #include "chrome/browser/profiles/profile.h"
20 #include "chromeos/chromeos_paths.h" 20 #include "chromeos/chromeos_paths.h"
21 #include "chromeos/dbus/dbus_thread_manager.h" 21 #include "chromeos/dbus/dbus_thread_manager.h"
22 #include "chromeos/tpm_token_loader.h"
22 #include "components/ownership/owner_key_util_impl.h" 23 #include "components/ownership/owner_key_util_impl.h"
23 #include "components/policy/core/common/cloud/cloud_policy_constants.h" 24 #include "components/policy/core/common/cloud/cloud_policy_constants.h"
24 #include "content/public/browser/browser_thread.h" 25 #include "content/public/browser/browser_thread.h"
25 #include "content/public/browser/notification_details.h" 26 #include "content/public/browser/notification_details.h"
26 #include "content/public/browser/notification_service.h" 27 #include "content/public/browser/notification_service.h"
27 #include "content/public/browser/notification_source.h" 28 #include "content/public/browser/notification_source.h"
28 #include "content/public/common/content_switches.h" 29 #include "content/public/common/content_switches.h"
29 #include "crypto/nss_util.h" 30 #include "crypto/nss_util.h"
30 #include "crypto/nss_util_internal.h" 31 #include "crypto/nss_util_internal.h"
31 #include "crypto/rsa_private_key.h" 32 #include "crypto/rsa_private_key.h"
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after
241 242
242 } // namespace 243 } // namespace
243 244
244 OwnerSettingsService::OwnerSettingsService(Profile* profile) 245 OwnerSettingsService::OwnerSettingsService(Profile* profile)
245 : profile_(profile), 246 : profile_(profile),
246 owner_key_util_(MakeOwnerKeyUtil()), 247 owner_key_util_(MakeOwnerKeyUtil()),
247 waiting_for_profile_creation_(true), 248 waiting_for_profile_creation_(true),
248 waiting_for_tpm_token_(true), 249 waiting_for_tpm_token_(true),
249 weak_factory_(this) { 250 weak_factory_(this) {
250 if (TPMTokenLoader::IsInitialized()) { 251 if (TPMTokenLoader::IsInitialized()) {
251 waiting_for_tpm_token_ = !TPMTokenLoader::Get()->IsTPMTokenReady(); 252 TPMTokenLoader::TPMTokenStatus tpm_token_status =
252 TPMTokenLoader::Get()->AddObserver(this); 253 TPMTokenLoader::Get()->IsTPMTokenEnabled(
254 base::Bind(&OwnerSettingsService::OnTPMTokenReady, as_weak_ptr()));
255 waiting_for_tpm_token_ =
256 tpm_token_status == TPMTokenLoader::TPM_TOKEN_STATUS_UNDETERMINED;
253 } 257 }
254 258
255 if (DBusThreadManager::IsInitialized() && 259 if (DBusThreadManager::IsInitialized() &&
256 DBusThreadManager::Get()->GetSessionManagerClient()) { 260 DBusThreadManager::Get()->GetSessionManagerClient()) {
257 DBusThreadManager::Get()->GetSessionManagerClient()->AddObserver(this); 261 DBusThreadManager::Get()->GetSessionManagerClient()->AddObserver(this);
258 } 262 }
259 263
260 registrar_.Add(this, 264 registrar_.Add(this,
261 chrome::NOTIFICATION_PROFILE_CREATED, 265 chrome::NOTIFICATION_PROFILE_CREATED,
262 content::Source<Profile>(profile_)); 266 content::Source<Profile>(profile_));
263 } 267 }
264 268
265 OwnerSettingsService::~OwnerSettingsService() { 269 OwnerSettingsService::~OwnerSettingsService() {
266 DCHECK(thread_checker_.CalledOnValidThread()); 270 DCHECK(thread_checker_.CalledOnValidThread());
267 if (TPMTokenLoader::IsInitialized())
268 TPMTokenLoader::Get()->RemoveObserver(this);
269
270 if (DBusThreadManager::IsInitialized() && 271 if (DBusThreadManager::IsInitialized() &&
271 DBusThreadManager::Get()->GetSessionManagerClient()) { 272 DBusThreadManager::Get()->GetSessionManagerClient()) {
272 DBusThreadManager::Get()->GetSessionManagerClient()->RemoveObserver(this); 273 DBusThreadManager::Get()->GetSessionManagerClient()->RemoveObserver(this);
273 } 274 }
274 } 275 }
275 276
276 bool OwnerSettingsService::IsOwner() { 277 bool OwnerSettingsService::IsOwner() {
277 DCHECK(thread_checker_.CalledOnValidThread()); 278 DCHECK(thread_checker_.CalledOnValidThread());
278 return private_key_ && private_key_->key(); 279 return private_key_ && private_key_->key();
279 } 280 }
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
359 Profile* profile = content::Source<Profile>(source).ptr(); 360 Profile* profile = content::Source<Profile>(source).ptr();
360 if (profile != profile_) { 361 if (profile != profile_) {
361 NOTREACHED(); 362 NOTREACHED();
362 return; 363 return;
363 } 364 }
364 365
365 waiting_for_profile_creation_ = false; 366 waiting_for_profile_creation_ = false;
366 ReloadPrivateKey(); 367 ReloadPrivateKey();
367 } 368 }
368 369
369 void OwnerSettingsService::OnTPMTokenReady() { 370 void OwnerSettingsService::OnTPMTokenReady(bool token_enabled) {
370 DCHECK(thread_checker_.CalledOnValidThread()); 371 DCHECK(thread_checker_.CalledOnValidThread());
371 waiting_for_tpm_token_ = false; 372 waiting_for_tpm_token_ = false;
372 373
373 // TPMTokenLoader initializes the TPM and NSS database which is necessary to 374 // TPMTokenLoader initializes the TPM and NSS database which is necessary to
374 // determine ownership. Force a reload once we know these are initialized. 375 // determine ownership. Force a reload once we know these are initialized.
375 ReloadPrivateKey(); 376 ReloadPrivateKey();
376 } 377 }
377 378
378 void OwnerSettingsService::OwnerKeySet(bool success) { 379 void OwnerSettingsService::OwnerKeySet(bool success) {
379 DCHECK(thread_checker_.CalledOnValidThread()); 380 DCHECK(thread_checker_.CalledOnValidThread());
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
538 DeviceSettingsService* OwnerSettingsService::GetDeviceSettingsService() { 539 DeviceSettingsService* OwnerSettingsService::GetDeviceSettingsService() {
539 DCHECK(thread_checker_.CalledOnValidThread()); 540 DCHECK(thread_checker_.CalledOnValidThread());
540 if (g_device_settings_service_for_testing) 541 if (g_device_settings_service_for_testing)
541 return g_device_settings_service_for_testing; 542 return g_device_settings_service_for_testing;
542 if (DeviceSettingsService::IsInitialized()) 543 if (DeviceSettingsService::IsInitialized())
543 return DeviceSettingsService::Get(); 544 return DeviceSettingsService::Get();
544 return NULL; 545 return NULL;
545 } 546 }
546 547
547 } // namespace chromeos 548 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698