OLD | NEW |
---|---|
(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/login/owner_key_reloader_service.h" | |
6 | |
7 #include "base/bind.h" | |
8 #include "chrome/browser/chromeos/login/owner_key_reloader_service_factory.h" | |
9 #include "chrome/browser/chromeos/login/user.h" | |
10 #include "chrome/browser/chromeos/login/user_manager.h" | |
11 #include "chrome/browser/chromeos/settings/device_settings_service.h" | |
12 #include "chrome/browser/net/nss_context.h" | |
13 #include "chrome/browser/profiles/profile.h" | |
14 #include "content/public/browser/browser_thread.h" | |
15 #include "content/public/browser/resource_context.h" | |
16 #include "crypto/scoped_nss_types.h" | |
17 | |
18 using content::BrowserThread; | |
19 | |
20 namespace chromeos { | |
21 | |
22 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.
| |
23 | |
24 OwnerKeyReloaderService::OwnerKeyReloaderService(Profile* profile) | |
25 : 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
| |
26 } | |
27 | |
28 OwnerKeyReloaderService::~OwnerKeyReloaderService() { | |
29 } | |
30 | |
31 // static | |
32 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.
| |
33 username_ = username; | |
34 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
| |
35 return; | |
36 const User* user = UserManager::Get()->FindUser(username); | |
37 if (!user || !user->is_profile_created()) | |
38 return; | |
39 Profile* profile = UserManager::Get()->GetProfileByUser(user); | |
40 if (!profile) | |
41 return; | |
42 OwnerKeyReloaderServiceFactory::GetForProfile(profile)->ReloadOwnerKey(); | |
43 } | |
44 | |
45 // static | |
46 std::string OwnerKeyReloaderService::GetUsername() { | |
47 return username_; | |
48 } | |
49 | |
50 void OwnerKeyReloaderService::ReloadOwnerKey() { | |
51 if (!UserManager::IsInitialized() || !profile_) | |
52 return; | |
53 const User* user = UserManager::Get()->GetUserByProfile(profile_); | |
54 if (!user || user->email() != GetUsername()) | |
55 return; | |
56 content::ResourceContext* context = | |
57 profile_ ? profile_->GetResourceContext() : NULL; | |
58 if (context) { | |
59 BrowserThread::PostTaskAndReplyWithResult( | |
60 BrowserThread::IO, | |
61 FROM_HERE, | |
62 base::Bind(&GetPublicNSSKeySlotForResourceContext, context), | |
63 base::Bind(&DeviceSettingsService::InitOwner, | |
64 base::Unretained(DeviceSettingsService::Get()), | |
65 GetUsername())); | |
66 } else { | |
67 crypto::ScopedPK11Slot slot; | |
68 DeviceSettingsService::Get()->InitOwner(GetUsername(), slot.Pass()); | |
69 } | |
70 } | |
71 | |
72 } // namespace chromeos | |
OLD | NEW |