| 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 // Find the user that is authenticating. |
| 271 const User* unlock_user = NULL; |
| 272 for (UserList::const_iterator it = users_.begin(); |
| 273 it != users_.end(); |
| 274 ++it) { |
| 275 if ((*it)->email() == user_context.username) { |
| 276 unlock_user = *it; |
| 277 break; |
| 278 } |
| 279 } |
| 280 LOG_ASSERT(unlock_user); |
| 281 |
| 282 // TODO(tengs): dispatch auth attempted event to the screenlockPrivate |
| 283 // API's event router. |
| 284 return; |
| 285 } |
| 286 |
| 264 BrowserThread::PostTask( | 287 BrowserThread::PostTask( |
| 265 BrowserThread::UI, FROM_HERE, | 288 BrowserThread::UI, FROM_HERE, |
| 266 base::Bind(&Authenticator::AuthenticateToUnlock, | 289 base::Bind(&Authenticator::AuthenticateToUnlock, |
| 267 authenticator_.get(), | 290 authenticator_.get(), |
| 268 user_context)); | 291 user_context)); |
| 269 } | 292 } |
| 270 | 293 |
| 271 void ScreenLocker::AuthenticateByPassword(const std::string& password) { | 294 void ScreenLocker::AuthenticateByPassword(const std::string& password) { |
| 272 LOG_ASSERT(users_.size() == 1); | 295 LOG_ASSERT(users_.size() == 1); |
| 273 Authenticate(UserContext(users_[0]->email(), password, "")); | 296 Authenticate(UserContext(users_[0]->email(), password, "")); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 297 } | 320 } |
| 298 | 321 |
| 299 void ScreenLocker::ShowUserPodButton(const std::string& username, | 322 void ScreenLocker::ShowUserPodButton(const std::string& username, |
| 300 const gfx::Image& icon, | 323 const gfx::Image& icon, |
| 301 const base::Closure& click_callback) { | 324 const base::Closure& click_callback) { |
| 302 if (!locked_) | 325 if (!locked_) |
| 303 return; | 326 return; |
| 304 | 327 |
| 305 screenlock_icon_provider_->AddIcon(username, icon); | 328 screenlock_icon_provider_->AddIcon(username, icon); |
| 306 | 329 |
| 307 // Append the current time to the URL so the image will not be cached. | 330 if (!username.empty()) { |
| 308 std::string icon_url = ScreenlockIconSource::GetIconURLForUser(username) | 331 // Append the current time to the URL so the image will not be cached. |
| 309 + "?" + base::Int64ToString(base::Time::Now().ToInternalValue()); | 332 std::string icon_url = |
| 310 delegate_->ShowUserPodButton(username, icon_url, click_callback); | 333 ScreenlockIconSource::GetIconURLForUser(username) + "?uniq=" + |
| 334 base::Int64ToString(base::Time::Now().ToInternalValue()); |
| 335 delegate_->ShowUserPodButton(username, icon_url, click_callback); |
| 336 } |
| 337 } |
| 338 |
| 339 void ScreenLocker::HideUserPodButton(const std::string& username) { |
| 340 if (!locked_) |
| 341 return; |
| 342 screenlock_icon_provider_->RemoveIcon(username); |
| 343 delegate_->HideUserPodButton(username); |
| 344 } |
| 345 |
| 346 void ScreenLocker::SetAuthType(const std::string& username, |
| 347 LoginDisplay::AuthType auth_type, |
| 348 const std::string& initial_value) { |
| 349 if (!locked_) |
| 350 return; |
| 351 delegate_->SetAuthType(username, auth_type, initial_value); |
| 352 } |
| 353 |
| 354 LoginDisplay::AuthType ScreenLocker::GetAuthType(const std::string& username) |
| 355 const { |
| 356 // Return default authentication type when not locked. |
| 357 if (!locked_) |
| 358 return LoginDisplay::OFFLINE_PASSWORD; |
| 359 return delegate_->GetAuthType(username); |
| 311 } | 360 } |
| 312 | 361 |
| 313 void ScreenLocker::ShowErrorMessage(int error_msg_id, | 362 void ScreenLocker::ShowErrorMessage(int error_msg_id, |
| 314 HelpAppLauncher::HelpTopic help_topic_id, | 363 HelpAppLauncher::HelpTopic help_topic_id, |
| 315 bool sign_out_only) { | 364 bool sign_out_only) { |
| 316 delegate_->SetInputEnabled(!sign_out_only); | 365 delegate_->SetInputEnabled(!sign_out_only); |
| 317 delegate_->ShowErrorMessage(error_msg_id, help_topic_id); | 366 delegate_->ShowErrorMessage(error_msg_id, help_topic_id); |
| 318 } | 367 } |
| 319 | 368 |
| 320 void ScreenLocker::SetLoginStatusConsumer( | 369 void ScreenLocker::SetLoginStatusConsumer( |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 475 | 524 |
| 476 bool ScreenLocker::IsUserLoggedIn(const std::string& username) { | 525 bool ScreenLocker::IsUserLoggedIn(const std::string& username) { |
| 477 for (UserList::const_iterator it = users_.begin(); it != users_.end(); ++it) { | 526 for (UserList::const_iterator it = users_.begin(); it != users_.end(); ++it) { |
| 478 if ((*it)->email() == username) | 527 if ((*it)->email() == username) |
| 479 return true; | 528 return true; |
| 480 } | 529 } |
| 481 return false; | 530 return false; |
| 482 } | 531 } |
| 483 | 532 |
| 484 } // namespace chromeos | 533 } // namespace chromeos |
| OLD | NEW |