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" |
(...skipping 20 matching lines...) Expand all Loading... |
31 | 31 |
32 // Calculates the backoff interval that should be used next. | 32 // Calculates the backoff interval that should be used next. |
33 // |backoff| The last backoff interval used. | 33 // |backoff| The last backoff interval used. |
34 uint32 GetNextBackoffInterval(uint32 backoff) { | 34 uint32 GetNextBackoffInterval(uint32 backoff) { |
35 if (backoff == 0u) | 35 if (backoff == 0u) |
36 return kInitialCryptohomeBackoffIntervalMs; | 36 return kInitialCryptohomeBackoffIntervalMs; |
37 return backoff * 2; | 37 return backoff * 2; |
38 } | 38 } |
39 | 39 |
40 void LoadDataForUser( | 40 void LoadDataForUser( |
41 const std::string& user_id, | 41 const user_manager::UserID& user_id, |
42 uint32 backoff_ms, | 42 uint32 backoff_ms, |
43 const chromeos::EasyUnlockKeyManager::GetDeviceDataListCallback& callback); | 43 const chromeos::EasyUnlockKeyManager::GetDeviceDataListCallback& callback); |
44 | 44 |
45 // Callback passed to |LoadDataForUser()|. | 45 // Callback passed to |LoadDataForUser()|. |
46 // If |LoadDataForUser| function succeeded, it invokes |callback| with the | 46 // If |LoadDataForUser| function succeeded, it invokes |callback| with the |
47 // results. | 47 // results. |
48 // If |LoadDataForUser| failed and further retries are allowed, schedules new | 48 // If |LoadDataForUser| failed and further retries are allowed, schedules new |
49 // |LoadDataForUser| call with some backoff. If no further retires are allowed, | 49 // |LoadDataForUser| call with some backoff. If no further retires are allowed, |
50 // it invokes |callback| with the |LoadDataForUser| results. | 50 // it invokes |callback| with the |LoadDataForUser| results. |
51 void RetryDataLoadOnError( | 51 void RetryDataLoadOnError( |
52 const std::string& user_id, | 52 const user_manager::UserID& user_id, |
53 uint32 backoff_ms, | 53 uint32 backoff_ms, |
54 const chromeos::EasyUnlockKeyManager::GetDeviceDataListCallback& callback, | 54 const chromeos::EasyUnlockKeyManager::GetDeviceDataListCallback& callback, |
55 bool success, | 55 bool success, |
56 const chromeos::EasyUnlockDeviceKeyDataList& data_list) { | 56 const chromeos::EasyUnlockDeviceKeyDataList& data_list) { |
57 if (success) { | 57 if (success) { |
58 callback.Run(success, data_list); | 58 callback.Run(success, data_list); |
59 return; | 59 return; |
60 } | 60 } |
61 | 61 |
62 uint32 next_backoff_ms = GetNextBackoffInterval(backoff_ms); | 62 uint32 next_backoff_ms = GetNextBackoffInterval(backoff_ms); |
63 if (next_backoff_ms > kMaxCryptohomeBackoffIntervalMs) { | 63 if (next_backoff_ms > kMaxCryptohomeBackoffIntervalMs) { |
64 callback.Run(false, data_list); | 64 callback.Run(false, data_list); |
65 return; | 65 return; |
66 } | 66 } |
67 | 67 |
68 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( | 68 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
69 FROM_HERE, | 69 FROM_HERE, |
70 base::Bind(&LoadDataForUser, user_id, next_backoff_ms, callback), | 70 base::Bind(&LoadDataForUser, user_id, next_backoff_ms, callback), |
71 base::TimeDelta::FromMilliseconds(next_backoff_ms)); | 71 base::TimeDelta::FromMilliseconds(next_backoff_ms)); |
72 } | 72 } |
73 | 73 |
74 // Loads device data list associated with the user's Easy unlock keys. | 74 // Loads device data list associated with the user's Easy unlock keys. |
75 void LoadDataForUser( | 75 void LoadDataForUser( |
76 const std::string& user_id, | 76 const user_manager::UserID& user_id, |
77 uint32 backoff_ms, | 77 uint32 backoff_ms, |
78 const chromeos::EasyUnlockKeyManager::GetDeviceDataListCallback& callback) { | 78 const chromeos::EasyUnlockKeyManager::GetDeviceDataListCallback& callback) { |
79 chromeos::EasyUnlockKeyManager* key_manager = | 79 chromeos::EasyUnlockKeyManager* key_manager = |
80 chromeos::UserSessionManager::GetInstance()->GetEasyUnlockKeyManager(); | 80 chromeos::UserSessionManager::GetInstance()->GetEasyUnlockKeyManager(); |
81 DCHECK(key_manager); | 81 DCHECK(key_manager); |
82 | 82 |
83 key_manager->GetDeviceDataList( | 83 key_manager->GetDeviceDataList( |
84 chromeos::UserContext(user_id), | 84 chromeos::UserContext(user_id), |
85 base::Bind(&RetryDataLoadOnError, user_id, backoff_ms, callback)); | 85 base::Bind(&RetryDataLoadOnError, user_id, backoff_ms, callback)); |
86 } | 86 } |
87 | 87 |
88 } // namespace | 88 } // namespace |
89 | 89 |
90 EasyUnlockServiceSignin::UserData::UserData() | 90 EasyUnlockServiceSignin::UserData::UserData() |
91 : state(EasyUnlockServiceSignin::USER_DATA_STATE_INITIAL) { | 91 : state(EasyUnlockServiceSignin::USER_DATA_STATE_INITIAL) { |
92 } | 92 } |
93 | 93 |
94 EasyUnlockServiceSignin::UserData::~UserData() {} | 94 EasyUnlockServiceSignin::UserData::~UserData() {} |
95 | 95 |
96 EasyUnlockServiceSignin::EasyUnlockServiceSignin(Profile* profile) | 96 EasyUnlockServiceSignin::EasyUnlockServiceSignin(Profile* profile) |
97 : EasyUnlockService(profile), | 97 : EasyUnlockService(profile), |
| 98 user_id_(std::string(), std::string()), |
98 allow_cryptohome_backoff_(true), | 99 allow_cryptohome_backoff_(true), |
99 service_active_(false), | 100 service_active_(false), |
100 user_pod_last_focused_timestamp_(base::TimeTicks::Now()), | 101 user_pod_last_focused_timestamp_(base::TimeTicks::Now()), |
101 weak_ptr_factory_(this) { | 102 weak_ptr_factory_(this) { |
102 } | 103 } |
103 | 104 |
104 EasyUnlockServiceSignin::~EasyUnlockServiceSignin() { | 105 EasyUnlockServiceSignin::~EasyUnlockServiceSignin() { |
105 } | 106 } |
106 | 107 |
107 void EasyUnlockServiceSignin::SetCurrentUser(const std::string& user_id) { | 108 void EasyUnlockServiceSignin::SetCurrentUser(const user_manager::UserID& user_id
) { |
108 OnFocusedUserChanged(user_id); | 109 OnFocusedUserChanged(user_id); |
109 } | 110 } |
110 | 111 |
111 EasyUnlockService::Type EasyUnlockServiceSignin::GetType() const { | 112 EasyUnlockService::Type EasyUnlockServiceSignin::GetType() const { |
112 return EasyUnlockService::TYPE_SIGNIN; | 113 return EasyUnlockService::TYPE_SIGNIN; |
113 } | 114 } |
114 | 115 |
115 std::string EasyUnlockServiceSignin::GetUserEmail() const { | 116 user_manager::UserID EasyUnlockServiceSignin::GetUserID() const { |
116 return user_id_; | 117 return user_id_; |
117 } | 118 } |
118 | 119 |
119 void EasyUnlockServiceSignin::LaunchSetup() { | 120 void EasyUnlockServiceSignin::LaunchSetup() { |
120 NOTREACHED(); | 121 NOTREACHED(); |
121 } | 122 } |
122 | 123 |
123 const base::DictionaryValue* EasyUnlockServiceSignin::GetPermitAccess() const { | 124 const base::DictionaryValue* EasyUnlockServiceSignin::GetPermitAccess() const { |
124 return NULL; | 125 return NULL; |
125 } | 126 } |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
170 std::string EasyUnlockServiceSignin::GetWrappedSecret() const { | 171 std::string EasyUnlockServiceSignin::GetWrappedSecret() const { |
171 const UserData* data = FindLoadedDataForCurrentUser(); | 172 const UserData* data = FindLoadedDataForCurrentUser(); |
172 // TODO(xiyuan): Use correct remote device instead of hard coded first one. | 173 // TODO(xiyuan): Use correct remote device instead of hard coded first one. |
173 uint32 device_index = 0; | 174 uint32 device_index = 0; |
174 if (!data || data->devices.size() <= device_index) | 175 if (!data || data->devices.size() <= device_index) |
175 return std::string(); | 176 return std::string(); |
176 return data->devices[device_index].wrapped_secret; | 177 return data->devices[device_index].wrapped_secret; |
177 } | 178 } |
178 | 179 |
179 void EasyUnlockServiceSignin::RecordEasySignInOutcome( | 180 void EasyUnlockServiceSignin::RecordEasySignInOutcome( |
180 const std::string& user_id, | 181 const user_manager::UserID& user_id, |
181 bool success) const { | 182 bool success) const { |
182 DCHECK_EQ(GetUserEmail(), user_id); | 183 DCHECK(GetUserID() == user_id); |
183 | 184 |
184 RecordEasyUnlockSigninEvent( | 185 RecordEasyUnlockSigninEvent( |
185 success ? EASY_UNLOCK_SUCCESS : EASY_UNLOCK_FAILURE); | 186 success ? EASY_UNLOCK_SUCCESS : EASY_UNLOCK_FAILURE); |
186 if (success) { | 187 if (success) { |
187 RecordEasyUnlockSigninDuration( | 188 RecordEasyUnlockSigninDuration( |
188 base::TimeTicks::Now() - user_pod_last_focused_timestamp_); | 189 base::TimeTicks::Now() - user_pod_last_focused_timestamp_); |
189 } | 190 } |
190 DVLOG(1) << "Easy sign-in " << (success ? "success" : "failure"); | 191 DVLOG(1) << "Easy sign-in " << (success ? "success" : "failure"); |
191 } | 192 } |
192 | 193 |
193 void EasyUnlockServiceSignin::RecordPasswordLoginEvent( | 194 void EasyUnlockServiceSignin::RecordPasswordLoginEvent( |
194 const std::string& user_id) const { | 195 const user_manager::UserID& user_id) const { |
195 // This happens during tests, where a user could log in without the user pod | 196 // This happens during tests, where a user could log in without the user pod |
196 // being focused. | 197 // being focused. |
197 if (GetUserEmail() != user_id) | 198 if (GetUserID() != user_id) |
198 return; | 199 return; |
199 | 200 |
200 if (!IsEnabled()) | 201 if (!IsEnabled()) |
201 return; | 202 return; |
202 | 203 |
203 EasyUnlockAuthEvent event = GetPasswordAuthEvent(); | 204 EasyUnlockAuthEvent event = GetPasswordAuthEvent(); |
204 RecordEasyUnlockSigninEvent(event); | 205 RecordEasyUnlockSigninEvent(event); |
205 DVLOG(1) << "Easy Sign-in password login event, event=" << event; | 206 DVLOG(1) << "Easy Sign-in password login event, event=" << event; |
206 } | 207 } |
207 | 208 |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
277 // in tests, the screen type might be different. | 278 // in tests, the screen type might be different. |
278 if (screen_type != | 279 if (screen_type != |
279 proximity_auth::ScreenlockBridge::LockHandler::SIGNIN_SCREEN) | 280 proximity_auth::ScreenlockBridge::LockHandler::SIGNIN_SCREEN) |
280 return; | 281 return; |
281 | 282 |
282 DisableAppWithoutResettingScreenlockState(); | 283 DisableAppWithoutResettingScreenlockState(); |
283 | 284 |
284 Shutdown(); | 285 Shutdown(); |
285 } | 286 } |
286 | 287 |
287 void EasyUnlockServiceSignin::OnFocusedUserChanged(const std::string& user_id) { | 288 void EasyUnlockServiceSignin::OnFocusedUserChanged(const user_manager::UserID& u
ser_id) { |
288 if (user_id_ == user_id) | 289 if (user_id_ == user_id) |
289 return; | 290 return; |
290 | 291 |
291 // Setting or clearing the user_id may changed |IsAllowed| value, so in these | 292 // Setting or clearing the user_id may changed |IsAllowed| value, so in these |
292 // cases update the app state. Otherwise, it's enough to notify the app the | 293 // cases update the app state. Otherwise, it's enough to notify the app the |
293 // user data has been updated. | 294 // user data has been updated. |
294 bool should_update_app_state = user_id_.empty() != user_id.empty(); | 295 bool should_update_app_state = user_id_.empty() != user_id.empty(); |
295 user_id_ = user_id; | 296 user_id_ = user_id; |
296 user_pod_last_focused_timestamp_ = base::TimeTicks::Now(); | 297 user_pod_last_focused_timestamp_ = base::TimeTicks::Now(); |
297 | 298 |
(...skipping 25 matching lines...) Expand all Loading... |
323 } | 324 } |
324 | 325 |
325 void EasyUnlockServiceSignin::LoadCurrentUserDataIfNeeded() { | 326 void EasyUnlockServiceSignin::LoadCurrentUserDataIfNeeded() { |
326 // TODO(xiyuan): Revisit this when adding tests. | 327 // TODO(xiyuan): Revisit this when adding tests. |
327 if (!base::SysInfo::IsRunningOnChromeOS()) | 328 if (!base::SysInfo::IsRunningOnChromeOS()) |
328 return; | 329 return; |
329 | 330 |
330 if (user_id_.empty() || !service_active_) | 331 if (user_id_.empty() || !service_active_) |
331 return; | 332 return; |
332 | 333 |
333 std::map<std::string, UserData*>::iterator it = user_data_.find(user_id_); | 334 std::map<user_manager::UserID, UserData*>::iterator it = user_data_.find(user_
id_); |
334 if (it == user_data_.end()) | 335 if (it == user_data_.end()) |
335 user_data_.insert(std::make_pair(user_id_, new UserData())); | 336 user_data_.insert(std::make_pair(user_id_, new UserData())); |
336 | 337 |
337 UserData* data = user_data_[user_id_]; | 338 UserData* data = user_data_[user_id_]; |
338 | 339 |
339 if (data->state != USER_DATA_STATE_INITIAL) | 340 if (data->state != USER_DATA_STATE_INITIAL) |
340 return; | 341 return; |
341 data->state = USER_DATA_STATE_LOADING; | 342 data->state = USER_DATA_STATE_LOADING; |
342 | 343 |
343 LoadDataForUser( | 344 LoadDataForUser( |
344 user_id_, | 345 user_id_, |
345 allow_cryptohome_backoff_ ? 0u : kMaxCryptohomeBackoffIntervalMs, | 346 allow_cryptohome_backoff_ ? 0u : kMaxCryptohomeBackoffIntervalMs, |
346 base::Bind(&EasyUnlockServiceSignin::OnUserDataLoaded, | 347 base::Bind(&EasyUnlockServiceSignin::OnUserDataLoaded, |
347 weak_ptr_factory_.GetWeakPtr(), | 348 weak_ptr_factory_.GetWeakPtr(), |
348 user_id_)); | 349 user_id_)); |
349 } | 350 } |
350 | 351 |
351 void EasyUnlockServiceSignin::OnUserDataLoaded( | 352 void EasyUnlockServiceSignin::OnUserDataLoaded( |
352 const std::string& user_id, | 353 const user_manager::UserID& user_id, |
353 bool success, | 354 bool success, |
354 const chromeos::EasyUnlockDeviceKeyDataList& devices) { | 355 const chromeos::EasyUnlockDeviceKeyDataList& devices) { |
355 allow_cryptohome_backoff_ = false; | 356 allow_cryptohome_backoff_ = false; |
356 | 357 |
357 UserData* data = user_data_[user_id]; | 358 UserData* data = user_data_[user_id]; |
358 data->state = USER_DATA_STATE_LOADED; | 359 data->state = USER_DATA_STATE_LOADED; |
359 if (success) { | 360 if (success) { |
360 data->devices = devices; | 361 data->devices = devices; |
361 chromeos::EasyUnlockKeyManager::DeviceDataListToRemoteDeviceList( | 362 chromeos::EasyUnlockKeyManager::DeviceDataListToRemoteDeviceList( |
362 user_id, devices, &data->remote_devices_value); | 363 user_id, devices, &data->remote_devices_value); |
(...skipping 15 matching lines...) Expand all Loading... |
378 // that it has to refresh it's user data. | 379 // that it has to refresh it's user data. |
379 if (user_id == user_id_) | 380 if (user_id == user_id_) |
380 NotifyUserUpdated(); | 381 NotifyUserUpdated(); |
381 } | 382 } |
382 | 383 |
383 const EasyUnlockServiceSignin::UserData* | 384 const EasyUnlockServiceSignin::UserData* |
384 EasyUnlockServiceSignin::FindLoadedDataForCurrentUser() const { | 385 EasyUnlockServiceSignin::FindLoadedDataForCurrentUser() const { |
385 if (user_id_.empty()) | 386 if (user_id_.empty()) |
386 return NULL; | 387 return NULL; |
387 | 388 |
388 std::map<std::string, UserData*>::const_iterator it = | 389 std::map<user_manager::UserID, UserData*>::const_iterator it = |
389 user_data_.find(user_id_); | 390 user_data_.find(user_id_); |
390 if (it == user_data_.end()) | 391 if (it == user_data_.end()) |
391 return NULL; | 392 return NULL; |
392 if (it->second->state != USER_DATA_STATE_LOADED) | 393 if (it->second->state != USER_DATA_STATE_LOADED) |
393 return NULL; | 394 return NULL; |
394 return it->second; | 395 return it->second; |
395 } | 396 } |
OLD | NEW |