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

Side by Side 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: Fixed tests, used GetPublicSlotForChromeOSUSer. 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(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, chrome::NOTIFICATION_PROFILE_CREATED,
29 content::Source<Profile>(profile_));
30 }
31
32 OwnerSettingsService::~OwnerSettingsService() {
33 }
34
35 void OwnerSettingsService::Observe(
36 int type,
37 const content::NotificationSource& source,
38 const content::NotificationDetails& details) {
39 if (type != chrome::NOTIFICATION_PROFILE_CREATED) {
40 NOTREACHED();
41 return;
42 }
43
44 Profile* profile = content::Source<Profile>(source).ptr();
45 if (profile != profile_) {
46 NOTREACHED();
47 return;
48 }
49
50 ReloadOwnerKey();
51 }
52
53 void OwnerSettingsService::ReloadOwnerKey() {
54 if (!UserManager::IsInitialized())
55 return;
56 const User* user = UserManager::Get()->GetUserByProfile(profile_);
57 if (!user || !user->is_profile_created())
58 return;
59 std::string user_id = user->email();
60 if (user_id != OwnerSettingsServiceFactory::GetInstance()->GetUsername())
61 return;
62 BrowserThread::PostTaskAndReplyWithResult(
63 BrowserThread::IO,
64 FROM_HERE,
65 base::Bind(&crypto::GetPublicSlotForChromeOSUser, user->username_hash()),
66 base::Bind(&DeviceSettingsService::InitOwner,
67 base::Unretained(DeviceSettingsService::Get()),
68 user_id));
69 }
70
71 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698