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

Unified Diff: chrome/browser/chromeos/login/owner_key_reloader_service.cc

Issue 270663002: Implemented profile-aware owner key loading. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixed tests. Created 6 years, 7 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/chromeos/login/owner_key_reloader_service.cc
diff --git a/chrome/browser/chromeos/login/owner_key_reloader_service.cc b/chrome/browser/chromeos/login/owner_key_reloader_service.cc
new file mode 100644
index 0000000000000000000000000000000000000000..e86823342b220ef07f4029113ce9188c95d54cd8
--- /dev/null
+++ b/chrome/browser/chromeos/login/owner_key_reloader_service.cc
@@ -0,0 +1,72 @@
+// 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_service.h"
+
+#include "base/bind.h"
+#include "chrome/browser/chromeos/login/owner_key_reloader_service_factory.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/resource_context.h"
+#include "crypto/scoped_nss_types.h"
+
+using content::BrowserThread;
+
+namespace chromeos {
+
+std::string OwnerKeyReloaderService::username_;
Mattias Nissler (ping if slow) 2014/05/14 12:18:10 Static non-POD members are outlawed (unless someth
ygorshenin1 2014/05/14 15:30:07 Done.
+
+OwnerKeyReloaderService::OwnerKeyReloaderService(Profile* profile)
+ : profile_(profile) {
Mattias Nissler (ping if slow) 2014/05/14 12:18:10 I usually advice people against passing a Profile
ygorshenin1 2014/05/14 15:30:07 Unfortunately ResourceContext is not ready at the
Mattias Nissler (ping if slow) 2014/05/14 16:00:36 Hm, too bad :-/ Let's go with a Profile pointer th
+}
+
+OwnerKeyReloaderService::~OwnerKeyReloaderService() {
+}
+
+// static
+void OwnerKeyReloaderService::SetUsername(const std::string& username) {
Mattias Nissler (ping if slow) 2014/05/14 12:18:10 Let's check whether we're on the same page here: I
ygorshenin1 2014/05/14 15:30:07 Done.
+ username_ = username;
+ if (!UserManager::IsInitialized())
Mattias Nissler (ping if slow) 2014/05/14 12:18:10 Is this just for unit tests?
ygorshenin1 2014/05/14 15:30:07 Yes, it's just for unit tests. On 2014/05/14 12:1
+ return;
+ const User* user = UserManager::Get()->FindUser(username);
+ if (!user || !user->is_profile_created())
+ return;
+ Profile* profile = UserManager::Get()->GetProfileByUser(user);
+ if (!profile)
+ return;
+ OwnerKeyReloaderServiceFactory::GetForProfile(profile)->ReloadOwnerKey();
+}
+
+// static
+std::string OwnerKeyReloaderService::GetUsername() {
+ return username_;
+}
+
+void OwnerKeyReloaderService::ReloadOwnerKey() {
+ if (!UserManager::IsInitialized() || !profile_)
+ return;
+ const User* user = UserManager::Get()->GetUserByProfile(profile_);
+ if (!user || user->email() != GetUsername())
+ return;
+ 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()),
+ GetUsername()));
+ } else {
+ crypto::ScopedPK11Slot slot;
+ DeviceSettingsService::Get()->InitOwner(GetUsername(), slot.Pass());
+ }
+}
+
+} // namespace chromeos

Powered by Google App Engine
This is Rietveld 408576698