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

Unified Diff: chrome/browser/signin/easy_unlock_service_signin_chromeos.cc

Issue 576343002: [Easy signin] Add method to get user info to easyUnlockPrivate (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: . Created 6 years, 3 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 side-by-side diff with in-line comments
Download patch
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..c82483348c30daae57b404b4fa280fd245b5ccbe 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,11 @@ EasyUnlockServiceSignin::UserData::~UserData() {}
EasyUnlockServiceSignin::EasyUnlockServiceSignin(Profile* profile)
: EasyUnlockService(profile),
allow_cryptohome_backoff_(true),
+ service_active_(false),
weak_ptr_factory_(this) {
}
EasyUnlockServiceSignin::~EasyUnlockServiceSignin() {
- STLDeleteContainerPairSecondPointers(user_data_.begin(), user_data_.end());
}
EasyUnlockService::Type EasyUnlockServiceSignin::GetType() const {
@@ -163,19 +161,72 @@ std::string EasyUnlockServiceSignin::GetChallenge() const {
}
void EasyUnlockServiceSignin::InitializeInternal() {
+ if (chromeos::LoginState::Get()->IsUserLoggedIn())
+ return;
+
+ service_active_ = true;
+
+ 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());
+}
+
+void EasyUnlockServiceSignin::ShutdownInternal() {
+ if (!service_active_)
+ return;
+ service_active_ = false;
+
+ weak_ptr_factory_.InvalidateWeakPtrs();
+ ScreenlockBridge::Get()->RemoveObserver(this);
+ chromeos::LoginState::Get()->RemoveObserver(this);
+ STLDeleteContainerPairSecondPointers(user_data_.begin(), user_data_.end());
+ user_data_.clear();
}
bool EasyUnlockServiceSignin::IsAllowedInternal() {
- return !user_id_.empty() &&
- FindLoadedDataForCurrentUser() &&
- CommandLine::ForCurrentProcess()->HasSwitch(
- chromeos::switches::kEnableEasySignin);
+ return service_active_ &&
+ !user_id_.empty() &&
+ !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();
+ Shutdown();
}
void EasyUnlockServiceSignin::LoadCurrentUserDataIfNeeded() {
- if (user_id_.empty() ||
- !CommandLine::ForCurrentProcess()->HasSwitch(
- chromeos::switches::kEnableEasySignin))
+ if (user_id_.empty() || !service_active_)
return;
std::map<std::string, UserData*>::iterator it = user_data_.find(user_id_);
@@ -209,12 +260,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())

Powered by Google App Engine
This is Rietveld 408576698