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

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: Addressed comments from Chris and rebased to ToT to get it running on the try servers again. Created 9 years, 2 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 | 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/browser_thread.h" 29 #include "content/browser/browser_thread.h"
30 #include "content/browser/user_metrics.h" 30 #include "content/browser/user_metrics.h"
31 #include "content/common/content_notification_types.h" 31 #include "content/common/content_notification_types.h"
32 #include "content/common/notification_service.h" 32 #include "content/common/notification_service.h"
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
220 last_login_failure_ = 220 last_login_failure_ =
221 LoginFailure::FromNetworkAuthFailure(GoogleServiceAuthError( 221 LoginFailure::FromNetworkAuthFailure(GoogleServiceAuthError(
222 GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS)); 222 GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS));
223 password_changed_ = true; 223 password_changed_ = true;
224 DVLOG(1) << "Password change detected - locking screen."; 224 DVLOG(1) << "Password change detected - locking screen.";
225 RequestScreenLock(); 225 RequestScreenLock();
226 } 226 }
227 } 227 }
228 228
229 //////////////////////////////////////////////////////////////////////////////// 229 ////////////////////////////////////////////////////////////////////////////////
230 // LoginPerformer, SignedSettingsHelper::Callback implementation:
231
232 void LoginPerformer::OnCheckWhitelistCompleted(SignedSettings::ReturnCode code,
233 const std::string& email) {
234 if (code == SignedSettings::SUCCESS) {
235 // Whitelist check passed, continue with authentication.
236 if (auth_mode_ == AUTH_MODE_EXTENSION) {
237 StartLoginCompletion();
238 } else {
239 StartAuthentication();
240 }
241 } else {
242 if (delegate_)
243 delegate_->WhiteListCheckFailed(email);
244 else
245 NOTREACHED();
246 }
247 }
248
249 ////////////////////////////////////////////////////////////////////////////////
250 // LoginPerformer, NotificationObserver implementation: 230 // LoginPerformer, NotificationObserver implementation:
251 // 231 //
252 232
253 void LoginPerformer::Observe(int type, 233 void LoginPerformer::Observe(int type,
254 const NotificationSource& source, 234 const NotificationSource& source,
255 const NotificationDetails& details) { 235 const NotificationDetails& details) {
256 if (type != chrome::NOTIFICATION_SCREEN_LOCK_STATE_CHANGED) 236 if (type != chrome::NOTIFICATION_SCREEN_LOCK_STATE_CHANGED)
257 return; 237 return;
258 238
259 bool is_screen_locked = *Details<bool>(details).ptr(); 239 bool is_screen_locked = *Details<bool>(details).ptr();
260 if (is_screen_locked) { 240 if (is_screen_locked) {
261 if (screen_lock_requested_) { 241 if (screen_lock_requested_) {
262 screen_lock_requested_ = false; 242 screen_lock_requested_ = false;
263 ResolveScreenLocked(); 243 ResolveScreenLocked();
264 } 244 }
265 } else { 245 } else {
266 ResolveScreenUnlocked(); 246 ResolveScreenUnlocked();
267 } 247 }
268 } 248 }
269 249
270 //////////////////////////////////////////////////////////////////////////////// 250 ////////////////////////////////////////////////////////////////////////////////
271 // LoginPerformer, public: 251 // LoginPerformer, public:
272 void LoginPerformer::CompleteLogin(const std::string& username, 252 void LoginPerformer::CompleteLogin(const std::string& username,
273 const std::string& password) { 253 const std::string& password) {
274 auth_mode_ = AUTH_MODE_EXTENSION; 254 auth_mode_ = AUTH_MODE_EXTENSION;
275 username_ = username; 255 username_ = username;
276 password_ = password; 256 password_ = password;
257
258 CrosSettings* cros_settings = CrosSettings::Get();
259
277 // Whitelist check is always performed during initial login and 260 // Whitelist check is always performed during initial login and
278 // should not be performed when ScreenLock is active (pending online auth). 261 // should not be performed when ScreenLock is active (pending online auth).
279 if (!ScreenLocker::default_screen_locker()) { 262 if (!ScreenLocker::default_screen_locker()) {
280 // Must not proceed without signature verification. 263 // Must not proceed without signature verification or valid user list.
281 UserCrosSettingsProvider user_settings; 264 bool trusted_settings_available =
282 bool trusted_setting_available = user_settings.RequestTrustedAllowNewUser( 265 cros_settings->GetTrusted(
283 base::Bind(&LoginPerformer::CompleteLogin, weak_factory_.GetWeakPtr(), 266 kAccountsPrefAllowNewUser,
284 username, password)); 267 base::Bind(&LoginPerformer::CompleteLogin,
285 if (!trusted_setting_available) { 268 weak_factory_.GetWeakPtr(),
269 username, password));
270 if (!trusted_settings_available) {
286 // Value of AllowNewUser setting is still not verified. 271 // Value of AllowNewUser setting is still not verified.
287 // Another attempt will be invoked after verification completion. 272 // Another attempt will be invoked after verification completion.
288 return; 273 return;
289 } 274 }
290 } 275 }
291 276
292 if (ScreenLocker::default_screen_locker() || 277 bool allow_new_user = false;
293 UserCrosSettingsProvider::cached_allow_new_user()) { 278 cros_settings->GetBoolean(kAccountsPrefAllowNewUser, &allow_new_user);
279 if (ScreenLocker::default_screen_locker() || allow_new_user) {
294 // Starts authentication if guest login is allowed or online auth pending. 280 // Starts authentication if guest login is allowed or online auth pending.
295 StartLoginCompletion(); 281 StartLoginCompletion();
296 } else { 282 } else {
297 // Otherwise, do whitelist check first. 283 // Otherwise, do whitelist check first.
298 PrefService* local_state = g_browser_process->local_state(); 284 const base::ListValue *user_list;
299 CHECK(local_state); 285 base::StringValue username_value(username);
300 if (local_state->IsManagedPreference(kAccountsPrefUsers)) { 286 if (cros_settings->GetList(kAccountsPrefUsers, &user_list) &&
301 if (UserCrosSettingsProvider::IsEmailInCachedWhitelist(username)) { 287 user_list->Find(username_value) != user_list->end()) {
302 StartLoginCompletion(); 288 StartLoginCompletion();
303 } else {
304 if (delegate_)
305 delegate_->WhiteListCheckFailed(username);
306 else
307 NOTREACHED();
308 }
309 } else { 289 } else {
310 // In case of signed settings: with current implementation we do not 290 if (delegate_)
311 // trust whitelist returned by PrefService. So make separate check. 291 delegate_->WhiteListCheckFailed(username);
312 SignedSettingsHelper::Get()->StartCheckWhitelistOp( 292 else
313 username, this); 293 NOTREACHED();
314 } 294 }
315 } 295 }
316 } 296 }
317 297
318 void LoginPerformer::Login(const std::string& username, 298 void LoginPerformer::Login(const std::string& username,
319 const std::string& password) { 299 const std::string& password) {
320 auth_mode_ = AUTH_MODE_INTERNAL; 300 auth_mode_ = AUTH_MODE_INTERNAL;
321 username_ = username; 301 username_ = username;
322 password_ = password; 302 password_ = password;
323 303
304 CrosSettings* cros_settings = CrosSettings::Get();
305
324 // Whitelist check is always performed during initial login and 306 // Whitelist check is always performed during initial login and
325 // should not be performed when ScreenLock is active (pending online auth). 307 // should not be performed when ScreenLock is active (pending online auth).
326 if (!ScreenLocker::default_screen_locker()) { 308 if (!ScreenLocker::default_screen_locker()) {
327 // Must not proceed without signature verification. 309 // Must not proceed without signature verification.
328 UserCrosSettingsProvider user_settings; 310 bool trusted_settings_available =
329 bool trusted_setting_available = user_settings.RequestTrustedAllowNewUser( 311 cros_settings->GetTrusted(
330 base::Bind(&LoginPerformer::Login, weak_factory_.GetWeakPtr(), username, 312 kAccountsPrefAllowNewUser,
331 password)); 313 base::Bind(&LoginPerformer::Login,
332 if (!trusted_setting_available) { 314 weak_factory_.GetWeakPtr(),
315 username, password));
316 if (!trusted_settings_available) {
333 // Value of AllowNewUser setting is still not verified. 317 // Value of AllowNewUser setting is still not verified.
334 // Another attempt will be invoked after verification completion. 318 // Another attempt will be invoked after verification completion.
335 return; 319 return;
336 } 320 }
337 } 321 }
338 322
339 if (ScreenLocker::default_screen_locker() || 323 bool allow_new_user = false;
340 UserCrosSettingsProvider::cached_allow_new_user()) { 324 cros_settings->GetBoolean(kAccountsPrefAllowNewUser, &allow_new_user);
325 if (ScreenLocker::default_screen_locker() || allow_new_user) {
341 // Starts authentication if guest login is allowed or online auth pending. 326 // Starts authentication if guest login is allowed or online auth pending.
342 StartAuthentication(); 327 StartAuthentication();
343 } else { 328 } else {
344 // Otherwise, do whitelist check first. 329 const base::ListValue *user_list;
345 PrefService* local_state = g_browser_process->local_state(); 330 base::StringValue username_value(username);
346 CHECK(local_state); 331 if (cros_settings->GetList(kAccountsPrefUsers, &user_list) &&
347 if (local_state->IsManagedPreference(kAccountsPrefUsers)) { 332 user_list->Find(username_value) != user_list->end()) {
348 if (UserCrosSettingsProvider::IsEmailInCachedWhitelist(username)) { 333 StartAuthentication();
349 StartAuthentication();
350 } else {
351 if (delegate_)
352 delegate_->WhiteListCheckFailed(username);
353 else
354 NOTREACHED();
355 }
356 } else { 334 } else {
357 // In case of signed settings: with current implementation we do not 335 if (delegate_)
358 // trust whitelist returned by PrefService. So make separate check. 336 delegate_->WhiteListCheckFailed(username);
359 SignedSettingsHelper::Get()->StartCheckWhitelistOp( 337 else
360 username, this); 338 NOTREACHED();
361 } 339 }
362 } 340 }
363 } 341 }
364 342
365 void LoginPerformer::LoginOffTheRecord() { 343 void LoginPerformer::LoginOffTheRecord() {
366 authenticator_ = LoginUtils::Get()->CreateAuthenticator(this); 344 authenticator_ = LoginUtils::Get()->CreateAuthenticator(this);
367 BrowserThread::PostTask( 345 BrowserThread::PostTask(
368 BrowserThread::UI, FROM_HERE, 346 BrowserThread::UI, FROM_HERE,
369 base::Bind(&Authenticator::LoginOffTheRecord, authenticator_.get())); 347 base::Bind(&Authenticator::LoginOffTheRecord, authenticator_.get()));
370 } 348 }
371 349
372 void LoginPerformer::RecoverEncryptedData(const std::string& old_password) { 350 void LoginPerformer::RecoverEncryptedData(const std::string& old_password) {
373 BrowserThread::PostTask( 351 BrowserThread::PostTask(
374 BrowserThread::UI, FROM_HERE, 352 BrowserThread::UI, FROM_HERE,
375 base::Bind(&Authenticator::RecoverEncryptedData, authenticator_.get(), 353 base::Bind(&Authenticator::RecoverEncryptedData, authenticator_.get(),
376 old_password, cached_credentials_)); 354 old_password,
355 cached_credentials_));
377 cached_credentials_ = GaiaAuthConsumer::ClientLoginResult(); 356 cached_credentials_ = GaiaAuthConsumer::ClientLoginResult();
378 } 357 }
379 358
380 void LoginPerformer::ResyncEncryptedData() { 359 void LoginPerformer::ResyncEncryptedData() {
381 BrowserThread::PostTask( 360 BrowserThread::PostTask(
382 BrowserThread::UI, FROM_HERE, 361 BrowserThread::UI, FROM_HERE,
383 base::Bind(&Authenticator::ResyncEncryptedData, authenticator_.get(), 362 base::Bind(&Authenticator::ResyncEncryptedData, authenticator_.get(),
384 cached_credentials_)); 363 cached_credentials_));
385 cached_credentials_ = GaiaAuthConsumer::ClientLoginResult(); 364 cached_credentials_ = GaiaAuthConsumer::ClientLoginResult();
386 } 365 }
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
539 } 518 }
540 519
541 void LoginPerformer::StartLoginCompletion() { 520 void LoginPerformer::StartLoginCompletion() {
542 DVLOG(1) << "Login completion started"; 521 DVLOG(1) << "Login completion started";
543 BootTimesLoader::Get()->AddLoginTimeMarker("AuthStarted", false); 522 BootTimesLoader::Get()->AddLoginTimeMarker("AuthStarted", false);
544 Profile* profile = g_browser_process->profile_manager()->GetDefaultProfile(); 523 Profile* profile = g_browser_process->profile_manager()->GetDefaultProfile();
545 524
546 authenticator_ = LoginUtils::Get()->CreateAuthenticator(this); 525 authenticator_ = LoginUtils::Get()->CreateAuthenticator(this);
547 BrowserThread::PostTask( 526 BrowserThread::PostTask(
548 BrowserThread::UI, FROM_HERE, 527 BrowserThread::UI, FROM_HERE,
549 base::Bind(&Authenticator::CompleteLogin, authenticator_.get(), profile, 528 base::Bind(&Authenticator::CompleteLogin, authenticator_.get(),
550 username_, password_)); 529 profile,
530 username_,
531 password_));
551 532
552 password_.clear(); 533 password_.clear();
553 } 534 }
554 535
555 void LoginPerformer::StartAuthentication() { 536 void LoginPerformer::StartAuthentication() {
556 DVLOG(1) << "Auth started"; 537 DVLOG(1) << "Auth started";
557 BootTimesLoader::Get()->AddLoginTimeMarker("AuthStarted", false); 538 BootTimesLoader::Get()->AddLoginTimeMarker("AuthStarted", false);
558 Profile* profile = g_browser_process->profile_manager()->GetDefaultProfile(); 539 Profile* profile = g_browser_process->profile_manager()->GetDefaultProfile();
559 if (delegate_) { 540 if (delegate_) {
560 authenticator_ = LoginUtils::Get()->CreateAuthenticator(this); 541 authenticator_ = LoginUtils::Get()->CreateAuthenticator(this);
561 BrowserThread::PostTask( 542 BrowserThread::PostTask(
562 BrowserThread::UI, FROM_HERE, 543 BrowserThread::UI, FROM_HERE,
563 base::Bind(&Authenticator::AuthenticateToLogin, authenticator_.get(), 544 base::Bind(&Authenticator::AuthenticateToLogin, authenticator_.get(),
564 profile, username_, password_, captcha_token_, captcha_)); 545 profile,
546 username_,
547 password_,
548 captcha_token_,
549 captcha_));
565 } else { 550 } else {
566 DCHECK(authenticator_.get()) 551 DCHECK(authenticator_.get())
567 << "Authenticator instance doesn't exist for login attempt retry."; 552 << "Authenticator instance doesn't exist for login attempt retry.";
568 // At this point offline auth has been successful, 553 // At this point offline auth has been successful,
569 // retry online auth, using existing Authenticator instance. 554 // retry online auth, using existing Authenticator instance.
570 BrowserThread::PostTask( 555 BrowserThread::PostTask(
571 BrowserThread::UI, FROM_HERE, 556 BrowserThread::UI, FROM_HERE,
572 base::Bind(&Authenticator::RetryAuth, authenticator_.get(), profile, 557 base::Bind(&Authenticator::RetryAuth, authenticator_.get(),
573 username_, password_, captcha_token_, captcha_)); 558 profile,
559 username_,
560 password_,
561 captcha_token_,
562 captcha_));
574 } 563 }
575 password_.clear(); 564 password_.clear();
576 } 565 }
577 566
578 } // namespace chromeos 567 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698