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

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

Issue 2859363003: cros: Initial structure for views-based lock. (Closed)
Patch Set: Update session state in chrome 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() {}
James Cook 2017/05/08 22:04:20 nit: = default where you can (and above)
jdufault 2017/05/08 23:02:34 Done.
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 // TODO(jdufault): Calling ash::ShowLockScreenInWidget should be a mojo
196 new ScreenlockIconSource(screenlock_icon_provider_->AsWeakPtr()); 246 // call. We should only set the session state to locked after the mojo call
197 content::URLDataSource::Add(web_ui()->GetWebContents()->GetBrowserContext(), 247 // has completed.
198 screenlock_icon_source); 248 LockWindow* lock_window = new LockWindow();
249 lock_window->SetBounds(
250 display::Screen::GetScreen()->GetPrimaryDisplay().bounds());
251 ash::ShowLockScreenInWidget(lock_window);
James Cook 2017/05/08 22:04:20 This is pretty weird (injecting ash-based views in
jdufault 2017/05/08 23:02:35 LockWindow will move into ash/ soon. I want to get
252 session_manager::SessionManager::Get()->SetSessionState(
253 session_manager::SessionState::LOCKED);
254 } else {
255 web_ui_.reset(new WebUIScreenLocker(this));
256 delegate_ = web_ui_.get();
257 owns_delegate_ = false;
258 web_ui_->LockScreen();
259
260 // Ownership of |icon_image_source| is passed.
261 screenlock_icon_provider_.reset(new ScreenlockIconProvider);
James Cook 2017/05/08 22:04:20 nit: MakeUnique while you're here
jdufault 2017/05/08 23:02:34 Done.
262 ScreenlockIconSource* screenlock_icon_source =
263 new ScreenlockIconSource(screenlock_icon_provider_->AsWeakPtr());
264 content::URLDataSource::Add(web_ui_->web_contents()->GetBrowserContext(),
265 screenlock_icon_source);
266 }
199 267
200 // Start locking on ash side. 268 // Start locking on ash side.
201 SessionControllerClient::Get()->StartLock(base::Bind( 269 SessionControllerClient::Get()->StartLock(base::Bind(
202 &ScreenLocker::OnStartLockCallback, weak_factory_.GetWeakPtr())); 270 &ScreenLocker::OnStartLockCallback, weak_factory_.GetWeakPtr()));
203 } 271 }
204 272
205 void ScreenLocker::OnAuthFailure(const AuthFailure& error) { 273 void ScreenLocker::OnAuthFailure(const AuthFailure& error) {
206 base::RecordAction(UserMetricsAction("ScreenLocker_OnLoginFailure")); 274 base::RecordAction(UserMetricsAction("ScreenLocker_OnLoginFailure"));
207 if (authentication_start_time_.is_null()) { 275 if (authentication_start_time_.is_null()) {
208 LOG(ERROR) << "Start time is not set at authentication failure"; 276 LOG(ERROR) << "Start time is not set at authentication failure";
209 } else { 277 } else {
210 base::TimeDelta delta = base::Time::Now() - authentication_start_time_; 278 base::TimeDelta delta = base::Time::Now() - authentication_start_time_;
211 VLOG(1) << "Authentication failure: " << delta.InSecondsF() << " second(s)"; 279 VLOG(1) << "Authentication failure: " << delta.InSecondsF() << " second(s)";
212 UMA_HISTOGRAM_TIMES("ScreenLocker.AuthenticationFailureTime", delta); 280 UMA_HISTOGRAM_TIMES("ScreenLocker.AuthenticationFailureTime", delta);
213 } 281 }
214 282
215 UMA_HISTOGRAM_ENUMERATION("ScreenLocker.AuthenticationFailure", 283 UMA_HISTOGRAM_ENUMERATION("ScreenLocker.AuthenticationFailure",
216 unlock_attempt_type_, UnlockType::AUTH_COUNT); 284 unlock_attempt_type_, UnlockType::AUTH_COUNT);
217 285
218 EnableInput(); 286 EnableInput();
219 // Don't enable signout button here as we're showing 287 // Don't enable signout button here as we're showing
220 // MessageBubble. 288 // MessageBubble.
221 289
222 web_ui()->ShowErrorMessage(incorrect_passwords_count_++ 290 delegate_->ShowErrorMessage(incorrect_passwords_count_++
223 ? IDS_LOGIN_ERROR_AUTHENTICATING_2ND_TIME 291 ? IDS_LOGIN_ERROR_AUTHENTICATING_2ND_TIME
224 : IDS_LOGIN_ERROR_AUTHENTICATING, 292 : IDS_LOGIN_ERROR_AUTHENTICATING,
225 HelpAppLauncher::HELP_CANT_ACCESS_ACCOUNT); 293 HelpAppLauncher::HELP_CANT_ACCESS_ACCOUNT);
226 294
227 if (auth_status_consumer_) 295 if (auth_status_consumer_)
228 auth_status_consumer_->OnAuthFailure(error); 296 auth_status_consumer_->OnAuthFailure(error);
229 } 297 }
230 298
231 void ScreenLocker::OnAuthSuccess(const UserContext& user_context) { 299 void ScreenLocker::OnAuthSuccess(const UserContext& user_context) {
232 incorrect_passwords_count_ = 0; 300 incorrect_passwords_count_ = 0;
233 if (authentication_start_time_.is_null()) { 301 if (authentication_start_time_.is_null()) {
234 if (user_context.GetAccountId().is_valid()) 302 if (user_context.GetAccountId().is_valid())
235 LOG(ERROR) << "Start time is not set at authentication success"; 303 LOG(ERROR) << "Start time is not set at authentication success";
236 } else { 304 } else {
237 base::TimeDelta delta = base::Time::Now() - authentication_start_time_; 305 base::TimeDelta delta = base::Time::Now() - authentication_start_time_;
238 VLOG(1) << "Authentication success: " << delta.InSecondsF() << " second(s)"; 306 VLOG(1) << "Authentication success: " << delta.InSecondsF() << " second(s)";
239 UMA_HISTOGRAM_TIMES("ScreenLocker.AuthenticationSuccessTime", delta); 307 UMA_HISTOGRAM_TIMES("ScreenLocker.AuthenticationSuccessTime", delta);
240 } 308 }
241 309
242 UMA_HISTOGRAM_ENUMERATION("ScreenLocker.AuthenticationSuccess", 310 UMA_HISTOGRAM_ENUMERATION("ScreenLocker.AuthenticationSuccess",
243 unlock_attempt_type_, UnlockType::AUTH_COUNT); 311 unlock_attempt_type_, UnlockType::AUTH_COUNT);
244 312
245 const user_manager::User* user = 313 const user_manager::User* user =
246 user_manager::UserManager::Get()->FindUser(user_context.GetAccountId()); 314 user_manager::UserManager::Get()->FindUser(user_context.GetAccountId());
247 if (user) { 315 if (user) {
248 if (!user->is_active()) { 316 if (!user->is_active()) {
249 saved_ime_state_ = NULL; 317 saved_ime_state_ = nullptr;
250 user_manager::UserManager::Get()->SwitchActiveUser( 318 user_manager::UserManager::Get()->SwitchActiveUser(
251 user_context.GetAccountId()); 319 user_context.GetAccountId());
252 } 320 }
253 321
254 // Reset the number of PIN attempts available to the user. We always do this 322 // Reset the number of PIN attempts available to the user. We always do this
255 // because: 323 // because:
256 // 1. If the user signed in with a PIN, that means they should be able to 324 // 1. If the user signed in with a PIN, that means they should be able to
257 // continue signing in with a PIN. 325 // continue signing in with a PIN.
258 // 2. If the user signed in with cryptohome keys, then the PIN timeout is 326 // 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 327 // going to be reset as well, so it is safe to reset the unlock attempt
(...skipping 12 matching lines...) Expand all
272 340
273 authentication_capture_.reset(new AuthenticationParametersCapture()); 341 authentication_capture_.reset(new AuthenticationParametersCapture());
274 authentication_capture_->user_context = user_context; 342 authentication_capture_->user_context = user_context;
275 343
276 // Add guard for case when something get broken in call chain to unlock 344 // Add guard for case when something get broken in call chain to unlock
277 // for sure. 345 // for sure.
278 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( 346 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
279 FROM_HERE, base::Bind(&ScreenLocker::UnlockOnLoginSuccess, 347 FROM_HERE, base::Bind(&ScreenLocker::UnlockOnLoginSuccess,
280 weak_factory_.GetWeakPtr()), 348 weak_factory_.GetWeakPtr()),
281 base::TimeDelta::FromMilliseconds(kUnlockGuardTimeoutMs)); 349 base::TimeDelta::FromMilliseconds(kUnlockGuardTimeoutMs));
282 web_ui()->AnimateAuthenticationSuccess(); 350 delegate_->AnimateAuthenticationSuccess();
283 } 351 }
284 352
285 void ScreenLocker::OnPasswordAuthSuccess(const UserContext& user_context) { 353 void ScreenLocker::OnPasswordAuthSuccess(const UserContext& user_context) {
286 // The user has signed in using their password, so reset the PIN timeout. 354 // The user has signed in using their password, so reset the PIN timeout.
287 quick_unlock::QuickUnlockStorage* quick_unlock_storage = 355 quick_unlock::QuickUnlockStorage* quick_unlock_storage =
288 quick_unlock::QuickUnlockFactory::GetForAccountId( 356 quick_unlock::QuickUnlockFactory::GetForAccountId(
289 user_context.GetAccountId()); 357 user_context.GetAccountId());
290 if (quick_unlock_storage) 358 if (quick_unlock_storage)
291 quick_unlock_storage->MarkStrongAuth(); 359 quick_unlock_storage->MarkStrongAuth();
292 } 360 }
(...skipping 14 matching lines...) Expand all
307 375
308 VLOG(1) << "Hiding the lock screen."; 376 VLOG(1) << "Hiding the lock screen.";
309 chromeos::ScreenLocker::Hide(); 377 chromeos::ScreenLocker::Hide();
310 } 378 }
311 379
312 void ScreenLocker::Authenticate(const UserContext& user_context) { 380 void ScreenLocker::Authenticate(const UserContext& user_context) {
313 LOG_ASSERT(IsUserLoggedIn(user_context.GetAccountId())) 381 LOG_ASSERT(IsUserLoggedIn(user_context.GetAccountId()))
314 << "Invalid user trying to unlock."; 382 << "Invalid user trying to unlock.";
315 383
316 authentication_start_time_ = base::Time::Now(); 384 authentication_start_time_ = base::Time::Now();
317 web_ui()->SetInputEnabled(false); 385 delegate_->SetInputEnabled(false);
318 if (user_context.IsUsingPin()) 386 if (user_context.IsUsingPin())
319 unlock_attempt_type_ = AUTH_PIN; 387 unlock_attempt_type_ = AUTH_PIN;
320 388
321 const user_manager::User* user = FindUnlockUser(user_context.GetAccountId()); 389 const user_manager::User* user = FindUnlockUser(user_context.GetAccountId());
322 if (user) { 390 if (user) {
323 // Check to see if the user submitted a PIN and it is valid. 391 // Check to see if the user submitted a PIN and it is valid.
324 const std::string pin = user_context.GetKey()->GetSecret(); 392 const std::string pin = user_context.GetKey()->GetSecret();
325 393
326 // We only want to try authenticating the pin if it is a number, 394 // 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 395 // 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; 439 return nullptr;
372 } 440 }
373 441
374 void ScreenLocker::OnStartLockCallback(bool locked) { 442 void ScreenLocker::OnStartLockCallback(bool locked) {
375 // Happens in tests that exit with a pending lock. In real lock failure, 443 // Happens in tests that exit with a pending lock. In real lock failure,
376 // ash::LockStateController would cause the current user session to be 444 // ash::LockStateController would cause the current user session to be
377 // terminated. 445 // terminated.
378 if (!locked) 446 if (!locked)
379 return; 447 return;
380 448
381 web_ui()->OnAshLockAnimationFinished(); 449 delegate_->OnAshLockAnimationFinished();
382 450
383 AccessibilityManager::Get()->PlayEarcon( 451 AccessibilityManager::Get()->PlayEarcon(
384 chromeos::SOUND_LOCK, PlaySoundOption::SPOKEN_FEEDBACK_ENABLED); 452 chromeos::SOUND_LOCK, PlaySoundOption::SPOKEN_FEEDBACK_ENABLED);
385 } 453 }
386 454
387 void ScreenLocker::ClearErrors() { 455 void ScreenLocker::ClearErrors() {
388 web_ui()->ClearErrors(); 456 delegate_->ClearErrors();
389 } 457 }
390 458
391 void ScreenLocker::Signout() { 459 void ScreenLocker::Signout() {
392 web_ui()->ClearErrors(); 460 delegate_->ClearErrors();
393 base::RecordAction(UserMetricsAction("ScreenLocker_Signout")); 461 base::RecordAction(UserMetricsAction("ScreenLocker_Signout"));
394 // We expect that this call will not wait for any user input. 462 // 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. 463 // If it changes at some point, we will need to force exit.
396 chrome::AttemptUserExit(); 464 chrome::AttemptUserExit();
397 465
398 // Don't hide yet the locker because the chrome screen may become visible 466 // Don't hide yet the locker because the chrome screen may become visible
399 // briefly. 467 // briefly.
400 } 468 }
401 469
402 void ScreenLocker::EnableInput() { 470 void ScreenLocker::EnableInput() {
403 web_ui()->SetInputEnabled(true); 471 delegate_->SetInputEnabled(true);
404 } 472 }
405 473
406 void ScreenLocker::ShowErrorMessage(int error_msg_id, 474 void ScreenLocker::ShowErrorMessage(int error_msg_id,
407 HelpAppLauncher::HelpTopic help_topic_id, 475 HelpAppLauncher::HelpTopic help_topic_id,
408 bool sign_out_only) { 476 bool sign_out_only) {
409 web_ui()->SetInputEnabled(!sign_out_only); 477 delegate_->SetInputEnabled(!sign_out_only);
410 web_ui()->ShowErrorMessage(error_msg_id, help_topic_id); 478 delegate_->ShowErrorMessage(error_msg_id, help_topic_id);
411 } 479 }
412 480
413 void ScreenLocker::SetLoginStatusConsumer( 481 void ScreenLocker::SetLoginStatusConsumer(
414 chromeos::AuthStatusConsumer* consumer) { 482 chromeos::AuthStatusConsumer* consumer) {
415 auth_status_consumer_ = consumer; 483 auth_status_consumer_ = consumer;
416 } 484 }
417 485
418 // static 486 // static
419 void ScreenLocker::InitClass() { 487 void ScreenLocker::InitClass() {
420 DCHECK(!g_screen_lock_observer); 488 DCHECK(!g_screen_lock_observer);
421 g_screen_lock_observer = new ScreenLockObserver; 489 g_screen_lock_observer = new ScreenLockObserver;
422 } 490 }
423 491
424 // static 492 // static
425 void ScreenLocker::ShutDownClass() { 493 void ScreenLocker::ShutDownClass() {
426 DCHECK(g_screen_lock_observer); 494 DCHECK(g_screen_lock_observer);
427 delete g_screen_lock_observer; 495 delete g_screen_lock_observer;
428 g_screen_lock_observer = NULL; 496 g_screen_lock_observer = nullptr;
429 } 497 }
430 498
431 // static 499 // static
432 void ScreenLocker::HandleLockScreenRequest() { 500 void ScreenLocker::HandleLockScreenRequest() {
433 VLOG(1) << "Received LockScreen request from session manager"; 501 VLOG(1) << "Received LockScreen request from session manager";
434 DCHECK(g_screen_lock_observer); 502 DCHECK(g_screen_lock_observer);
435 if (UserAddingScreen::Get()->IsRunning()) { 503 if (UserAddingScreen::Get()->IsRunning()) {
436 VLOG(1) << "Waiting for user adding screen to stop"; 504 VLOG(1) << "Waiting for user adding screen to stop";
437 UserAddingScreen::Get()->AddObserver(g_screen_lock_observer); 505 UserAddingScreen::Get()->AddObserver(g_screen_lock_observer);
438 UserAddingScreen::Get()->Cancel(); 506 UserAddingScreen::Get()->Cancel();
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
504 } 572 }
505 573
506 DCHECK(screen_locker_); 574 DCHECK(screen_locker_);
507 SessionControllerClient::Get()->RunUnlockAnimation( 575 SessionControllerClient::Get()->RunUnlockAnimation(
508 base::Bind(&ScreenLocker::ScheduleDeletion)); 576 base::Bind(&ScreenLocker::ScheduleDeletion));
509 } 577 }
510 578
511 // static 579 // static
512 void ScreenLocker::ScheduleDeletion() { 580 void ScreenLocker::ScheduleDeletion() {
513 // Avoid possible multiple calls. 581 // Avoid possible multiple calls.
514 if (screen_locker_ == NULL) 582 if (screen_locker_ == nullptr)
515 return; 583 return;
516 VLOG(1) << "Deleting ScreenLocker " << screen_locker_; 584 VLOG(1) << "Deleting ScreenLocker " << screen_locker_;
517 585
518 AccessibilityManager::Get()->PlayEarcon( 586 AccessibilityManager::Get()->PlayEarcon(
519 SOUND_UNLOCK, PlaySoundOption::SPOKEN_FEEDBACK_ENABLED); 587 SOUND_UNLOCK, PlaySoundOption::SPOKEN_FEEDBACK_ENABLED);
520 588
521 delete screen_locker_; 589 delete screen_locker_;
522 screen_locker_ = NULL; 590 screen_locker_ = nullptr;
523 } 591 }
524 592
525 //////////////////////////////////////////////////////////////////////////////// 593 ////////////////////////////////////////////////////////////////////////////////
526 // ScreenLocker, private: 594 // ScreenLocker, private:
527 595
528 ScreenLocker::~ScreenLocker() { 596 ScreenLocker::~ScreenLocker() {
529 VLOG(1) << "Destroying ScreenLocker " << this; 597 VLOG(1) << "Destroying ScreenLocker " << this;
530 DCHECK(base::MessageLoopForUI::IsCurrent()); 598 DCHECK(base::MessageLoopForUI::IsCurrent());
531 599
532 if (authenticator_.get()) 600 if (authenticator_.get())
533 authenticator_->SetConsumer(NULL); 601 authenticator_->SetConsumer(nullptr);
534 ClearErrors(); 602 ClearErrors();
535 603
536 screen_locker_ = NULL; 604 screen_locker_ = nullptr;
537 bool state = false; 605 bool state = false;
538 VLOG(1) << "Emitting SCREEN_LOCK_STATE_CHANGED with state=" << state; 606 VLOG(1) << "Emitting SCREEN_LOCK_STATE_CHANGED with state=" << state;
539 content::NotificationService::current()->Notify( 607 content::NotificationService::current()->Notify(
540 chrome::NOTIFICATION_SCREEN_LOCK_STATE_CHANGED, 608 chrome::NOTIFICATION_SCREEN_LOCK_STATE_CHANGED,
541 content::Source<ScreenLocker>(this), 609 content::Source<ScreenLocker>(this),
542 content::Details<bool>(&state)); 610 content::Details<bool>(&state));
543 611
544 VLOG(1) << "Calling session manager's HandleLockScreenDismissed D-Bus method"; 612 VLOG(1) << "Calling session manager's HandleLockScreenDismissed D-Bus method";
545 DBusThreadManager::Get()->GetSessionManagerClient()-> 613 DBusThreadManager::Get()->GetSessionManagerClient()->
546 NotifyLockScreenDismissed(); 614 NotifyLockScreenDismissed();
547 615
548 session_manager::SessionManager::Get()->SetSessionState( 616 session_manager::SessionManager::Get()->SetSessionState(
549 session_manager::SessionState::ACTIVE); 617 session_manager::SessionState::ACTIVE);
550 618
551 if (saved_ime_state_.get()) { 619 if (saved_ime_state_.get()) {
552 input_method::InputMethodManager::Get()->SetState(saved_ime_state_); 620 input_method::InputMethodManager::Get()->SetState(saved_ime_state_);
553 } 621 }
622
623 if (owns_delegate_) {
624 owns_delegate_ = false;
625 delete delegate_;
626 delegate_ = nullptr;
627 }
554 } 628 }
555 629
556 void ScreenLocker::SetAuthenticator(Authenticator* authenticator) { 630 void ScreenLocker::SetAuthenticator(Authenticator* authenticator) {
557 authenticator_ = authenticator; 631 authenticator_ = authenticator;
558 } 632 }
559 633
560 void ScreenLocker::ScreenLockReady() { 634 void ScreenLocker::ScreenLockReady() {
561 locked_ = true; 635 locked_ = true;
562 base::TimeDelta delta = base::Time::Now() - start_time_; 636 base::TimeDelta delta = base::Time::Now() - start_time_;
563 VLOG(1) << "ScreenLocker " << this << " is ready after " 637 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) { 682 if (scan_result != biod::ScanResult::SCAN_RESULT_SUCCESS) {
609 OnFingerprintAuthFailure(*active_user); 683 OnFingerprintAuthFailure(*active_user);
610 return; 684 return;
611 } 685 }
612 686
613 UserContext user_context(active_user->GetAccountId()); 687 UserContext user_context(active_user->GetAccountId());
614 if (!base::ContainsKey(matches, active_user->username_hash())) { 688 if (!base::ContainsKey(matches, active_user->username_hash())) {
615 OnFingerprintAuthFailure(*active_user); 689 OnFingerprintAuthFailure(*active_user);
616 return; 690 return;
617 } 691 }
618 web_ui()->SetFingerprintState(active_user->GetAccountId(), 692 delegate_->SetFingerprintState(active_user->GetAccountId(),
619 WebUIScreenLocker::FingerprintState::kSignin); 693 FingerprintState::kSignin);
620 OnAuthSuccess(user_context); 694 OnAuthSuccess(user_context);
621 } 695 }
622 696
623 void ScreenLocker::OnSessionFailed() { 697 void ScreenLocker::OnSessionFailed() {
624 LOG(ERROR) << "Fingerprint session failed."; 698 LOG(ERROR) << "Fingerprint session failed.";
625 } 699 }
626 700
627 void ScreenLocker::OnFingerprintAuthFailure(const user_manager::User& user) { 701 void ScreenLocker::OnFingerprintAuthFailure(const user_manager::User& user) {
628 UMA_HISTOGRAM_ENUMERATION("ScreenLocker.AuthenticationFailure", 702 UMA_HISTOGRAM_ENUMERATION("ScreenLocker.AuthenticationFailure",
629 unlock_attempt_type_, UnlockType::AUTH_COUNT); 703 unlock_attempt_type_, UnlockType::AUTH_COUNT);
630 704
631 web_ui()->SetFingerprintState(user.GetAccountId(), 705 delegate_->SetFingerprintState(user.GetAccountId(),
632 WebUIScreenLocker::FingerprintState::kFailed); 706 FingerprintState::kFailed);
633 707
634 quick_unlock::QuickUnlockStorage* quick_unlock_storage = 708 quick_unlock::QuickUnlockStorage* quick_unlock_storage =
635 quick_unlock::QuickUnlockFactory::GetForUser(&user); 709 quick_unlock::QuickUnlockFactory::GetForUser(&user);
636 if (quick_unlock_storage && 710 if (quick_unlock_storage &&
637 quick_unlock_storage->IsFingerprintAuthenticationAvailable()) { 711 quick_unlock_storage->IsFingerprintAuthenticationAvailable()) {
638 quick_unlock_storage->fingerprint_storage()->AddUnlockAttempt(); 712 quick_unlock_storage->fingerprint_storage()->AddUnlockAttempt();
639 if (quick_unlock_storage->fingerprint_storage()->ExceededUnlockAttempts()) { 713 if (quick_unlock_storage->fingerprint_storage()->ExceededUnlockAttempts()) {
640 web_ui()->SetFingerprintState( 714 delegate_->SetFingerprintState(user.GetAccountId(),
641 user.GetAccountId(), WebUIScreenLocker::FingerprintState::kRemoved); 715 FingerprintState::kRemoved);
642 web_ui()->ShowErrorMessage(IDS_LOGIN_ERROR_FINGERPRINT_MAX_ATTEMPT, 716 delegate_->ShowErrorMessage(IDS_LOGIN_ERROR_FINGERPRINT_MAX_ATTEMPT,
643 HelpAppLauncher::HELP_CANT_ACCESS_ACCOUNT); 717 HelpAppLauncher::HELP_CANT_ACCESS_ACCOUNT);
644 } 718 }
645 } 719 }
646 720
647 if (auth_status_consumer_) { 721 if (auth_status_consumer_) {
648 AuthFailure failure(AuthFailure::UNLOCK_FAILED); 722 AuthFailure failure(AuthFailure::UNLOCK_FAILED);
649 auth_status_consumer_->OnAuthFailure(failure); 723 auth_status_consumer_->OnAuthFailure(failure);
650 } 724 }
651 } 725 }
652 726
653 } // namespace chromeos 727 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698