OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/browser/chromeos/login/owner_key_reloader.h" |
| 6 |
| 7 #include "base/bind.h" |
| 8 #include "chrome/browser/chrome_notification_types.h" |
| 9 #include "chrome/browser/chromeos/login/user.h" |
| 10 #include "chrome/browser/chromeos/login/user_manager.h" |
| 11 #include "chrome/browser/chromeos/settings/device_settings_service.h" |
| 12 #include "chrome/browser/net/nss_context.h" |
| 13 #include "chrome/browser/profiles/profile.h" |
| 14 #include "content/public/browser/browser_thread.h" |
| 15 #include "content/public/browser/notification_details.h" |
| 16 #include "content/public/browser/notification_service.h" |
| 17 #include "content/public/browser/notification_source.h" |
| 18 #include "content/public/browser/resource_context.h" |
| 19 #include "crypto/scoped_nss_types.h" |
| 20 |
| 21 using content::BrowserThread; |
| 22 |
| 23 namespace chromeos { |
| 24 |
| 25 namespace { |
| 26 |
| 27 void InitiateOwnerKeyLoad(const std::string& username, Profile* profile) { |
| 28 content::ResourceContext* context = |
| 29 profile ? profile->GetResourceContext() : NULL; |
| 30 if (context) { |
| 31 BrowserThread::PostTaskAndReplyWithResult( |
| 32 BrowserThread::IO, |
| 33 FROM_HERE, |
| 34 base::Bind(&GetPublicNSSKeySlotForResourceContext, context), |
| 35 base::Bind(&DeviceSettingsService::InitOwner, |
| 36 base::Unretained(DeviceSettingsService::Get()), |
| 37 username)); |
| 38 } else { |
| 39 crypto::ScopedPK11Slot slot; |
| 40 DeviceSettingsService::Get()->InitOwner(username, slot.Pass()); |
| 41 } |
| 42 } |
| 43 |
| 44 } // namespace |
| 45 |
| 46 OwnerKeyReloader::OwnerKeyReloader() { |
| 47 registrar_.Add(this, |
| 48 chrome::NOTIFICATION_PROFILE_CREATED, |
| 49 content::NotificationService::AllSources()); |
| 50 } |
| 51 |
| 52 OwnerKeyReloader::~OwnerKeyReloader() { |
| 53 } |
| 54 |
| 55 void OwnerKeyReloader::Observe(int type, |
| 56 const content::NotificationSource& source, |
| 57 const content::NotificationDetails& details) { |
| 58 if (type != chrome::NOTIFICATION_LOGIN_USER_PROFILE_PREPARED) { |
| 59 NOTREACHED(); |
| 60 return; |
| 61 } |
| 62 if (!UserManager::IsInitialized()) |
| 63 return; |
| 64 Profile* profile = content::Details<Profile>(details).ptr(); |
| 65 const User* user = UserManager::Get()->GetUserByProfile(profile); |
| 66 if (user && user->email() == username_) |
| 67 InitiateOwnerKeyLoad(username_, profile); |
| 68 } |
| 69 |
| 70 void OwnerKeyReloader::ReloadOwnerKey(const std::string& username) { |
| 71 username_ = username; |
| 72 if (!UserManager::IsInitialized()) |
| 73 return; |
| 74 const User* user = UserManager::Get()->FindUser(username_); |
| 75 if (user && user->is_profile_created()) { |
| 76 Profile* profile = UserManager::Get()->GetProfileByUser(user); |
| 77 InitiateOwnerKeyLoad(username_, profile); |
| 78 } |
| 79 } |
| 80 |
| 81 } // namespace chromeos |
OLD | NEW |