Index: chrome/browser/chromeos/login/owner_settings_service.cc |
diff --git a/chrome/browser/chromeos/login/owner_settings_service.cc b/chrome/browser/chromeos/login/owner_settings_service.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..5f54956d9767dd902772ce7a02f0021de9978cf9 |
--- /dev/null |
+++ b/chrome/browser/chromeos/login/owner_settings_service.cc |
@@ -0,0 +1,61 @@ |
+// 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_settings_service.h" |
+ |
+#include <string> |
+ |
+#include "base/bind.h" |
+#include "chrome/browser/chromeos/login/owner_settings_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 { |
+ |
+OwnerSettingsService::OwnerSettingsService(Profile* profile) |
+ : profile_(profile), weak_factory_(this) { |
+ // ReloadOwnerKey() is called after delay because at the time of |
Nikita (slow)
2014/05/15 12:48:58
It seems that this is not actually a delay but jus
ygorshenin1
2014/05/16 12:09:37
Done.
|
+ // OwnerSettinsService construction ProfileIOData is not initialized. |
+ BrowserThread::PostTask(BrowserThread::UI, |
+ FROM_HERE, |
+ base::Bind(&OwnerSettingsService::ReloadOwnerKey, |
+ weak_factory_.GetWeakPtr())); |
+} |
+ |
+OwnerSettingsService::~OwnerSettingsService() { |
+} |
+ |
+void OwnerSettingsService::ReloadOwnerKey() { |
+ if (!UserManager::IsInitialized()) |
+ return; |
+ const User* user = UserManager::Get()->GetUserByProfile(profile_); |
+ if (!user) |
+ return; |
+ std::string username = user->email(); |
Nikita (slow)
2014/05/15 12:48:58
nit: user_id
ygorshenin1
2014/05/16 12:09:37
Done.
|
+ if (username != OwnerSettingsServiceFactory::GetInstance()->GetUsername()) |
+ return; |
+ content::ResourceContext* context = profile_->GetResourceContext(); |
+ 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; |
Nikita (slow)
2014/05/15 12:48:58
nit: Can you please add comment describing the sit
ygorshenin1
2014/05/16 12:09:37
There shouldn't be such situations, so I've added
|
+ DeviceSettingsService::Get()->InitOwner(username, slot.Pass()); |
+ } |
+} |
+ |
+} // namespace chromeos |