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

Unified Diff: chrome/browser/chromeos/ownership/owner_settings_service.cc

Issue 270663002: Implemented profile-aware owner key loading. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixes, rebase. 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/ownership/owner_settings_service.cc
diff --git a/chrome/browser/chromeos/ownership/owner_settings_service.cc b/chrome/browser/chromeos/ownership/owner_settings_service.cc
new file mode 100644
index 0000000000000000000000000000000000000000..fa7a21a7010e6ba2a61436a3192a4e940ceb9dfb
--- /dev/null
+++ b/chrome/browser/chromeos/ownership/owner_settings_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/ownership/owner_settings_service.h"
+
+#include <string>
+
+#include "base/bind.h"
+#include "chrome/browser/chrome_notification_types.h"
+#include "chrome/browser/chromeos/login/users/user.h"
+#include "chrome/browser/chromeos/login/users/user_manager.h"
+#include "chrome/browser/chromeos/ownership/owner_settings_service_factory.h"
+#include "chrome/browser/chromeos/settings/device_settings_service.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_source.h"
+#include "crypto/nss_util_internal.h"
+#include "crypto/scoped_nss_types.h"
+
+using content::BrowserThread;
+
+namespace chromeos {
+
+OwnerSettingsService::OwnerSettingsService(Profile* profile)
+ : profile_(profile), weak_factory_(this) {
+ registrar_.Add(this,
+ chrome::NOTIFICATION_PROFILE_CREATED,
+ content::Source<Profile>(profile_));
+}
+
+OwnerSettingsService::~OwnerSettingsService() {
+}
+
+void OwnerSettingsService::Observe(
+ int type,
+ const content::NotificationSource& source,
+ const content::NotificationDetails& details) {
+ if (type != chrome::NOTIFICATION_PROFILE_CREATED) {
+ NOTREACHED();
+ return;
+ }
+
+ Profile* profile = content::Source<Profile>(source).ptr();
+ if (profile != profile_) {
+ NOTREACHED();
+ return;
+ }
+
+ ReloadOwnerKey();
+}
+
+void OwnerSettingsService::ReloadOwnerKey() {
+ if (!UserManager::IsInitialized())
+ return;
+ const User* user = UserManager::Get()->GetUserByProfile(profile_);
+ if (!user || !user->is_profile_created())
+ return;
+ std::string user_id = user->email();
+ if (user_id != OwnerSettingsServiceFactory::GetInstance()->GetUsername())
+ return;
+ BrowserThread::PostTaskAndReplyWithResult(
+ BrowserThread::IO,
+ FROM_HERE,
+ base::Bind(&crypto::GetPublicSlotForChromeOSUser, user->username_hash()),
+ base::Bind(&DeviceSettingsService::InitOwner,
+ base::Unretained(DeviceSettingsService::Get()),
+ user_id));
+}
+
+} // namespace chromeos

Powered by Google App Engine
This is Rietveld 408576698