| OLD | NEW |
| 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/signin/easy_unlock_service_signin_chromeos.h" | 5 #include "chrome/browser/signin/easy_unlock_service_signin_chromeos.h" |
| 6 | 6 |
| 7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
| 8 #include "base/bind.h" | 8 #include "base/bind.h" |
| 9 #include "base/location.h" | 9 #include "base/location.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| 11 #include "base/stl_util.h" | 11 #include "base/stl_util.h" |
| 12 #include "base/sys_info.h" |
| 12 #include "base/thread_task_runner_handle.h" | 13 #include "base/thread_task_runner_handle.h" |
| 13 #include "base/time/time.h" | 14 #include "base/time/time.h" |
| 14 #include "chrome/browser/chromeos/login/easy_unlock/easy_unlock_key_manager.h" | 15 #include "chrome/browser/chromeos/login/easy_unlock/easy_unlock_key_manager.h" |
| 15 #include "chrome/browser/chromeos/login/easy_unlock/easy_unlock_metrics.h" | 16 #include "chrome/browser/chromeos/login/easy_unlock/easy_unlock_metrics.h" |
| 16 #include "chrome/browser/chromeos/login/session/user_session_manager.h" | 17 #include "chrome/browser/chromeos/login/session/user_session_manager.h" |
| 17 #include "chromeos/login/auth/user_context.h" | 18 #include "chromeos/login/auth/user_context.h" |
| 18 | 19 |
| 19 namespace { | 20 namespace { |
| 20 | 21 |
| 21 // The maximum allowed backoff interval when waiting for cryptohome to start. | 22 // The maximum allowed backoff interval when waiting for cryptohome to start. |
| (...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 177 DCHECK_EQ(GetUserEmail(), user_id); | 178 DCHECK_EQ(GetUserEmail(), user_id); |
| 178 | 179 |
| 179 chromeos::RecordEasyUnlockLoginEvent(success | 180 chromeos::RecordEasyUnlockLoginEvent(success |
| 180 ? chromeos::EASY_SIGN_IN_SUCCESS | 181 ? chromeos::EASY_SIGN_IN_SUCCESS |
| 181 : chromeos::EASY_SIGN_IN_FAILURE); | 182 : chromeos::EASY_SIGN_IN_FAILURE); |
| 182 DVLOG(1) << "Easy sign-in " << (success ? "success" : "failure"); | 183 DVLOG(1) << "Easy sign-in " << (success ? "success" : "failure"); |
| 183 } | 184 } |
| 184 | 185 |
| 185 void EasyUnlockServiceSignin::RecordPasswordLoginEvent( | 186 void EasyUnlockServiceSignin::RecordPasswordLoginEvent( |
| 186 const std::string& user_id) const { | 187 const std::string& user_id) const { |
| 187 DCHECK_EQ(GetUserEmail(), user_id); | 188 // This happens during tests where user could login without pod focusing. |
| 189 if (GetUserEmail() != user_id) |
| 190 return; |
| 188 | 191 |
| 189 chromeos::EasyUnlockLoginEvent event = | 192 chromeos::EasyUnlockLoginEvent event = |
| 190 chromeos::EASY_SIGN_IN_LOGIN_EVENT_COUNT; | 193 chromeos::EASY_SIGN_IN_LOGIN_EVENT_COUNT; |
| 191 if (!GetRemoteDevices() || | 194 if (!GetRemoteDevices() || |
| 192 GetHardlockState() == EasyUnlockScreenlockStateHandler::NO_PAIRING) { | 195 GetHardlockState() == EasyUnlockScreenlockStateHandler::NO_PAIRING) { |
| 193 event = chromeos::PASSWORD_SIGN_IN_NO_PAIRING; | 196 event = chromeos::PASSWORD_SIGN_IN_NO_PAIRING; |
| 194 } else if (GetHardlockState() != | 197 } else if (GetHardlockState() != |
| 195 EasyUnlockScreenlockStateHandler::NO_HARDLOCK) { | 198 EasyUnlockScreenlockStateHandler::NO_HARDLOCK) { |
| 196 switch (GetHardlockState()) { | 199 switch (GetHardlockState()) { |
| 197 case EasyUnlockScreenlockStateHandler::NO_HARDLOCK: | 200 case EasyUnlockScreenlockStateHandler::NO_HARDLOCK: |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 317 LoadCurrentUserDataIfNeeded(); | 320 LoadCurrentUserDataIfNeeded(); |
| 318 } | 321 } |
| 319 | 322 |
| 320 void EasyUnlockServiceSignin::LoggedInStateChanged() { | 323 void EasyUnlockServiceSignin::LoggedInStateChanged() { |
| 321 if (!chromeos::LoginState::Get()->IsUserLoggedIn()) | 324 if (!chromeos::LoginState::Get()->IsUserLoggedIn()) |
| 322 return; | 325 return; |
| 323 UnloadApp(); | 326 UnloadApp(); |
| 324 } | 327 } |
| 325 | 328 |
| 326 void EasyUnlockServiceSignin::LoadCurrentUserDataIfNeeded() { | 329 void EasyUnlockServiceSignin::LoadCurrentUserDataIfNeeded() { |
| 330 // TODO(xiyuan): Revisit this when adding tests. |
| 331 if (!base::SysInfo::IsRunningOnChromeOS()) |
| 332 return; |
| 333 |
| 327 if (user_id_.empty() || !service_active_) | 334 if (user_id_.empty() || !service_active_) |
| 328 return; | 335 return; |
| 329 | 336 |
| 330 std::map<std::string, UserData*>::iterator it = user_data_.find(user_id_); | 337 std::map<std::string, UserData*>::iterator it = user_data_.find(user_id_); |
| 331 if (it == user_data_.end()) | 338 if (it == user_data_.end()) |
| 332 user_data_.insert(std::make_pair(user_id_, new UserData())); | 339 user_data_.insert(std::make_pair(user_id_, new UserData())); |
| 333 | 340 |
| 334 UserData* data = user_data_[user_id_]; | 341 UserData* data = user_data_[user_id_]; |
| 335 | 342 |
| 336 if (data->state != USER_DATA_STATE_INITIAL) | 343 if (data->state != USER_DATA_STATE_INITIAL) |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 371 return NULL; | 378 return NULL; |
| 372 | 379 |
| 373 std::map<std::string, UserData*>::const_iterator it = | 380 std::map<std::string, UserData*>::const_iterator it = |
| 374 user_data_.find(user_id_); | 381 user_data_.find(user_id_); |
| 375 if (it == user_data_.end()) | 382 if (it == user_data_.end()) |
| 376 return NULL; | 383 return NULL; |
| 377 if (it->second->state != USER_DATA_STATE_LOADED) | 384 if (it->second->state != USER_DATA_STATE_LOADED) |
| 378 return NULL; | 385 return NULL; |
| 379 return it->second; | 386 return it->second; |
| 380 } | 387 } |
| OLD | NEW |