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

Side by Side Diff: chrome/browser/chromeos/login/lock/screen_locker.cc

Issue 2859363003: cros: Initial structure for views-based lock. (Closed)
Patch Set: Initial upload Created 3 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 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/lock/screen_locker.h" 5 #include "chrome/browser/chromeos/login/lock/screen_locker.h"
6 6
7 #include <string> 7 #include <string>
8 #include <vector> 8 #include <vector>
9 9
10 #include "ash/login/views/lock_screen.h"
11 #include "ash/public/interfaces/constants.mojom.h"
12 #include "ash/public/interfaces/session_controller.mojom.h"
10 #include "ash/shell.h" 13 #include "ash/shell.h"
11 #include "ash/wm/window_state.h" 14 #include "ash/wm/window_state.h"
12 #include "ash/wm/window_state_aura.h" 15 #include "ash/wm/window_state_aura.h"
13 #include "ash/wm/window_util.h" 16 #include "ash/wm/window_util.h"
14 #include "ash/wm/wm_event.h" 17 #include "ash/wm/wm_event.h"
15 #include "base/bind.h" 18 #include "base/bind.h"
16 #include "base/command_line.h" 19 #include "base/command_line.h"
17 #include "base/lazy_instance.h" 20 #include "base/lazy_instance.h"
18 #include "base/location.h" 21 #include "base/location.h"
19 #include "base/macros.h" 22 #include "base/macros.h"
(...skipping 19 matching lines...) Expand all
39 #include "chrome/browser/signin/easy_unlock_service.h" 42 #include "chrome/browser/signin/easy_unlock_service.h"
40 #include "chrome/browser/signin/signin_manager_factory.h" 43 #include "chrome/browser/signin/signin_manager_factory.h"
41 #include "chrome/browser/ui/ash/ash_util.h" 44 #include "chrome/browser/ui/ash/ash_util.h"
42 #include "chrome/browser/ui/ash/session_controller_client.h" 45 #include "chrome/browser/ui/ash/session_controller_client.h"
43 #include "chrome/browser/ui/webui/chromeos/login/screenlock_icon_provider.h" 46 #include "chrome/browser/ui/webui/chromeos/login/screenlock_icon_provider.h"
44 #include "chrome/browser/ui/webui/chromeos/login/screenlock_icon_source.h" 47 #include "chrome/browser/ui/webui/chromeos/login/screenlock_icon_source.h"
45 #include "chrome/common/chrome_switches.h" 48 #include "chrome/common/chrome_switches.h"
46 #include "chrome/grit/browser_resources.h" 49 #include "chrome/grit/browser_resources.h"
47 #include "chrome/grit/generated_resources.h" 50 #include "chrome/grit/generated_resources.h"
48 #include "chromeos/audio/chromeos_sounds.h" 51 #include "chromeos/audio/chromeos_sounds.h"
52 #include "chromeos/chromeos_switches.h"
49 #include "chromeos/dbus/dbus_thread_manager.h" 53 #include "chromeos/dbus/dbus_thread_manager.h"
50 #include "chromeos/dbus/session_manager_client.h" 54 #include "chromeos/dbus/session_manager_client.h"
51 #include "chromeos/login/auth/authenticator.h" 55 #include "chromeos/login/auth/authenticator.h"
52 #include "chromeos/login/auth/extended_authenticator.h" 56 #include "chromeos/login/auth/extended_authenticator.h"
53 #include "chromeos/network/portal_detector/network_portal_detector.h" 57 #include "chromeos/network/portal_detector/network_portal_detector.h"
54 #include "components/session_manager/core/session_manager.h" 58 #include "components/session_manager/core/session_manager.h"
55 #include "components/signin/core/browser/signin_manager.h" 59 #include "components/signin/core/browser/signin_manager.h"
56 #include "components/user_manager/user_manager.h" 60 #include "components/user_manager/user_manager.h"
57 #include "components/user_manager/user_type.h" 61 #include "components/user_manager/user_type.h"
58 #include "content/public/browser/browser_thread.h" 62 #include "content/public/browser/browser_thread.h"
59 #include "content/public/browser/notification_service.h" 63 #include "content/public/browser/notification_service.h"
60 #include "content/public/browser/url_data_source.h" 64 #include "content/public/browser/url_data_source.h"
61 #include "content/public/browser/web_contents.h" 65 #include "content/public/browser/web_contents.h"
62 #include "content/public/browser/web_ui.h" 66 #include "content/public/browser/web_ui.h"
63 #include "content/public/common/service_manager_connection.h" 67 #include "content/public/common/service_manager_connection.h"
64 #include "media/audio/sounds/sounds_manager.h" 68 #include "media/audio/sounds/sounds_manager.h"
65 #include "services/device/public/interfaces/constants.mojom.h" 69 #include "services/device/public/interfaces/constants.mojom.h"
66 #include "services/service_manager/public/cpp/connector.h" 70 #include "services/service_manager/public/cpp/connector.h"
67 #include "ui/base/resource/resource_bundle.h" 71 #include "ui/base/resource/resource_bundle.h"
72 #include "ui/display/display.h"
73 #include "ui/display/screen.h"
68 #include "ui/gfx/image/image.h" 74 #include "ui/gfx/image/image.h"
69 #include "url/gurl.h" 75 #include "url/gurl.h"
70 76
71 using base::UserMetricsAction; 77 using base::UserMetricsAction;
72 using content::BrowserThread; 78 using content::BrowserThread;
73 79
74 namespace chromeos { 80 namespace chromeos {
75 81
76 namespace { 82 namespace {
77 83
78 // Timeout for unlock animation guard - some animations may be required to run 84 // Timeout for unlock animation guard - some animations may be required to run
79 // on successful authentication before unlocking, but we want to be sure that 85 // on successful authentication before unlocking, but we want to be sure that
80 // unlock happens even if animations are broken. 86 // unlock happens even if animations are broken.
81 const int kUnlockGuardTimeoutMs = 400; 87 const int kUnlockGuardTimeoutMs = 400;
82 88
89 // Returns true if we are using md-based login/lock.
90 bool IsUsingMdLogin() {
91 return base::CommandLine::ForCurrentProcess()->HasSwitch(
92 chromeos::switches::kShowMdLogin);
93 }
94
83 // Returns true if fingerprint authentication is available for one of the 95 // Returns true if fingerprint authentication is available for one of the
84 // |users|. 96 // |users|.
85 bool IsFingerprintAuthenticationAvailableForUsers( 97 bool IsFingerprintAuthenticationAvailableForUsers(
86 const user_manager::UserList& users) { 98 const user_manager::UserList& users) {
87 for (auto* user : users) { 99 for (auto* user : users) {
88 quick_unlock::QuickUnlockStorage* quick_unlock_storage = 100 quick_unlock::QuickUnlockStorage* quick_unlock_storage =
89 quick_unlock::QuickUnlockFactory::GetForUser(user); 101 quick_unlock::QuickUnlockFactory::GetForUser(user);
90 if (quick_unlock_storage && 102 if (quick_unlock_storage &&
91 quick_unlock_storage->IsFingerprintAuthenticationAvailable()) { 103 quick_unlock_storage->IsFingerprintAuthenticationAvailable()) {
92 return true; 104 return true;
(...skipping 10 matching lines...) Expand all
103 ScreenLockObserver() : session_started_(false) { 115 ScreenLockObserver() : session_started_(false) {
104 registrar_.Add(this, 116 registrar_.Add(this,
105 chrome::NOTIFICATION_SESSION_STARTED, 117 chrome::NOTIFICATION_SESSION_STARTED,
106 content::NotificationService::AllSources()); 118 content::NotificationService::AllSources());
107 DBusThreadManager::Get()->GetSessionManagerClient()->SetStubDelegate(this); 119 DBusThreadManager::Get()->GetSessionManagerClient()->SetStubDelegate(this);
108 } 120 }
109 121
110 ~ScreenLockObserver() override { 122 ~ScreenLockObserver() override {
111 if (DBusThreadManager::IsInitialized()) { 123 if (DBusThreadManager::IsInitialized()) {
112 DBusThreadManager::Get()->GetSessionManagerClient()->SetStubDelegate( 124 DBusThreadManager::Get()->GetSessionManagerClient()->SetStubDelegate(
113 NULL); 125 nullptr);
114 } 126 }
115 } 127 }
116 128
117 bool session_started() const { return session_started_; } 129 bool session_started() const { return session_started_; }
118 130
119 // SessionManagerClient::StubDelegate overrides: 131 // SessionManagerClient::StubDelegate overrides:
120 void LockScreenForStub() override { ScreenLocker::HandleLockScreenRequest(); } 132 void LockScreenForStub() override { ScreenLocker::HandleLockScreenRequest(); }
121 133
122 // NotificationObserver overrides: 134 // NotificationObserver overrides:
123 void Observe(int type, 135 void Observe(int type,
(...skipping 21 matching lines...) Expand all
145 ScreenLocker::HandleLockScreenRequest(); 157 ScreenLocker::HandleLockScreenRequest();
146 } 158 }
147 159
148 private: 160 private:
149 bool session_started_; 161 bool session_started_;
150 content::NotificationRegistrar registrar_; 162 content::NotificationRegistrar registrar_;
151 163
152 DISALLOW_COPY_AND_ASSIGN(ScreenLockObserver); 164 DISALLOW_COPY_AND_ASSIGN(ScreenLockObserver);
153 }; 165 };
154 166
155 ScreenLockObserver* g_screen_lock_observer = NULL; 167 // Stubbed delegate that will eventually be replaced by mojo calls.
168 class StubDelegate : public ScreenLocker::Delegate {
169 public:
170 StubDelegate() {}
171 ~StubDelegate() override {}
172
173 // ScreenLocker::Delegate:
174 void SetInputEnabled(bool enabled) override { NOTIMPLEMENTED(); }
175 void ShowErrorMessage(int error_msg_id,
176 HelpAppLauncher::HelpTopic help_topic_id) override {
177 NOTIMPLEMENTED();
178 }
179 void ClearErrors() override { NOTIMPLEMENTED(); }
180 void AnimateAuthenticationSuccess() override { NOTIMPLEMENTED(); }
181 void OnLockWebUIReady() override { NOTIMPLEMENTED(); }
182 void OnLockBackgroundDisplayed() override { NOTIMPLEMENTED(); }
183 void OnHeaderBarVisible() override { NOTIMPLEMENTED(); }
184 void OnAshLockAnimationFinished() override { NOTIMPLEMENTED(); }
185 void SetFingerprintState(const AccountId& account_id,
186 ScreenLocker::FingerprintState state) override {
187 NOTIMPLEMENTED();
188 }
189 content::WebContents* GetWebContents() override { return nullptr; }
190
191 private:
192 DISALLOW_COPY_AND_ASSIGN(StubDelegate);
193 };
194
195 ScreenLockObserver* g_screen_lock_observer = nullptr;
156 196
157 } // namespace 197 } // namespace
158 198
159 // static 199 // static
160 ScreenLocker* ScreenLocker::screen_locker_ = NULL; 200 ScreenLocker* ScreenLocker::screen_locker_ = nullptr;
201
202 //////////////////////////////////////////////////////////////////////////////
203 // ScreenLocker::Delegate, public:
204
205 ScreenLocker::Delegate::Delegate() {}
206
207 ScreenLocker::Delegate::~Delegate() {}
161 208
162 ////////////////////////////////////////////////////////////////////////////// 209 //////////////////////////////////////////////////////////////////////////////
163 // ScreenLocker, public: 210 // ScreenLocker, public:
164 211
165 ScreenLocker::ScreenLocker(const user_manager::UserList& users) 212 ScreenLocker::ScreenLocker(const user_manager::UserList& users)
166 : users_(users), binding_(this), weak_factory_(this) { 213 : users_(users), binding_(this), weak_factory_(this) {
167 DCHECK(!screen_locker_); 214 DCHECK(!screen_locker_);
168 screen_locker_ = this; 215 screen_locker_ = this;
169 216
170 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); 217 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance();
171 media::SoundsManager* manager = media::SoundsManager::Get(); 218 media::SoundsManager* manager = media::SoundsManager::Get();
172 manager->Initialize(SOUND_LOCK, 219 manager->Initialize(SOUND_LOCK,
173 bundle.GetRawDataResource(IDR_SOUND_LOCK_WAV)); 220 bundle.GetRawDataResource(IDR_SOUND_LOCK_WAV));
174 manager->Initialize(SOUND_UNLOCK, 221 manager->Initialize(SOUND_UNLOCK,
175 bundle.GetRawDataResource(IDR_SOUND_UNLOCK_WAV)); 222 bundle.GetRawDataResource(IDR_SOUND_UNLOCK_WAV));
176 service_manager::Connector* connector = 223 service_manager::Connector* connector =
177 content::ServiceManagerConnection::GetForProcess()->GetConnector(); 224 content::ServiceManagerConnection::GetForProcess()->GetConnector();
178 connector->BindInterface(device::mojom::kServiceName, &fp_service_); 225 connector->BindInterface(device::mojom::kServiceName, &fp_service_);
179 fp_service_->AddFingerprintObserver(binding_.CreateInterfacePtrAndBind()); 226 fp_service_->AddFingerprintObserver(binding_.CreateInterfacePtrAndBind());
180 } 227 }
181 228
182 void ScreenLocker::Init() { 229 void ScreenLocker::Init() {
183 input_method::InputMethodManager* imm = 230 input_method::InputMethodManager* imm =
184 input_method::InputMethodManager::Get(); 231 input_method::InputMethodManager::Get();
185 saved_ime_state_ = imm->GetActiveIMEState(); 232 saved_ime_state_ = imm->GetActiveIMEState();
186 imm->SetState(saved_ime_state_->Clone()); 233 imm->SetState(saved_ime_state_->Clone());
187 234
188 authenticator_ = UserSessionManager::GetInstance()->CreateAuthenticator(this); 235 authenticator_ = UserSessionManager::GetInstance()->CreateAuthenticator(this);
189 extended_authenticator_ = ExtendedAuthenticator::Create(this); 236 extended_authenticator_ = ExtendedAuthenticator::Create(this);
190 web_ui_.reset(new WebUIScreenLocker(this)); 237 if (IsUsingMdLogin()) {
191 web_ui()->LockScreen(); 238 // Create delegate that will eventually call into the views-based lock
239 // screen via mojo.
240 delegate_ = new StubDelegate();
241 owns_delegate_ = true;
192 242
193 // Ownership of |icon_image_source| is passed. 243 // Create and display lock screen.
194 screenlock_icon_provider_.reset(new ScreenlockIconProvider); 244 // TODO(jdufualt): LockWindow should live in ash;
195 ScreenlockIconSource* screenlock_icon_source = 245 // ash::ShowLockScreenInWidget should be a mojo call.
196 new ScreenlockIconSource(screenlock_icon_provider_->AsWeakPtr()); 246 LockWindow* lock_window = new LockWindow();
197 content::URLDataSource::Add(web_ui()->GetWebContents()->GetBrowserContext(), 247 lock_window->SetBounds(
198 screenlock_icon_source); 248 display::Screen::GetScreen()->GetPrimaryDisplay().bounds());
249 ash::ShowLockScreenInWidget(lock_window);
250 } else {
251 web_ui_.reset(new WebUIScreenLocker(this));
252 delegate_ = web_ui_.get();
253 owns_delegate_ = false;
254 web_ui_->LockScreen();
255
256 // Ownership of |icon_image_source| is passed.
257 screenlock_icon_provider_.reset(new ScreenlockIconProvider);
258 ScreenlockIconSource* screenlock_icon_source =
259 new ScreenlockIconSource(screenlock_icon_provider_->AsWeakPtr());
260 content::URLDataSource::Add(web_ui_->web_contents()->GetBrowserContext(),
261 screenlock_icon_source);
262 }
199 263
200 // Start locking on ash side. 264 // Start locking on ash side.
201 SessionControllerClient::Get()->StartLock(base::Bind( 265 SessionControllerClient::Get()->StartLock(base::Bind(
202 &ScreenLocker::OnStartLockCallback, weak_factory_.GetWeakPtr())); 266 &ScreenLocker::OnStartLockCallback, weak_factory_.GetWeakPtr()));
203 } 267 }
204 268
205 void ScreenLocker::OnAuthFailure(const AuthFailure& error) { 269 void ScreenLocker::OnAuthFailure(const AuthFailure& error) {
206 base::RecordAction(UserMetricsAction("ScreenLocker_OnLoginFailure")); 270 base::RecordAction(UserMetricsAction("ScreenLocker_OnLoginFailure"));
207 if (authentication_start_time_.is_null()) { 271 if (authentication_start_time_.is_null()) {
208 LOG(ERROR) << "Start time is not set at authentication failure"; 272 LOG(ERROR) << "Start time is not set at authentication failure";
209 } else { 273 } else {
210 base::TimeDelta delta = base::Time::Now() - authentication_start_time_; 274 base::TimeDelta delta = base::Time::Now() - authentication_start_time_;
211 VLOG(1) << "Authentication failure: " << delta.InSecondsF() << " second(s)"; 275 VLOG(1) << "Authentication failure: " << delta.InSecondsF() << " second(s)";
212 UMA_HISTOGRAM_TIMES("ScreenLocker.AuthenticationFailureTime", delta); 276 UMA_HISTOGRAM_TIMES("ScreenLocker.AuthenticationFailureTime", delta);
213 } 277 }
214 278
215 UMA_HISTOGRAM_ENUMERATION("ScreenLocker.AuthenticationFailure", 279 UMA_HISTOGRAM_ENUMERATION("ScreenLocker.AuthenticationFailure",
216 unlock_attempt_type_, UnlockType::AUTH_COUNT); 280 unlock_attempt_type_, UnlockType::AUTH_COUNT);
217 281
218 EnableInput(); 282 EnableInput();
219 // Don't enable signout button here as we're showing 283 // Don't enable signout button here as we're showing
220 // MessageBubble. 284 // MessageBubble.
221 285
222 web_ui()->ShowErrorMessage(incorrect_passwords_count_++ 286 delegate_->ShowErrorMessage(incorrect_passwords_count_++
223 ? IDS_LOGIN_ERROR_AUTHENTICATING_2ND_TIME 287 ? IDS_LOGIN_ERROR_AUTHENTICATING_2ND_TIME
224 : IDS_LOGIN_ERROR_AUTHENTICATING, 288 : IDS_LOGIN_ERROR_AUTHENTICATING,
225 HelpAppLauncher::HELP_CANT_ACCESS_ACCOUNT); 289 HelpAppLauncher::HELP_CANT_ACCESS_ACCOUNT);
226 290
227 if (auth_status_consumer_) 291 if (auth_status_consumer_)
228 auth_status_consumer_->OnAuthFailure(error); 292 auth_status_consumer_->OnAuthFailure(error);
229 } 293 }
230 294
231 void ScreenLocker::OnAuthSuccess(const UserContext& user_context) { 295 void ScreenLocker::OnAuthSuccess(const UserContext& user_context) {
232 incorrect_passwords_count_ = 0; 296 incorrect_passwords_count_ = 0;
233 if (authentication_start_time_.is_null()) { 297 if (authentication_start_time_.is_null()) {
234 if (user_context.GetAccountId().is_valid()) 298 if (user_context.GetAccountId().is_valid())
235 LOG(ERROR) << "Start time is not set at authentication success"; 299 LOG(ERROR) << "Start time is not set at authentication success";
236 } else { 300 } else {
237 base::TimeDelta delta = base::Time::Now() - authentication_start_time_; 301 base::TimeDelta delta = base::Time::Now() - authentication_start_time_;
238 VLOG(1) << "Authentication success: " << delta.InSecondsF() << " second(s)"; 302 VLOG(1) << "Authentication success: " << delta.InSecondsF() << " second(s)";
239 UMA_HISTOGRAM_TIMES("ScreenLocker.AuthenticationSuccessTime", delta); 303 UMA_HISTOGRAM_TIMES("ScreenLocker.AuthenticationSuccessTime", delta);
240 } 304 }
241 305
242 UMA_HISTOGRAM_ENUMERATION("ScreenLocker.AuthenticationSuccess", 306 UMA_HISTOGRAM_ENUMERATION("ScreenLocker.AuthenticationSuccess",
243 unlock_attempt_type_, UnlockType::AUTH_COUNT); 307 unlock_attempt_type_, UnlockType::AUTH_COUNT);
244 308
245 const user_manager::User* user = 309 const user_manager::User* user =
246 user_manager::UserManager::Get()->FindUser(user_context.GetAccountId()); 310 user_manager::UserManager::Get()->FindUser(user_context.GetAccountId());
247 if (user) { 311 if (user) {
248 if (!user->is_active()) { 312 if (!user->is_active()) {
249 saved_ime_state_ = NULL; 313 saved_ime_state_ = nullptr;
250 user_manager::UserManager::Get()->SwitchActiveUser( 314 user_manager::UserManager::Get()->SwitchActiveUser(
251 user_context.GetAccountId()); 315 user_context.GetAccountId());
252 } 316 }
253 317
254 // Reset the number of PIN attempts available to the user. We always do this 318 // Reset the number of PIN attempts available to the user. We always do this
255 // because: 319 // because:
256 // 1. If the user signed in with a PIN, that means they should be able to 320 // 1. If the user signed in with a PIN, that means they should be able to
257 // continue signing in with a PIN. 321 // continue signing in with a PIN.
258 // 2. If the user signed in with cryptohome keys, then the PIN timeout is 322 // 2. If the user signed in with cryptohome keys, then the PIN timeout is
259 // going to be reset as well, so it is safe to reset the unlock attempt 323 // going to be reset as well, so it is safe to reset the unlock attempt
(...skipping 12 matching lines...) Expand all
272 336
273 authentication_capture_.reset(new AuthenticationParametersCapture()); 337 authentication_capture_.reset(new AuthenticationParametersCapture());
274 authentication_capture_->user_context = user_context; 338 authentication_capture_->user_context = user_context;
275 339
276 // Add guard for case when something get broken in call chain to unlock 340 // Add guard for case when something get broken in call chain to unlock
277 // for sure. 341 // for sure.
278 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( 342 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
279 FROM_HERE, base::Bind(&ScreenLocker::UnlockOnLoginSuccess, 343 FROM_HERE, base::Bind(&ScreenLocker::UnlockOnLoginSuccess,
280 weak_factory_.GetWeakPtr()), 344 weak_factory_.GetWeakPtr()),
281 base::TimeDelta::FromMilliseconds(kUnlockGuardTimeoutMs)); 345 base::TimeDelta::FromMilliseconds(kUnlockGuardTimeoutMs));
282 web_ui()->AnimateAuthenticationSuccess(); 346 delegate_->AnimateAuthenticationSuccess();
283 } 347 }
284 348
285 void ScreenLocker::OnPasswordAuthSuccess(const UserContext& user_context) { 349 void ScreenLocker::OnPasswordAuthSuccess(const UserContext& user_context) {
286 // The user has signed in using their password, so reset the PIN timeout. 350 // The user has signed in using their password, so reset the PIN timeout.
287 quick_unlock::QuickUnlockStorage* quick_unlock_storage = 351 quick_unlock::QuickUnlockStorage* quick_unlock_storage =
288 quick_unlock::QuickUnlockFactory::GetForAccountId( 352 quick_unlock::QuickUnlockFactory::GetForAccountId(
289 user_context.GetAccountId()); 353 user_context.GetAccountId());
290 if (quick_unlock_storage) 354 if (quick_unlock_storage)
291 quick_unlock_storage->MarkStrongAuth(); 355 quick_unlock_storage->MarkStrongAuth();
292 } 356 }
(...skipping 14 matching lines...) Expand all
307 371
308 VLOG(1) << "Hiding the lock screen."; 372 VLOG(1) << "Hiding the lock screen.";
309 chromeos::ScreenLocker::Hide(); 373 chromeos::ScreenLocker::Hide();
310 } 374 }
311 375
312 void ScreenLocker::Authenticate(const UserContext& user_context) { 376 void ScreenLocker::Authenticate(const UserContext& user_context) {
313 LOG_ASSERT(IsUserLoggedIn(user_context.GetAccountId())) 377 LOG_ASSERT(IsUserLoggedIn(user_context.GetAccountId()))
314 << "Invalid user trying to unlock."; 378 << "Invalid user trying to unlock.";
315 379
316 authentication_start_time_ = base::Time::Now(); 380 authentication_start_time_ = base::Time::Now();
317 web_ui()->SetInputEnabled(false); 381 delegate_->SetInputEnabled(false);
318 if (user_context.IsUsingPin()) 382 if (user_context.IsUsingPin())
319 unlock_attempt_type_ = AUTH_PIN; 383 unlock_attempt_type_ = AUTH_PIN;
320 384
321 const user_manager::User* user = FindUnlockUser(user_context.GetAccountId()); 385 const user_manager::User* user = FindUnlockUser(user_context.GetAccountId());
322 if (user) { 386 if (user) {
323 // Check to see if the user submitted a PIN and it is valid. 387 // Check to see if the user submitted a PIN and it is valid.
324 const std::string pin = user_context.GetKey()->GetSecret(); 388 const std::string pin = user_context.GetKey()->GetSecret();
325 389
326 // We only want to try authenticating the pin if it is a number, 390 // We only want to try authenticating the pin if it is a number,
327 // otherwise we will timeout PIN if the user enters their account password 391 // otherwise we will timeout PIN if the user enters their account password
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
371 return nullptr; 435 return nullptr;
372 } 436 }
373 437
374 void ScreenLocker::OnStartLockCallback(bool locked) { 438 void ScreenLocker::OnStartLockCallback(bool locked) {
375 // Happens in tests that exit with a pending lock. In real lock failure, 439 // Happens in tests that exit with a pending lock. In real lock failure,
376 // ash::LockStateController would cause the current user session to be 440 // ash::LockStateController would cause the current user session to be
377 // terminated. 441 // terminated.
378 if (!locked) 442 if (!locked)
379 return; 443 return;
380 444
381 web_ui()->OnAshLockAnimationFinished(); 445 delegate_->OnAshLockAnimationFinished();
382 446
383 AccessibilityManager::Get()->PlayEarcon( 447 AccessibilityManager::Get()->PlayEarcon(
384 chromeos::SOUND_LOCK, PlaySoundOption::SPOKEN_FEEDBACK_ENABLED); 448 chromeos::SOUND_LOCK, PlaySoundOption::SPOKEN_FEEDBACK_ENABLED);
385 } 449 }
386 450
387 void ScreenLocker::ClearErrors() { 451 void ScreenLocker::ClearErrors() {
388 web_ui()->ClearErrors(); 452 delegate_->ClearErrors();
389 } 453 }
390 454
391 void ScreenLocker::Signout() { 455 void ScreenLocker::Signout() {
392 web_ui()->ClearErrors(); 456 delegate_->ClearErrors();
393 base::RecordAction(UserMetricsAction("ScreenLocker_Signout")); 457 base::RecordAction(UserMetricsAction("ScreenLocker_Signout"));
394 // We expect that this call will not wait for any user input. 458 // We expect that this call will not wait for any user input.
395 // If it changes at some point, we will need to force exit. 459 // If it changes at some point, we will need to force exit.
396 chrome::AttemptUserExit(); 460 chrome::AttemptUserExit();
397 461
398 // Don't hide yet the locker because the chrome screen may become visible 462 // Don't hide yet the locker because the chrome screen may become visible
399 // briefly. 463 // briefly.
400 } 464 }
401 465
402 void ScreenLocker::EnableInput() { 466 void ScreenLocker::EnableInput() {
403 web_ui()->SetInputEnabled(true); 467 delegate_->SetInputEnabled(true);
404 } 468 }
405 469
406 void ScreenLocker::ShowErrorMessage(int error_msg_id, 470 void ScreenLocker::ShowErrorMessage(int error_msg_id,
407 HelpAppLauncher::HelpTopic help_topic_id, 471 HelpAppLauncher::HelpTopic help_topic_id,
408 bool sign_out_only) { 472 bool sign_out_only) {
409 web_ui()->SetInputEnabled(!sign_out_only); 473 delegate_->SetInputEnabled(!sign_out_only);
410 web_ui()->ShowErrorMessage(error_msg_id, help_topic_id); 474 delegate_->ShowErrorMessage(error_msg_id, help_topic_id);
411 } 475 }
412 476
413 void ScreenLocker::SetLoginStatusConsumer( 477 void ScreenLocker::SetLoginStatusConsumer(
414 chromeos::AuthStatusConsumer* consumer) { 478 chromeos::AuthStatusConsumer* consumer) {
415 auth_status_consumer_ = consumer; 479 auth_status_consumer_ = consumer;
416 } 480 }
417 481
418 // static 482 // static
419 void ScreenLocker::InitClass() { 483 void ScreenLocker::InitClass() {
420 DCHECK(!g_screen_lock_observer); 484 DCHECK(!g_screen_lock_observer);
421 g_screen_lock_observer = new ScreenLockObserver; 485 g_screen_lock_observer = new ScreenLockObserver;
422 } 486 }
423 487
424 // static 488 // static
425 void ScreenLocker::ShutDownClass() { 489 void ScreenLocker::ShutDownClass() {
426 DCHECK(g_screen_lock_observer); 490 DCHECK(g_screen_lock_observer);
427 delete g_screen_lock_observer; 491 delete g_screen_lock_observer;
428 g_screen_lock_observer = NULL; 492 g_screen_lock_observer = nullptr;
429 } 493 }
430 494
431 // static 495 // static
432 void ScreenLocker::HandleLockScreenRequest() { 496 void ScreenLocker::HandleLockScreenRequest() {
433 VLOG(1) << "Received LockScreen request from session manager"; 497 VLOG(1) << "Received LockScreen request from session manager";
434 DCHECK(g_screen_lock_observer); 498 DCHECK(g_screen_lock_observer);
435 if (UserAddingScreen::Get()->IsRunning()) { 499 if (UserAddingScreen::Get()->IsRunning()) {
436 VLOG(1) << "Waiting for user adding screen to stop"; 500 VLOG(1) << "Waiting for user adding screen to stop";
437 UserAddingScreen::Get()->AddObserver(g_screen_lock_observer); 501 UserAddingScreen::Get()->AddObserver(g_screen_lock_observer);
438 UserAddingScreen::Get()->Cancel(); 502 UserAddingScreen::Get()->Cancel();
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
504 } 568 }
505 569
506 DCHECK(screen_locker_); 570 DCHECK(screen_locker_);
507 SessionControllerClient::Get()->RunUnlockAnimation( 571 SessionControllerClient::Get()->RunUnlockAnimation(
508 base::Bind(&ScreenLocker::ScheduleDeletion)); 572 base::Bind(&ScreenLocker::ScheduleDeletion));
509 } 573 }
510 574
511 // static 575 // static
512 void ScreenLocker::ScheduleDeletion() { 576 void ScreenLocker::ScheduleDeletion() {
513 // Avoid possible multiple calls. 577 // Avoid possible multiple calls.
514 if (screen_locker_ == NULL) 578 if (screen_locker_ == nullptr)
515 return; 579 return;
516 VLOG(1) << "Deleting ScreenLocker " << screen_locker_; 580 VLOG(1) << "Deleting ScreenLocker " << screen_locker_;
517 581
518 AccessibilityManager::Get()->PlayEarcon( 582 AccessibilityManager::Get()->PlayEarcon(
519 SOUND_UNLOCK, PlaySoundOption::SPOKEN_FEEDBACK_ENABLED); 583 SOUND_UNLOCK, PlaySoundOption::SPOKEN_FEEDBACK_ENABLED);
520 584
521 delete screen_locker_; 585 delete screen_locker_;
522 screen_locker_ = NULL; 586 screen_locker_ = nullptr;
523 } 587 }
524 588
525 //////////////////////////////////////////////////////////////////////////////// 589 ////////////////////////////////////////////////////////////////////////////////
526 // ScreenLocker, private: 590 // ScreenLocker, private:
527 591
528 ScreenLocker::~ScreenLocker() { 592 ScreenLocker::~ScreenLocker() {
529 VLOG(1) << "Destroying ScreenLocker " << this; 593 VLOG(1) << "Destroying ScreenLocker " << this;
530 DCHECK(base::MessageLoopForUI::IsCurrent()); 594 DCHECK(base::MessageLoopForUI::IsCurrent());
531 595
532 if (authenticator_.get()) 596 if (authenticator_.get())
533 authenticator_->SetConsumer(NULL); 597 authenticator_->SetConsumer(nullptr);
534 ClearErrors(); 598 ClearErrors();
535 599
536 screen_locker_ = NULL; 600 screen_locker_ = nullptr;
537 bool state = false; 601 bool state = false;
538 VLOG(1) << "Emitting SCREEN_LOCK_STATE_CHANGED with state=" << state; 602 VLOG(1) << "Emitting SCREEN_LOCK_STATE_CHANGED with state=" << state;
539 content::NotificationService::current()->Notify( 603 content::NotificationService::current()->Notify(
540 chrome::NOTIFICATION_SCREEN_LOCK_STATE_CHANGED, 604 chrome::NOTIFICATION_SCREEN_LOCK_STATE_CHANGED,
541 content::Source<ScreenLocker>(this), 605 content::Source<ScreenLocker>(this),
542 content::Details<bool>(&state)); 606 content::Details<bool>(&state));
543 607
544 VLOG(1) << "Calling session manager's HandleLockScreenDismissed D-Bus method"; 608 VLOG(1) << "Calling session manager's HandleLockScreenDismissed D-Bus method";
545 DBusThreadManager::Get()->GetSessionManagerClient()-> 609 DBusThreadManager::Get()->GetSessionManagerClient()->
546 NotifyLockScreenDismissed(); 610 NotifyLockScreenDismissed();
547 611
548 session_manager::SessionManager::Get()->SetSessionState( 612 session_manager::SessionManager::Get()->SetSessionState(
549 session_manager::SessionState::ACTIVE); 613 session_manager::SessionState::ACTIVE);
550 614
551 if (saved_ime_state_.get()) { 615 if (saved_ime_state_.get()) {
552 input_method::InputMethodManager::Get()->SetState(saved_ime_state_); 616 input_method::InputMethodManager::Get()->SetState(saved_ime_state_);
553 } 617 }
618
619 if (owns_delegate_) {
620 owns_delegate_ = false;
621 delete delegate_;
622 delegate_ = nullptr;
623 }
554 } 624 }
555 625
556 void ScreenLocker::SetAuthenticator(Authenticator* authenticator) { 626 void ScreenLocker::SetAuthenticator(Authenticator* authenticator) {
557 authenticator_ = authenticator; 627 authenticator_ = authenticator;
558 } 628 }
559 629
560 void ScreenLocker::ScreenLockReady() { 630 void ScreenLocker::ScreenLockReady() {
561 locked_ = true; 631 locked_ = true;
562 base::TimeDelta delta = base::Time::Now() - start_time_; 632 base::TimeDelta delta = base::Time::Now() - start_time_;
563 VLOG(1) << "ScreenLocker " << this << " is ready after " 633 VLOG(1) << "ScreenLocker " << this << " is ready after "
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
608 if (scan_result != biod::ScanResult::SCAN_RESULT_SUCCESS) { 678 if (scan_result != biod::ScanResult::SCAN_RESULT_SUCCESS) {
609 OnFingerprintAuthFailure(*active_user); 679 OnFingerprintAuthFailure(*active_user);
610 return; 680 return;
611 } 681 }
612 682
613 UserContext user_context(active_user->GetAccountId()); 683 UserContext user_context(active_user->GetAccountId());
614 if (!base::ContainsKey(matches, active_user->username_hash())) { 684 if (!base::ContainsKey(matches, active_user->username_hash())) {
615 OnFingerprintAuthFailure(*active_user); 685 OnFingerprintAuthFailure(*active_user);
616 return; 686 return;
617 } 687 }
618 web_ui()->SetFingerprintState(active_user->GetAccountId(), 688 delegate_->SetFingerprintState(active_user->GetAccountId(),
619 WebUIScreenLocker::FingerprintState::kSignin); 689 FingerprintState::kSignin);
620 OnAuthSuccess(user_context); 690 OnAuthSuccess(user_context);
621 } 691 }
622 692
623 void ScreenLocker::OnSessionFailed() { 693 void ScreenLocker::OnSessionFailed() {
624 LOG(ERROR) << "Fingerprint session failed."; 694 LOG(ERROR) << "Fingerprint session failed.";
625 } 695 }
626 696
627 void ScreenLocker::OnFingerprintAuthFailure(const user_manager::User& user) { 697 void ScreenLocker::OnFingerprintAuthFailure(const user_manager::User& user) {
628 UMA_HISTOGRAM_ENUMERATION("ScreenLocker.AuthenticationFailure", 698 UMA_HISTOGRAM_ENUMERATION("ScreenLocker.AuthenticationFailure",
629 unlock_attempt_type_, UnlockType::AUTH_COUNT); 699 unlock_attempt_type_, UnlockType::AUTH_COUNT);
630 700
631 web_ui()->SetFingerprintState(user.GetAccountId(), 701 delegate_->SetFingerprintState(user.GetAccountId(),
632 WebUIScreenLocker::FingerprintState::kFailed); 702 FingerprintState::kFailed);
633 703
634 quick_unlock::QuickUnlockStorage* quick_unlock_storage = 704 quick_unlock::QuickUnlockStorage* quick_unlock_storage =
635 quick_unlock::QuickUnlockFactory::GetForUser(&user); 705 quick_unlock::QuickUnlockFactory::GetForUser(&user);
636 if (quick_unlock_storage && 706 if (quick_unlock_storage &&
637 quick_unlock_storage->IsFingerprintAuthenticationAvailable()) { 707 quick_unlock_storage->IsFingerprintAuthenticationAvailable()) {
638 quick_unlock_storage->fingerprint_storage()->AddUnlockAttempt(); 708 quick_unlock_storage->fingerprint_storage()->AddUnlockAttempt();
639 if (quick_unlock_storage->fingerprint_storage()->ExceededUnlockAttempts()) { 709 if (quick_unlock_storage->fingerprint_storage()->ExceededUnlockAttempts()) {
640 web_ui()->SetFingerprintState( 710 delegate_->SetFingerprintState(user.GetAccountId(),
641 user.GetAccountId(), WebUIScreenLocker::FingerprintState::kRemoved); 711 FingerprintState::kRemoved);
642 web_ui()->ShowErrorMessage(IDS_LOGIN_ERROR_FINGERPRINT_MAX_ATTEMPT, 712 delegate_->ShowErrorMessage(IDS_LOGIN_ERROR_FINGERPRINT_MAX_ATTEMPT,
643 HelpAppLauncher::HELP_CANT_ACCESS_ACCOUNT); 713 HelpAppLauncher::HELP_CANT_ACCESS_ACCOUNT);
644 } 714 }
645 } 715 }
646 716
647 if (auth_status_consumer_) { 717 if (auth_status_consumer_) {
648 AuthFailure failure(AuthFailure::UNLOCK_FAILED); 718 AuthFailure failure(AuthFailure::UNLOCK_FAILED);
649 auth_status_consumer_->OnAuthFailure(failure); 719 auth_status_consumer_->OnAuthFailure(failure);
650 } 720 }
651 } 721 }
652 722
653 } // namespace chromeos 723 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698