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/ownership/owner_settings_service.h" |
| 6 |
| 7 #include <string> |
| 8 |
| 9 #include "base/bind.h" |
| 10 #include "chrome/browser/chrome_notification_types.h" |
| 11 #include "chrome/browser/chromeos/login/users/user.h" |
| 12 #include "chrome/browser/chromeos/login/users/user_manager.h" |
| 13 #include "chrome/browser/chromeos/ownership/owner_settings_service_factory.h" |
| 14 #include "chrome/browser/chromeos/settings/device_settings_service.h" |
| 15 #include "chrome/browser/profiles/profile.h" |
| 16 #include "content/public/browser/browser_thread.h" |
| 17 #include "content/public/browser/notification_details.h" |
| 18 #include "content/public/browser/notification_source.h" |
| 19 #include "crypto/nss_util_internal.h" |
| 20 #include "crypto/scoped_nss_types.h" |
| 21 |
| 22 using content::BrowserThread; |
| 23 |
| 24 namespace chromeos { |
| 25 |
| 26 OwnerSettingsService::OwnerSettingsService(Profile* profile) |
| 27 : profile_(profile), weak_factory_(this) { |
| 28 registrar_.Add(this, |
| 29 chrome::NOTIFICATION_PROFILE_CREATED, |
| 30 content::Source<Profile>(profile_)); |
| 31 } |
| 32 |
| 33 OwnerSettingsService::~OwnerSettingsService() { |
| 34 } |
| 35 |
| 36 void OwnerSettingsService::Observe( |
| 37 int type, |
| 38 const content::NotificationSource& source, |
| 39 const content::NotificationDetails& details) { |
| 40 if (type != chrome::NOTIFICATION_PROFILE_CREATED) { |
| 41 NOTREACHED(); |
| 42 return; |
| 43 } |
| 44 |
| 45 Profile* profile = content::Source<Profile>(source).ptr(); |
| 46 if (profile != profile_) { |
| 47 NOTREACHED(); |
| 48 return; |
| 49 } |
| 50 |
| 51 ReloadOwnerKey(); |
| 52 } |
| 53 |
| 54 void OwnerSettingsService::ReloadOwnerKey() { |
| 55 if (!UserManager::IsInitialized()) |
| 56 return; |
| 57 const User* user = UserManager::Get()->GetUserByProfile(profile_); |
| 58 if (!user || !user->is_profile_created()) |
| 59 return; |
| 60 std::string user_id = user->email(); |
| 61 if (user_id != OwnerSettingsServiceFactory::GetInstance()->GetUsername()) |
| 62 return; |
| 63 BrowserThread::PostTaskAndReplyWithResult( |
| 64 BrowserThread::IO, |
| 65 FROM_HERE, |
| 66 base::Bind(&crypto::GetPublicSlotForChromeOSUser, user->username_hash()), |
| 67 base::Bind(&DeviceSettingsService::InitOwner, |
| 68 base::Unretained(DeviceSettingsService::Get()), |
| 69 user_id)); |
| 70 } |
| 71 |
| 72 } // namespace chromeos |
OLD | NEW |