OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/screen_locker.h" | 5 #include "chrome/browser/chromeos/login/screen_locker.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "ash/ash_switches.h" | 10 #include "ash/ash_switches.h" |
11 #include "ash/audio/sounds.h" | 11 #include "ash/audio/sounds.h" |
12 #include "ash/desktop_background/desktop_background_controller.h" | 12 #include "ash/desktop_background/desktop_background_controller.h" |
13 #include "ash/shell.h" | 13 #include "ash/shell.h" |
14 #include "ash/wm/lock_state_controller.h" | 14 #include "ash/wm/lock_state_controller.h" |
15 #include "ash/wm/window_state.h" | 15 #include "ash/wm/window_state.h" |
16 #include "ash/wm/window_util.h" | 16 #include "ash/wm/window_util.h" |
17 #include "base/bind.h" | 17 #include "base/bind.h" |
18 #include "base/command_line.h" | 18 #include "base/command_line.h" |
19 #include "base/lazy_instance.h" | 19 #include "base/lazy_instance.h" |
20 #include "base/memory/weak_ptr.h" | 20 #include "base/memory/weak_ptr.h" |
21 #include "base/message_loop/message_loop.h" | 21 #include "base/message_loop/message_loop.h" |
22 #include "base/metrics/histogram.h" | 22 #include "base/metrics/histogram.h" |
23 #include "base/strings/string_number_conversions.h" | 23 #include "base/strings/string_number_conversions.h" |
24 #include "base/strings/string_util.h" | 24 #include "base/strings/string_util.h" |
25 #include "base/timer/timer.h" | 25 #include "base/timer/timer.h" |
26 #include "chrome/browser/chrome_notification_types.h" | 26 #include "chrome/browser/chrome_notification_types.h" |
27 #include "chrome/browser/chromeos/extensions/screenlock_private_api.h" | |
27 #include "chrome/browser/chromeos/login/authenticator.h" | 28 #include "chrome/browser/chromeos/login/authenticator.h" |
28 #include "chrome/browser/chromeos/login/login_performer.h" | 29 #include "chrome/browser/chromeos/login/login_performer.h" |
29 #include "chrome/browser/chromeos/login/login_utils.h" | 30 #include "chrome/browser/chromeos/login/login_utils.h" |
30 #include "chrome/browser/chromeos/login/user_adding_screen.h" | 31 #include "chrome/browser/chromeos/login/user_adding_screen.h" |
31 #include "chrome/browser/chromeos/login/user_manager.h" | 32 #include "chrome/browser/chromeos/login/user_manager.h" |
32 #include "chrome/browser/chromeos/login/webui_screen_locker.h" | 33 #include "chrome/browser/chromeos/login/webui_screen_locker.h" |
33 #include "chrome/browser/lifetime/application_lifetime.h" | 34 #include "chrome/browser/lifetime/application_lifetime.h" |
34 #include "chrome/browser/profiles/profile.h" | 35 #include "chrome/browser/profiles/profile.h" |
35 #include "chrome/browser/profiles/profile_manager.h" | 36 #include "chrome/browser/profiles/profile_manager.h" |
36 #include "chrome/browser/signin/signin_manager.h" | 37 #include "chrome/browser/signin/signin_manager.h" |
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
250 authentication_capture_.reset(); | 251 authentication_capture_.reset(); |
251 weak_factory_.InvalidateWeakPtrs(); | 252 weak_factory_.InvalidateWeakPtrs(); |
252 | 253 |
253 VLOG(1) << "Hiding the lock screen."; | 254 VLOG(1) << "Hiding the lock screen."; |
254 chromeos::ScreenLocker::Hide(); | 255 chromeos::ScreenLocker::Hide(); |
255 } | 256 } |
256 | 257 |
257 void ScreenLocker::Authenticate(const UserContext& user_context) { | 258 void ScreenLocker::Authenticate(const UserContext& user_context) { |
258 LOG_ASSERT(IsUserLoggedIn(user_context.username)) | 259 LOG_ASSERT(IsUserLoggedIn(user_context.username)) |
259 << "Invalid user trying to unlock."; | 260 << "Invalid user trying to unlock."; |
261 | |
260 authentication_start_time_ = base::Time::Now(); | 262 authentication_start_time_ = base::Time::Now(); |
261 delegate_->SetInputEnabled(false); | 263 delegate_->SetInputEnabled(false); |
262 delegate_->OnAuthenticate(); | 264 delegate_->OnAuthenticate(); |
263 | 265 |
266 // Send authentication request to app using chrome.screenlockPrivate API | |
267 // if the authentication type is not the system password. | |
268 LoginDisplay::AuthType auth_type = GetAuthType(user_context.username); | |
269 if (auth_type != LoginDisplay::OFFLINE_PASSWORD) { | |
270 const User* unlock_user = | |
271 UserManager::Get()->FindUser(user_context.username); | |
xiyuan
2014/02/19 21:48:44
nit: It's better use the |users_| of ScreenLocker,
Tim Song
2014/02/20 00:06:46
Done.
| |
272 LOG_ASSERT(unlock_user); | |
273 Profile* profile = UserManager::Get()->GetProfileByUser(unlock_user); | |
274 extensions::ScreenlockPrivateEventRouter* router = | |
275 extensions::ScreenlockPrivateEventRouter::GetFactoryInstance() | |
276 ->GetForProfile(profile); | |
277 router->OnAuthAttempted(auth_type, user_context.password); | |
278 return; | |
279 } | |
280 | |
264 BrowserThread::PostTask( | 281 BrowserThread::PostTask( |
265 BrowserThread::UI, FROM_HERE, | 282 BrowserThread::UI, FROM_HERE, |
266 base::Bind(&Authenticator::AuthenticateToUnlock, | 283 base::Bind(&Authenticator::AuthenticateToUnlock, |
267 authenticator_.get(), | 284 authenticator_.get(), |
268 user_context)); | 285 user_context)); |
269 } | 286 } |
270 | 287 |
271 void ScreenLocker::AuthenticateByPassword(const std::string& password) { | 288 void ScreenLocker::AuthenticateByPassword(const std::string& password) { |
272 LOG_ASSERT(users_.size() == 1); | 289 LOG_ASSERT(users_.size() == 1); |
273 Authenticate(UserContext(users_[0]->email(), password, "")); | 290 Authenticate(UserContext(users_[0]->email(), password, "")); |
(...skipping 23 matching lines...) Expand all Loading... | |
297 } | 314 } |
298 | 315 |
299 void ScreenLocker::ShowUserPodButton(const std::string& username, | 316 void ScreenLocker::ShowUserPodButton(const std::string& username, |
300 const gfx::Image& icon, | 317 const gfx::Image& icon, |
301 const base::Closure& click_callback) { | 318 const base::Closure& click_callback) { |
302 if (!locked_) | 319 if (!locked_) |
303 return; | 320 return; |
304 | 321 |
305 screenlock_icon_provider_->AddIcon(username, icon); | 322 screenlock_icon_provider_->AddIcon(username, icon); |
306 | 323 |
307 // Append the current time to the URL so the image will not be cached. | 324 if (!username.empty()) { |
308 std::string icon_url = ScreenlockIconSource::GetIconURLForUser(username) | 325 // Append the current time to the URL so the image will not be cached. |
309 + "?" + base::Int64ToString(base::Time::Now().ToInternalValue()); | 326 std::string icon_url = |
310 delegate_->ShowUserPodButton(username, icon_url, click_callback); | 327 ScreenlockIconSource::GetIconURLForUser(username) + "?uniq=" + |
328 base::Int64ToString(base::Time::Now().ToInternalValue()); | |
329 delegate_->ShowUserPodButton(username, icon_url, click_callback); | |
330 } | |
331 } | |
332 | |
333 void ScreenLocker::HideUserPodButton(const std::string& username) { | |
334 if (!locked_) | |
335 return; | |
336 screenlock_icon_provider_->RemoveIcon(username); | |
337 delegate_->HideUserPodButton(username); | |
338 } | |
339 | |
340 void ScreenLocker::SetAuthType(const std::string& username, | |
341 LoginDisplay::AuthType auth_type, | |
342 const std::string& initial_value) { | |
343 if (!locked_) | |
344 return; | |
345 delegate_->SetAuthType(username, auth_type, initial_value); | |
346 } | |
347 | |
348 LoginDisplay::AuthType ScreenLocker::GetAuthType(const std::string& username) | |
349 const { | |
350 // Return default authentication type when not locked. | |
351 if (!locked_) | |
352 return LoginDisplay::OFFLINE_PASSWORD; | |
353 return delegate_->GetAuthType(username); | |
311 } | 354 } |
312 | 355 |
313 void ScreenLocker::ShowErrorMessage(int error_msg_id, | 356 void ScreenLocker::ShowErrorMessage(int error_msg_id, |
314 HelpAppLauncher::HelpTopic help_topic_id, | 357 HelpAppLauncher::HelpTopic help_topic_id, |
315 bool sign_out_only) { | 358 bool sign_out_only) { |
316 delegate_->SetInputEnabled(!sign_out_only); | 359 delegate_->SetInputEnabled(!sign_out_only); |
317 delegate_->ShowErrorMessage(error_msg_id, help_topic_id); | 360 delegate_->ShowErrorMessage(error_msg_id, help_topic_id); |
318 } | 361 } |
319 | 362 |
320 void ScreenLocker::SetLoginStatusConsumer( | 363 void ScreenLocker::SetLoginStatusConsumer( |
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
475 | 518 |
476 bool ScreenLocker::IsUserLoggedIn(const std::string& username) { | 519 bool ScreenLocker::IsUserLoggedIn(const std::string& username) { |
477 for (UserList::const_iterator it = users_.begin(); it != users_.end(); ++it) { | 520 for (UserList::const_iterator it = users_.begin(); it != users_.end(); ++it) { |
478 if ((*it)->email() == username) | 521 if ((*it)->email() == username) |
479 return true; | 522 return true; |
480 } | 523 } |
481 return false; | 524 return false; |
482 } | 525 } |
483 | 526 |
484 } // namespace chromeos | 527 } // namespace chromeos |
OLD | NEW |