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

Side by Side Diff: chrome/browser/chromeos/login/login_performer.cc

Issue 7867044: PART1: Initiated the SignedSettings refactoring. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Final rebase to ToT before hitting the CQ. Created 9 years, 1 month 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/chromeos/login/login_performer.h" 5 #include "chrome/browser/chromeos/login/login_performer.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/command_line.h" 10 #include "base/command_line.h"
11 #include "base/logging.h" 11 #include "base/logging.h"
12 #include "base/message_loop.h" 12 #include "base/message_loop.h"
13 #include "base/metrics/histogram.h" 13 #include "base/metrics/histogram.h"
14 #include "base/utf_string_conversions.h" 14 #include "base/utf_string_conversions.h"
15 #include "chrome/browser/browser_process.h" 15 #include "chrome/browser/browser_process.h"
16 #include "chrome/browser/chromeos/boot_times_loader.h" 16 #include "chrome/browser/chromeos/boot_times_loader.h"
17 #include "chrome/browser/chromeos/cros/cros_library.h" 17 #include "chrome/browser/chromeos/cros/cros_library.h"
18 #include "chrome/browser/chromeos/cros/screen_lock_library.h" 18 #include "chrome/browser/chromeos/cros/screen_lock_library.h"
19 #include "chrome/browser/chromeos/cros_settings.h"
19 #include "chrome/browser/chromeos/cros_settings_names.h" 20 #include "chrome/browser/chromeos/cros_settings_names.h"
20 #include "chrome/browser/chromeos/login/login_utils.h" 21 #include "chrome/browser/chromeos/login/login_utils.h"
21 #include "chrome/browser/chromeos/login/screen_locker.h" 22 #include "chrome/browser/chromeos/login/screen_locker.h"
22 #include "chrome/browser/chromeos/user_cros_settings_provider.h"
23 #include "chrome/browser/prefs/pref_service.h" 23 #include "chrome/browser/prefs/pref_service.h"
24 #include "chrome/browser/profiles/profile.h" 24 #include "chrome/browser/profiles/profile.h"
25 #include "chrome/browser/profiles/profile_manager.h" 25 #include "chrome/browser/profiles/profile_manager.h"
26 #include "chrome/common/chrome_notification_types.h" 26 #include "chrome/common/chrome_notification_types.h"
27 #include "chrome/common/chrome_switches.h" 27 #include "chrome/common/chrome_switches.h"
28 #include "chrome/common/pref_names.h" 28 #include "chrome/common/pref_names.h"
29 #include "content/browser/user_metrics.h" 29 #include "content/browser/user_metrics.h"
30 #include "content/public/browser/browser_thread.h" 30 #include "content/public/browser/browser_thread.h"
31 #include "content/public/browser/notification_service.h" 31 #include "content/public/browser/notification_service.h"
32 #include "content/public/browser/notification_types.h" 32 #include "content/public/browser/notification_types.h"
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
215 last_login_failure_ = 215 last_login_failure_ =
216 LoginFailure::FromNetworkAuthFailure(GoogleServiceAuthError( 216 LoginFailure::FromNetworkAuthFailure(GoogleServiceAuthError(
217 GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS)); 217 GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS));
218 password_changed_ = true; 218 password_changed_ = true;
219 DVLOG(1) << "Password change detected - locking screen."; 219 DVLOG(1) << "Password change detected - locking screen.";
220 RequestScreenLock(); 220 RequestScreenLock();
221 } 221 }
222 } 222 }
223 223
224 //////////////////////////////////////////////////////////////////////////////// 224 ////////////////////////////////////////////////////////////////////////////////
225 // LoginPerformer, SignedSettingsHelper::Callback implementation:
226
227 void LoginPerformer::OnCheckWhitelistCompleted(SignedSettings::ReturnCode code,
228 const std::string& email) {
229 if (code == SignedSettings::SUCCESS) {
230 // Whitelist check passed, continue with authentication.
231 if (auth_mode_ == AUTH_MODE_EXTENSION) {
232 StartLoginCompletion();
233 } else {
234 StartAuthentication();
235 }
236 } else {
237 if (delegate_)
238 delegate_->WhiteListCheckFailed(email);
239 else
240 NOTREACHED();
241 }
242 }
243
244 ////////////////////////////////////////////////////////////////////////////////
245 // LoginPerformer, content::NotificationObserver implementation: 225 // LoginPerformer, content::NotificationObserver implementation:
246 // 226 //
247 227
248 void LoginPerformer::Observe(int type, 228 void LoginPerformer::Observe(int type,
249 const content::NotificationSource& source, 229 const content::NotificationSource& source,
250 const content::NotificationDetails& details) { 230 const content::NotificationDetails& details) {
251 if (type != chrome::NOTIFICATION_SCREEN_LOCK_STATE_CHANGED) 231 if (type != chrome::NOTIFICATION_SCREEN_LOCK_STATE_CHANGED)
252 return; 232 return;
253 233
254 bool is_screen_locked = *content::Details<bool>(details).ptr(); 234 bool is_screen_locked = *content::Details<bool>(details).ptr();
255 if (is_screen_locked) { 235 if (is_screen_locked) {
256 if (screen_lock_requested_) { 236 if (screen_lock_requested_) {
257 screen_lock_requested_ = false; 237 screen_lock_requested_ = false;
258 ResolveScreenLocked(); 238 ResolveScreenLocked();
259 } 239 }
260 } else { 240 } else {
261 ResolveScreenUnlocked(); 241 ResolveScreenUnlocked();
262 } 242 }
263 } 243 }
264 244
265 //////////////////////////////////////////////////////////////////////////////// 245 ////////////////////////////////////////////////////////////////////////////////
266 // LoginPerformer, public: 246 // LoginPerformer, public:
267 void LoginPerformer::CompleteLogin(const std::string& username, 247 void LoginPerformer::CompleteLogin(const std::string& username,
268 const std::string& password) { 248 const std::string& password) {
269 auth_mode_ = AUTH_MODE_EXTENSION; 249 auth_mode_ = AUTH_MODE_EXTENSION;
270 username_ = username; 250 username_ = username;
271 password_ = password; 251 password_ = password;
252
253 CrosSettings* cros_settings = CrosSettings::Get();
254
272 // Whitelist check is always performed during initial login and 255 // Whitelist check is always performed during initial login and
273 // should not be performed when ScreenLock is active (pending online auth). 256 // should not be performed when ScreenLock is active (pending online auth).
274 if (!ScreenLocker::default_screen_locker()) { 257 if (!ScreenLocker::default_screen_locker()) {
275 // Must not proceed without signature verification. 258 // Must not proceed without signature verification or valid user list.
276 UserCrosSettingsProvider user_settings; 259 bool trusted_settings_available =
277 bool trusted_setting_available = user_settings.RequestTrustedAllowNewUser( 260 cros_settings->GetTrusted(
278 base::Bind(&LoginPerformer::CompleteLogin, weak_factory_.GetWeakPtr(), 261 kAccountsPrefAllowNewUser,
279 username, password)); 262 base::Bind(&LoginPerformer::CompleteLogin,
280 if (!trusted_setting_available) { 263 weak_factory_.GetWeakPtr(),
264 username, password));
265 if (!trusted_settings_available) {
281 // Value of AllowNewUser setting is still not verified. 266 // Value of AllowNewUser setting is still not verified.
282 // Another attempt will be invoked after verification completion. 267 // Another attempt will be invoked after verification completion.
283 return; 268 return;
284 } 269 }
285 } 270 }
286 271
287 if (ScreenLocker::default_screen_locker() || 272 bool allow_new_user = false;
288 UserCrosSettingsProvider::cached_allow_new_user()) { 273 cros_settings->GetBoolean(kAccountsPrefAllowNewUser, &allow_new_user);
274 if (ScreenLocker::default_screen_locker() || allow_new_user) {
289 // Starts authentication if guest login is allowed or online auth pending. 275 // Starts authentication if guest login is allowed or online auth pending.
290 StartLoginCompletion(); 276 StartLoginCompletion();
291 } else { 277 } else {
292 // Otherwise, do whitelist check first. 278 // Otherwise, do whitelist check first.
293 PrefService* local_state = g_browser_process->local_state(); 279 const base::ListValue *user_list;
294 CHECK(local_state); 280 base::StringValue username_value(username);
295 if (local_state->IsManagedPreference(kAccountsPrefUsers)) { 281 if (cros_settings->GetList(kAccountsPrefUsers, &user_list) &&
296 if (UserCrosSettingsProvider::IsEmailInCachedWhitelist(username)) { 282 user_list->Find(username_value) != user_list->end()) {
297 StartLoginCompletion(); 283 StartLoginCompletion();
298 } else {
299 if (delegate_)
300 delegate_->WhiteListCheckFailed(username);
301 else
302 NOTREACHED();
303 }
304 } else { 284 } else {
305 // In case of signed settings: with current implementation we do not 285 if (delegate_)
306 // trust whitelist returned by PrefService. So make separate check. 286 delegate_->WhiteListCheckFailed(username);
307 SignedSettingsHelper::Get()->StartCheckWhitelistOp( 287 else
308 username, this); 288 NOTREACHED();
309 } 289 }
310 } 290 }
311 } 291 }
312 292
313 void LoginPerformer::Login(const std::string& username, 293 void LoginPerformer::Login(const std::string& username,
314 const std::string& password) { 294 const std::string& password) {
315 auth_mode_ = AUTH_MODE_INTERNAL; 295 auth_mode_ = AUTH_MODE_INTERNAL;
316 username_ = username; 296 username_ = username;
317 password_ = password; 297 password_ = password;
318 298
299 CrosSettings* cros_settings = CrosSettings::Get();
300
319 // Whitelist check is always performed during initial login and 301 // Whitelist check is always performed during initial login and
320 // should not be performed when ScreenLock is active (pending online auth). 302 // should not be performed when ScreenLock is active (pending online auth).
321 if (!ScreenLocker::default_screen_locker()) { 303 if (!ScreenLocker::default_screen_locker()) {
322 // Must not proceed without signature verification. 304 // Must not proceed without signature verification.
323 UserCrosSettingsProvider user_settings; 305 bool trusted_settings_available =
324 bool trusted_setting_available = user_settings.RequestTrustedAllowNewUser( 306 cros_settings->GetTrusted(
325 base::Bind(&LoginPerformer::Login, weak_factory_.GetWeakPtr(), username, 307 kAccountsPrefAllowNewUser,
326 password)); 308 base::Bind(&LoginPerformer::Login,
327 if (!trusted_setting_available) { 309 weak_factory_.GetWeakPtr(),
310 username, password));
311 if (!trusted_settings_available) {
328 // Value of AllowNewUser setting is still not verified. 312 // Value of AllowNewUser setting is still not verified.
329 // Another attempt will be invoked after verification completion. 313 // Another attempt will be invoked after verification completion.
330 return; 314 return;
331 } 315 }
332 } 316 }
333 317
334 if (ScreenLocker::default_screen_locker() || 318 bool allow_new_user = false;
335 UserCrosSettingsProvider::cached_allow_new_user()) { 319 cros_settings->GetBoolean(kAccountsPrefAllowNewUser, &allow_new_user);
320 if (ScreenLocker::default_screen_locker() || allow_new_user) {
336 // Starts authentication if guest login is allowed or online auth pending. 321 // Starts authentication if guest login is allowed or online auth pending.
337 StartAuthentication(); 322 StartAuthentication();
338 } else { 323 } else {
339 // Otherwise, do whitelist check first. 324 const base::ListValue *user_list;
340 PrefService* local_state = g_browser_process->local_state(); 325 base::StringValue username_value(username);
341 CHECK(local_state); 326 if (cros_settings->GetList(kAccountsPrefUsers, &user_list) &&
342 if (local_state->IsManagedPreference(kAccountsPrefUsers)) { 327 user_list->Find(username_value) != user_list->end()) {
343 if (UserCrosSettingsProvider::IsEmailInCachedWhitelist(username)) { 328 StartAuthentication();
344 StartAuthentication();
345 } else {
346 if (delegate_)
347 delegate_->WhiteListCheckFailed(username);
348 else
349 NOTREACHED();
350 }
351 } else { 329 } else {
352 // In case of signed settings: with current implementation we do not 330 if (delegate_)
353 // trust whitelist returned by PrefService. So make separate check. 331 delegate_->WhiteListCheckFailed(username);
354 SignedSettingsHelper::Get()->StartCheckWhitelistOp( 332 else
355 username, this); 333 NOTREACHED();
356 } 334 }
357 } 335 }
358 } 336 }
359 337
360 void LoginPerformer::LoginOffTheRecord() { 338 void LoginPerformer::LoginOffTheRecord() {
361 authenticator_ = LoginUtils::Get()->CreateAuthenticator(this); 339 authenticator_ = LoginUtils::Get()->CreateAuthenticator(this);
362 BrowserThread::PostTask( 340 BrowserThread::PostTask(
363 BrowserThread::UI, FROM_HERE, 341 BrowserThread::UI, FROM_HERE,
364 base::Bind(&Authenticator::LoginOffTheRecord, authenticator_.get())); 342 base::Bind(&Authenticator::LoginOffTheRecord, authenticator_.get()));
365 } 343 }
366 344
367 void LoginPerformer::RecoverEncryptedData(const std::string& old_password) { 345 void LoginPerformer::RecoverEncryptedData(const std::string& old_password) {
368 BrowserThread::PostTask( 346 BrowserThread::PostTask(
369 BrowserThread::UI, FROM_HERE, 347 BrowserThread::UI, FROM_HERE,
370 base::Bind(&Authenticator::RecoverEncryptedData, authenticator_.get(), 348 base::Bind(&Authenticator::RecoverEncryptedData, authenticator_.get(),
371 old_password, cached_credentials_)); 349 old_password,
350 cached_credentials_));
372 cached_credentials_ = GaiaAuthConsumer::ClientLoginResult(); 351 cached_credentials_ = GaiaAuthConsumer::ClientLoginResult();
373 } 352 }
374 353
375 void LoginPerformer::ResyncEncryptedData() { 354 void LoginPerformer::ResyncEncryptedData() {
376 BrowserThread::PostTask( 355 BrowserThread::PostTask(
377 BrowserThread::UI, FROM_HERE, 356 BrowserThread::UI, FROM_HERE,
378 base::Bind(&Authenticator::ResyncEncryptedData, authenticator_.get(), 357 base::Bind(&Authenticator::ResyncEncryptedData, authenticator_.get(),
379 cached_credentials_)); 358 cached_credentials_));
380 cached_credentials_ = GaiaAuthConsumer::ClientLoginResult(); 359 cached_credentials_ = GaiaAuthConsumer::ClientLoginResult();
381 } 360 }
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
532 } 511 }
533 512
534 void LoginPerformer::StartLoginCompletion() { 513 void LoginPerformer::StartLoginCompletion() {
535 DVLOG(1) << "Login completion started"; 514 DVLOG(1) << "Login completion started";
536 BootTimesLoader::Get()->AddLoginTimeMarker("AuthStarted", false); 515 BootTimesLoader::Get()->AddLoginTimeMarker("AuthStarted", false);
537 Profile* profile = g_browser_process->profile_manager()->GetDefaultProfile(); 516 Profile* profile = g_browser_process->profile_manager()->GetDefaultProfile();
538 517
539 authenticator_ = LoginUtils::Get()->CreateAuthenticator(this); 518 authenticator_ = LoginUtils::Get()->CreateAuthenticator(this);
540 BrowserThread::PostTask( 519 BrowserThread::PostTask(
541 BrowserThread::UI, FROM_HERE, 520 BrowserThread::UI, FROM_HERE,
542 base::Bind(&Authenticator::CompleteLogin, authenticator_.get(), profile, 521 base::Bind(&Authenticator::CompleteLogin, authenticator_.get(),
543 username_, password_)); 522 profile,
523 username_,
524 password_));
544 525
545 password_.clear(); 526 password_.clear();
546 } 527 }
547 528
548 void LoginPerformer::StartAuthentication() { 529 void LoginPerformer::StartAuthentication() {
549 DVLOG(1) << "Auth started"; 530 DVLOG(1) << "Auth started";
550 BootTimesLoader::Get()->AddLoginTimeMarker("AuthStarted", false); 531 BootTimesLoader::Get()->AddLoginTimeMarker("AuthStarted", false);
551 Profile* profile = g_browser_process->profile_manager()->GetDefaultProfile(); 532 Profile* profile = g_browser_process->profile_manager()->GetDefaultProfile();
552 if (delegate_) { 533 if (delegate_) {
553 authenticator_ = LoginUtils::Get()->CreateAuthenticator(this); 534 authenticator_ = LoginUtils::Get()->CreateAuthenticator(this);
554 BrowserThread::PostTask( 535 BrowserThread::PostTask(
555 BrowserThread::UI, FROM_HERE, 536 BrowserThread::UI, FROM_HERE,
556 base::Bind(&Authenticator::AuthenticateToLogin, authenticator_.get(), 537 base::Bind(&Authenticator::AuthenticateToLogin, authenticator_.get(),
557 profile, username_, password_, captcha_token_, captcha_)); 538 profile,
539 username_,
540 password_,
541 captcha_token_,
542 captcha_));
558 } else { 543 } else {
559 DCHECK(authenticator_.get()) 544 DCHECK(authenticator_.get())
560 << "Authenticator instance doesn't exist for login attempt retry."; 545 << "Authenticator instance doesn't exist for login attempt retry.";
561 // At this point offline auth has been successful, 546 // At this point offline auth has been successful,
562 // retry online auth, using existing Authenticator instance. 547 // retry online auth, using existing Authenticator instance.
563 BrowserThread::PostTask( 548 BrowserThread::PostTask(
564 BrowserThread::UI, FROM_HERE, 549 BrowserThread::UI, FROM_HERE,
565 base::Bind(&Authenticator::RetryAuth, authenticator_.get(), profile, 550 base::Bind(&Authenticator::RetryAuth, authenticator_.get(),
566 username_, password_, captcha_token_, captcha_)); 551 profile,
552 username_,
553 password_,
554 captcha_token_,
555 captcha_));
567 } 556 }
568 password_.clear(); 557 password_.clear();
569 } 558 }
570 559
571 } // namespace chromeos 560 } // namespace chromeos
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/login/login_performer.h ('k') | chrome/browser/chromeos/login/user_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698