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

Side by Side 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 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/signin/easy_unlock_service_signin_chromeos.h" 5 #include "chrome/browser/signin/easy_unlock_service_signin_chromeos.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/command_line.h"
9 #include "base/location.h" 8 #include "base/location.h"
10 #include "base/logging.h" 9 #include "base/logging.h"
11 #include "base/stl_util.h" 10 #include "base/stl_util.h"
12 #include "base/thread_task_runner_handle.h" 11 #include "base/thread_task_runner_handle.h"
13 #include "base/time/time.h" 12 #include "base/time/time.h"
14 #include "chrome/browser/chromeos/login/easy_unlock/easy_unlock_key_manager.h" 13 #include "chrome/browser/chromeos/login/easy_unlock/easy_unlock_key_manager.h"
15 #include "chrome/browser/chromeos/login/session/user_session_manager.h" 14 #include "chrome/browser/chromeos/login/session/user_session_manager.h"
16 #include "chromeos/chromeos_switches.h"
17 #include "chromeos/login/auth/user_context.h" 15 #include "chromeos/login/auth/user_context.h"
18 16
19 namespace { 17 namespace {
20 18
21 // The maximum allowed backoff interval when waiting for cryptohome to start. 19 // The maximum allowed backoff interval when waiting for cryptohome to start.
22 size_t kMaxCryptohomeBackoffIntervalMs = 10000u; 20 size_t kMaxCryptohomeBackoffIntervalMs = 10000u;
23 21
24 // If the data load fails, the initial interval after which the load will be 22 // If the data load fails, the initial interval after which the load will be
25 // retried. Further intervals will exponentially increas by factor 2. 23 // retried. Further intervals will exponentially increas by factor 2.
26 size_t kInitialCryptohomeBackoffIntervalMs = 200u; 24 size_t kInitialCryptohomeBackoffIntervalMs = 200u;
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
85 83
86 EasyUnlockServiceSignin::UserData::UserData() 84 EasyUnlockServiceSignin::UserData::UserData()
87 : state(EasyUnlockServiceSignin::USER_DATA_STATE_INITIAL) { 85 : state(EasyUnlockServiceSignin::USER_DATA_STATE_INITIAL) {
88 } 86 }
89 87
90 EasyUnlockServiceSignin::UserData::~UserData() {} 88 EasyUnlockServiceSignin::UserData::~UserData() {}
91 89
92 EasyUnlockServiceSignin::EasyUnlockServiceSignin(Profile* profile) 90 EasyUnlockServiceSignin::EasyUnlockServiceSignin(Profile* profile)
93 : EasyUnlockService(profile), 91 : EasyUnlockService(profile),
94 allow_cryptohome_backoff_(true), 92 allow_cryptohome_backoff_(true),
93 service_stopped_(false),
95 weak_ptr_factory_(this) { 94 weak_ptr_factory_(this) {
96 } 95 }
97 96
98 EasyUnlockServiceSignin::~EasyUnlockServiceSignin() { 97 EasyUnlockServiceSignin::~EasyUnlockServiceSignin() {
99 STLDeleteContainerPairSecondPointers(user_data_.begin(), user_data_.end()); 98 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
100 } 99 }
101 100
102 EasyUnlockService::Type EasyUnlockServiceSignin::GetType() const { 101 EasyUnlockService::Type EasyUnlockServiceSignin::GetType() const {
103 return EasyUnlockService::TYPE_SIGNIN; 102 return EasyUnlockService::TYPE_SIGNIN;
104 } 103 }
105 104
106 std::string EasyUnlockServiceSignin::GetUserEmail() const { 105 std::string EasyUnlockServiceSignin::GetUserEmail() const {
107 return user_id_; 106 return user_id_;
108 } 107 }
109 108
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
156 std::string EasyUnlockServiceSignin::GetChallenge() const { 155 std::string EasyUnlockServiceSignin::GetChallenge() const {
157 const UserData* data = FindLoadedDataForCurrentUser(); 156 const UserData* data = FindLoadedDataForCurrentUser();
158 // TODO(xiyuan): Use correct remote device instead of hard coded first one. 157 // TODO(xiyuan): Use correct remote device instead of hard coded first one.
159 size_t device_index = 0; 158 size_t device_index = 0;
160 if (!data || data->devices.size() <= device_index) 159 if (!data || data->devices.size() <= device_index)
161 return std::string(); 160 return std::string();
162 return data->devices[device_index].challenge; 161 return data->devices[device_index].challenge;
163 } 162 }
164 163
165 void EasyUnlockServiceSignin::InitializeInternal() { 164 void EasyUnlockServiceSignin::InitializeInternal() {
165 if (chromeos::LoginState::Get()->IsUserLoggedIn()) {
166 service_stopped_ = true;
167 return;
168 }
169
170 chromeos::LoginState::Get()->AddObserver(this);
171 ScreenlockBridge* screenlock_bridge = ScreenlockBridge::Get();
172 screenlock_bridge->AddObserver(this);
173 if (!screenlock_bridge->focused_user_id().empty())
174 OnFocusedUserChanged(screenlock_bridge->focused_user_id());
166 } 175 }
167 176
168 bool EasyUnlockServiceSignin::IsAllowedInternal() { 177 bool EasyUnlockServiceSignin::IsAllowedInternal() {
169 return !user_id_.empty() && 178 return !user_id_.empty() &&
170 FindLoadedDataForCurrentUser() && 179 !service_stopped_ &&
171 CommandLine::ForCurrentProcess()->HasSwitch( 180 !chromeos::LoginState::Get()->IsUserLoggedIn();
172 chromeos::switches::kEnableEasySignin); 181 }
182
183 void EasyUnlockServiceSignin::OnScreenDidLock() {
184 }
185
186 void EasyUnlockServiceSignin::OnScreenDidUnlock() {
187 }
188
189 void EasyUnlockServiceSignin::OnFocusedUserChanged(const std::string& user_id) {
190 if (user_id_ == user_id)
191 return;
192
193 // Setting or clearing the user_id may changed |IsAllowed| value, so in these
194 // cases update the app state. Otherwise, it's enough to notify the app the
195 // user data has been updated.
196 bool should_update_app_state = user_id_.empty() != user_id.empty();
197 user_id_ = user_id;
198
199 ResetScreenlockStateHandler();
200
201 if (should_update_app_state) {
202 UpdateAppState();
203 } else {
204 NotifyUserUpdated();
205 }
206
207 LoadCurrentUserDataIfNeeded();
208 }
209
210 void EasyUnlockServiceSignin::LoggedInStateChanged() {
211 if (!chromeos::LoginState::Get()->IsUserLoggedIn())
212 return;
213 UnloadApp();
214 StopService();
215 }
216
217 void EasyUnlockServiceSignin::StopService() {
218 if (service_stopped_)
219 return;
220 service_stopped_ = true;
221
222 weak_ptr_factory_.InvalidateWeakPtrs();
223 ScreenlockBridge::Get()->RemoveObserver(this);
224 chromeos::LoginState::Get()->RemoveObserver(this);
225 STLDeleteContainerPairSecondPointers(user_data_.begin(), user_data_.end());
226 user_data_.clear();
173 } 227 }
174 228
175 void EasyUnlockServiceSignin::LoadCurrentUserDataIfNeeded() { 229 void EasyUnlockServiceSignin::LoadCurrentUserDataIfNeeded() {
176 if (user_id_.empty() || 230 if (user_id_.empty() || service_stopped_)
177 !CommandLine::ForCurrentProcess()->HasSwitch(
178 chromeos::switches::kEnableEasySignin))
179 return; 231 return;
180 232
181 std::map<std::string, UserData*>::iterator it = user_data_.find(user_id_); 233 std::map<std::string, UserData*>::iterator it = user_data_.find(user_id_);
182 if (it == user_data_.end()) 234 if (it == user_data_.end())
183 user_data_.insert(std::make_pair(user_id_, new UserData())); 235 user_data_.insert(std::make_pair(user_id_, new UserData()));
184 236
185 UserData* data = user_data_[user_id_]; 237 UserData* data = user_data_[user_id_];
186 238
187 if (data->state != USER_DATA_STATE_INITIAL) 239 if (data->state != USER_DATA_STATE_INITIAL)
188 return; 240 return;
(...skipping 13 matching lines...) Expand all
202 const chromeos::EasyUnlockDeviceKeyDataList& devices) { 254 const chromeos::EasyUnlockDeviceKeyDataList& devices) {
203 allow_cryptohome_backoff_ = false; 255 allow_cryptohome_backoff_ = false;
204 256
205 UserData* data = user_data_[user_id_]; 257 UserData* data = user_data_[user_id_];
206 data->state = USER_DATA_STATE_LOADED; 258 data->state = USER_DATA_STATE_LOADED;
207 if (success) { 259 if (success) {
208 data->devices = devices; 260 data->devices = devices;
209 chromeos::EasyUnlockKeyManager::DeviceDataListToRemoteDeviceList( 261 chromeos::EasyUnlockKeyManager::DeviceDataListToRemoteDeviceList(
210 user_id, devices, &data->remote_devices_value); 262 user_id, devices, &data->remote_devices_value);
211 } 263 }
264
265 // If the fetched data belongs to the currently focused user, notify the app
266 // that it has to refresh it's user data.
267 if (user_id == user_id_)
268 NotifyUserUpdated();
212 } 269 }
213 270
214 const EasyUnlockServiceSignin::UserData* 271 const EasyUnlockServiceSignin::UserData*
215 EasyUnlockServiceSignin::FindLoadedDataForCurrentUser() const { 272 EasyUnlockServiceSignin::FindLoadedDataForCurrentUser() const {
216 if (user_id_.empty()) 273 if (user_id_.empty())
217 return NULL; 274 return NULL;
275
218 std::map<std::string, UserData*>::const_iterator it = 276 std::map<std::string, UserData*>::const_iterator it =
219 user_data_.find(user_id_); 277 user_data_.find(user_id_);
220 if (it == user_data_.end()) 278 if (it == user_data_.end())
221 return NULL; 279 return NULL;
222 if (it->second->state != USER_DATA_STATE_LOADED) 280 if (it->second->state != USER_DATA_STATE_LOADED)
223 return NULL; 281 return NULL;
224 return it->second; 282 return it->second;
225 } 283 }
OLDNEW
« no previous file with comments | « chrome/browser/signin/easy_unlock_service_signin_chromeos.h ('k') | chrome/browser/signin/screenlock_bridge.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698