OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/chromeos/login/owner_manager.h" | 5 #include "chrome/browser/chromeos/login/owner_manager.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/file_path.h" | 10 #include "base/file_path.h" |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
42 // Whether we loaded the public key or not, send a notification indicating | 42 // Whether we loaded the public key or not, send a notification indicating |
43 // that we're done with this attempt. | 43 // that we're done with this attempt. |
44 BrowserThread::PostTask( | 44 BrowserThread::PostTask( |
45 BrowserThread::UI, FROM_HERE, | 45 BrowserThread::UI, FROM_HERE, |
46 NewRunnableMethod(this, | 46 NewRunnableMethod(this, |
47 &OwnerManager::SendNotification, | 47 &OwnerManager::SendNotification, |
48 result, | 48 result, |
49 NotificationService::NoDetails())); | 49 NotificationService::NoDetails())); |
50 } | 50 } |
51 | 51 |
52 void OwnerManager::GenerateKeysAndExportPublic() { | |
53 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | |
54 VLOG(1) << "Generating key pair"; | |
55 | |
56 private_key_.reset(utils_->GenerateKeyPair()); | |
57 | |
58 if (private_key_.get() && private_key_->ExportPublicKey(&public_key_)) { | |
59 // If we generated the keys successfully, export them. | |
60 BrowserThread::PostTask( | |
61 BrowserThread::UI, FROM_HERE, | |
62 NewRunnableMethod(this, &OwnerManager::ExportKey)); | |
63 } else { | |
64 private_key_.reset(NULL); | |
65 // If we didn't generate the key, send along a notification of failure. | |
66 BrowserThread::PostTask( | |
67 BrowserThread::UI, FROM_HERE, | |
68 NewRunnableMethod(this, | |
69 &OwnerManager::SendNotification, | |
70 NotificationType::OWNER_KEY_FETCH_ATTEMPT_FAILED, | |
71 NotificationService::NoDetails())); | |
72 } | |
73 } | |
74 | |
75 void OwnerManager::ExportKey() { | |
76 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
77 VLOG(1) << "Exporting public key"; | |
78 if (utils_->ExportPublicKeyViaDbus(private_key_.get(), this)) { | |
79 BrowserThread::PostTask( | |
80 BrowserThread::UI, FROM_HERE, | |
81 NewRunnableMethod(this, | |
82 &OwnerManager::SendNotification, | |
83 NotificationType::OWNERSHIP_TAKEN, | |
84 NotificationService::NoDetails())); | |
85 } else { | |
86 private_key_.reset(NULL); | |
87 BrowserThread::PostTask( | |
88 BrowserThread::UI, FROM_HERE, | |
89 NewRunnableMethod(this, | |
90 &OwnerManager::SendNotification, | |
91 NotificationType::OWNER_KEY_FETCH_ATTEMPT_FAILED, | |
92 NotificationService::NoDetails())); | |
93 } | |
94 BootTimesLoader::Get()->AddLoginTimeMarker("ExportKeyEnd", false); | |
95 } | |
96 | |
97 void OwnerManager::OnComplete(bool value) { | |
98 VLOG(1) << "Export public key attempt: " << (value ? "success" : "fail"); | |
99 NotificationType result = NotificationType::OWNER_KEY_FETCH_ATTEMPT_SUCCEEDED; | |
100 if (!value) | |
101 result = NotificationType::OWNER_KEY_FETCH_ATTEMPT_FAILED; | |
102 | |
103 // Whether we exported the public key or not, send a notification indicating | |
104 // that we're done with this attempt. | |
105 BrowserThread::PostTask( | |
106 BrowserThread::UI, FROM_HERE, | |
107 NewRunnableMethod(this, | |
108 &OwnerManager::SendNotification, | |
109 result, | |
110 NotificationService::NoDetails())); | |
111 // We've stored some settings in transient storage | |
112 // before owner has been assigned. | |
113 // Now owner is assigned and key is generated and we should persist | |
114 // those settings into signed storage. | |
115 if (g_browser_process && g_browser_process->local_state()) { | |
116 SignedSettingsTempStorage::Finalize(g_browser_process->local_state()); | |
117 } | |
118 } | |
119 | |
120 bool OwnerManager::EnsurePublicKey() { | 52 bool OwnerManager::EnsurePublicKey() { |
121 if (public_key_.empty()) | 53 if (public_key_.empty()) |
122 LoadOwnerKey(); | 54 LoadOwnerKey(); |
123 | 55 |
124 return !public_key_.empty(); | 56 return !public_key_.empty(); |
125 } | 57 } |
126 | 58 |
127 bool OwnerManager::EnsurePrivateKey() { | 59 bool OwnerManager::EnsurePrivateKey() { |
128 if (!EnsurePublicKey()) | 60 if (!EnsurePublicKey()) |
129 return false; | 61 return false; |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
198 | 130 |
199 void OwnerManager::SendNotification(NotificationType type, | 131 void OwnerManager::SendNotification(NotificationType type, |
200 const NotificationDetails& details) { | 132 const NotificationDetails& details) { |
201 NotificationService::current()->Notify( | 133 NotificationService::current()->Notify( |
202 type, | 134 type, |
203 NotificationService::AllSources(), | 135 NotificationService::AllSources(), |
204 details); | 136 details); |
205 } | 137 } |
206 | 138 |
207 } // namespace chromeos | 139 } // namespace chromeos |
OLD | NEW |