| Index: chrome/browser/chromeos/login/owner_key_reloader.cc
|
| diff --git a/chrome/browser/chromeos/login/owner_key_reloader.cc b/chrome/browser/chromeos/login/owner_key_reloader.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..7b6f8600ed07a01d269ab7c251e417d476df138e
|
| --- /dev/null
|
| +++ b/chrome/browser/chromeos/login/owner_key_reloader.cc
|
| @@ -0,0 +1,81 @@
|
| +// Copyright 2014 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#include "chrome/browser/chromeos/login/owner_key_reloader.h"
|
| +
|
| +#include "base/bind.h"
|
| +#include "chrome/browser/chrome_notification_types.h"
|
| +#include "chrome/browser/chromeos/login/user.h"
|
| +#include "chrome/browser/chromeos/login/user_manager.h"
|
| +#include "chrome/browser/chromeos/settings/device_settings_service.h"
|
| +#include "chrome/browser/net/nss_context.h"
|
| +#include "chrome/browser/profiles/profile.h"
|
| +#include "content/public/browser/browser_thread.h"
|
| +#include "content/public/browser/notification_details.h"
|
| +#include "content/public/browser/notification_service.h"
|
| +#include "content/public/browser/notification_source.h"
|
| +#include "content/public/browser/resource_context.h"
|
| +#include "crypto/scoped_nss_types.h"
|
| +
|
| +using content::BrowserThread;
|
| +
|
| +namespace chromeos {
|
| +
|
| +namespace {
|
| +
|
| +void InitiateOwnerKeyLoad(const std::string& username, Profile* profile) {
|
| + content::ResourceContext* context =
|
| + profile ? profile->GetResourceContext() : NULL;
|
| + if (context) {
|
| + BrowserThread::PostTaskAndReplyWithResult(
|
| + BrowserThread::IO,
|
| + FROM_HERE,
|
| + base::Bind(&GetPublicNSSKeySlotForResourceContext, context),
|
| + base::Bind(&DeviceSettingsService::InitOwner,
|
| + base::Unretained(DeviceSettingsService::Get()),
|
| + username));
|
| + } else {
|
| + crypto::ScopedPK11Slot slot;
|
| + DeviceSettingsService::Get()->InitOwner(username, slot.Pass());
|
| + }
|
| +}
|
| +
|
| +} // namespace
|
| +
|
| +OwnerKeyReloader::OwnerKeyReloader() {
|
| + registrar_.Add(this,
|
| + chrome::NOTIFICATION_PROFILE_CREATED,
|
| + content::NotificationService::AllSources());
|
| +}
|
| +
|
| +OwnerKeyReloader::~OwnerKeyReloader() {
|
| +}
|
| +
|
| +void OwnerKeyReloader::Observe(int type,
|
| + const content::NotificationSource& source,
|
| + const content::NotificationDetails& details) {
|
| + if (type != chrome::NOTIFICATION_LOGIN_USER_PROFILE_PREPARED) {
|
| + NOTREACHED();
|
| + return;
|
| + }
|
| + if (!UserManager::IsInitialized())
|
| + return;
|
| + Profile* profile = content::Details<Profile>(details).ptr();
|
| + const User* user = UserManager::Get()->GetUserByProfile(profile);
|
| + if (user && user->email() == username_)
|
| + InitiateOwnerKeyLoad(username_, profile);
|
| +}
|
| +
|
| +void OwnerKeyReloader::ReloadOwnerKey(const std::string& username) {
|
| + username_ = username;
|
| + if (!UserManager::IsInitialized())
|
| + return;
|
| + const User* user = UserManager::Get()->FindUser(username_);
|
| + if (user && user->is_profile_created()) {
|
| + Profile* profile = UserManager::Get()->GetProfileByUser(user);
|
| + InitiateOwnerKeyLoad(username_, profile);
|
| + }
|
| +}
|
| +
|
| +} // namespace chromeos
|
|
|