Chromium Code Reviews| Index: chrome/browser/signin/easy_unlock_service_signin_chromeos.cc |
| diff --git a/chrome/browser/signin/easy_unlock_service_signin_chromeos.cc b/chrome/browser/signin/easy_unlock_service_signin_chromeos.cc |
| index 2feeb6912148a049df18aae1fa1cfb3cc6869eaa..2fde377178d409b55782301642e41f09cecade8c 100644 |
| --- a/chrome/browser/signin/easy_unlock_service_signin_chromeos.cc |
| +++ b/chrome/browser/signin/easy_unlock_service_signin_chromeos.cc |
| @@ -5,7 +5,6 @@ |
| #include "chrome/browser/signin/easy_unlock_service_signin_chromeos.h" |
| #include "base/bind.h" |
| -#include "base/command_line.h" |
| #include "base/location.h" |
| #include "base/logging.h" |
| #include "base/stl_util.h" |
| @@ -13,7 +12,6 @@ |
| #include "base/time/time.h" |
| #include "chrome/browser/chromeos/login/easy_unlock/easy_unlock_key_manager.h" |
| #include "chrome/browser/chromeos/login/session/user_session_manager.h" |
| -#include "chromeos/chromeos_switches.h" |
| #include "chromeos/login/auth/user_context.h" |
| namespace { |
| @@ -92,11 +90,12 @@ EasyUnlockServiceSignin::UserData::~UserData() {} |
| EasyUnlockServiceSignin::EasyUnlockServiceSignin(Profile* profile) |
| : EasyUnlockService(profile), |
| allow_cryptohome_backoff_(true), |
| + service_stopped_(false), |
| weak_ptr_factory_(this) { |
| } |
| EasyUnlockServiceSignin::~EasyUnlockServiceSignin() { |
| - STLDeleteContainerPairSecondPointers(user_data_.begin(), user_data_.end()); |
| + StopService(); |
|
xiyuan
2014/09/22 17:35:33
dtor is pretty late. Suggest to do this earlier in
tbarzic
2014/09/22 18:54:02
Done. (added Shutdown override for service and rep
|
| } |
| EasyUnlockService::Type EasyUnlockServiceSignin::GetType() const { |
| @@ -163,19 +162,72 @@ std::string EasyUnlockServiceSignin::GetChallenge() const { |
| } |
| void EasyUnlockServiceSignin::InitializeInternal() { |
| + if (chromeos::LoginState::Get()->IsUserLoggedIn()) { |
| + service_stopped_ = true; |
| + return; |
| + } |
| + |
| + chromeos::LoginState::Get()->AddObserver(this); |
| + ScreenlockBridge* screenlock_bridge = ScreenlockBridge::Get(); |
| + screenlock_bridge->AddObserver(this); |
| + if (!screenlock_bridge->focused_user_id().empty()) |
| + OnFocusedUserChanged(screenlock_bridge->focused_user_id()); |
| } |
| bool EasyUnlockServiceSignin::IsAllowedInternal() { |
| return !user_id_.empty() && |
| - FindLoadedDataForCurrentUser() && |
| - CommandLine::ForCurrentProcess()->HasSwitch( |
| - chromeos::switches::kEnableEasySignin); |
| + !service_stopped_ && |
| + !chromeos::LoginState::Get()->IsUserLoggedIn(); |
| +} |
| + |
| +void EasyUnlockServiceSignin::OnScreenDidLock() { |
| +} |
| + |
| +void EasyUnlockServiceSignin::OnScreenDidUnlock() { |
| +} |
| + |
| +void EasyUnlockServiceSignin::OnFocusedUserChanged(const std::string& user_id) { |
| + if (user_id_ == user_id) |
| + return; |
| + |
| + // Setting or clearing the user_id may changed |IsAllowed| value, so in these |
| + // cases update the app state. Otherwise, it's enough to notify the app the |
| + // user data has been updated. |
| + bool should_update_app_state = user_id_.empty() != user_id.empty(); |
| + user_id_ = user_id; |
| + |
| + ResetScreenlockStateHandler(); |
| + |
| + if (should_update_app_state) { |
| + UpdateAppState(); |
| + } else { |
| + NotifyUserUpdated(); |
| + } |
| + |
| + LoadCurrentUserDataIfNeeded(); |
| +} |
| + |
| +void EasyUnlockServiceSignin::LoggedInStateChanged() { |
| + if (!chromeos::LoginState::Get()->IsUserLoggedIn()) |
| + return; |
| + UnloadApp(); |
| + StopService(); |
| +} |
| + |
| +void EasyUnlockServiceSignin::StopService() { |
| + if (service_stopped_) |
| + return; |
| + service_stopped_ = true; |
| + |
| + weak_ptr_factory_.InvalidateWeakPtrs(); |
| + ScreenlockBridge::Get()->RemoveObserver(this); |
| + chromeos::LoginState::Get()->RemoveObserver(this); |
| + STLDeleteContainerPairSecondPointers(user_data_.begin(), user_data_.end()); |
| + user_data_.clear(); |
| } |
| void EasyUnlockServiceSignin::LoadCurrentUserDataIfNeeded() { |
| - if (user_id_.empty() || |
| - !CommandLine::ForCurrentProcess()->HasSwitch( |
| - chromeos::switches::kEnableEasySignin)) |
| + if (user_id_.empty() || service_stopped_) |
| return; |
| std::map<std::string, UserData*>::iterator it = user_data_.find(user_id_); |
| @@ -209,12 +261,18 @@ void EasyUnlockServiceSignin::OnUserDataLoaded( |
| chromeos::EasyUnlockKeyManager::DeviceDataListToRemoteDeviceList( |
| user_id, devices, &data->remote_devices_value); |
| } |
| + |
| + // If the fetched data belongs to the currently focused user, notify the app |
| + // that it has to refresh it's user data. |
| + if (user_id == user_id_) |
| + NotifyUserUpdated(); |
| } |
| const EasyUnlockServiceSignin::UserData* |
| EasyUnlockServiceSignin::FindLoadedDataForCurrentUser() const { |
| if (user_id_.empty()) |
| return NULL; |
| + |
| std::map<std::string, UserData*>::const_iterator it = |
| user_data_.find(user_id_); |
| if (it == user_data_.end()) |