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

Side by Side Diff: chrome/browser/signin/chrome_signin_client.cc

Issue 2802373002: Add ForceSigninVerifier. (Closed)
Patch Set: add comments Created 3 years, 8 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/chrome_signin_client.h" 5 #include "chrome/browser/signin/chrome_signin_client.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
11 #include "base/command_line.h" 11 #include "base/command_line.h"
12 #include "base/memory/ptr_util.h" 12 #include "base/memory/ptr_util.h"
13 #include "base/strings/utf_string_conversions.h" 13 #include "base/strings/utf_string_conversions.h"
14 #include "build/build_config.h" 14 #include "build/build_config.h"
15 #include "chrome/browser/browser_process.h" 15 #include "chrome/browser/browser_process.h"
16 #include "chrome/browser/content_settings/cookie_settings_factory.h" 16 #include "chrome/browser/content_settings/cookie_settings_factory.h"
17 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" 17 #include "chrome/browser/content_settings/host_content_settings_map_factory.h"
18 #include "chrome/browser/profiles/profile_attributes_entry.h" 18 #include "chrome/browser/profiles/profile_attributes_entry.h"
19 #include "chrome/browser/profiles/profile_attributes_storage.h" 19 #include "chrome/browser/profiles/profile_attributes_storage.h"
20 #include "chrome/browser/profiles/profile_manager.h" 20 #include "chrome/browser/profiles/profile_manager.h"
21 #include "chrome/browser/profiles/profile_metrics.h" 21 #include "chrome/browser/profiles/profile_metrics.h"
22 #include "chrome/browser/profiles/profile_window.h" 22 #include "chrome/browser/profiles/profile_window.h"
23 #include "chrome/browser/signin/force_signin_verifier.h"
23 #include "chrome/browser/signin/local_auth.h" 24 #include "chrome/browser/signin/local_auth.h"
24 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" 25 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h"
25 #include "chrome/browser/signin/signin_manager_factory.h" 26 #include "chrome/browser/signin/signin_manager_factory.h"
27 #include "chrome/browser/signin/signin_util.h"
26 #include "chrome/browser/ui/browser_list.h" 28 #include "chrome/browser/ui/browser_list.h"
27 #include "chrome/browser/ui/user_manager.h" 29 #include "chrome/browser/ui/user_manager.h"
28 #include "chrome/browser/web_data_service_factory.h" 30 #include "chrome/browser/web_data_service_factory.h"
29 #include "chrome/common/channel_info.h" 31 #include "chrome/common/channel_info.h"
30 #include "chrome/common/features.h" 32 #include "chrome/common/features.h"
31 #include "chrome/common/pref_names.h" 33 #include "chrome/common/pref_names.h"
32 #include "components/content_settings/core/browser/cookie_settings.h" 34 #include "components/content_settings/core/browser/cookie_settings.h"
33 #include "components/metrics/metrics_service.h" 35 #include "components/metrics/metrics_service.h"
34 #include "components/prefs/pref_service.h" 36 #include "components/prefs/pref_service.h"
35 #include "components/signin/core/browser/profile_oauth2_token_service.h" 37 #include "components/signin/core/browser/profile_oauth2_token_service.h"
(...skipping 29 matching lines...) Expand all
65 return prefs && prefs->GetBoolean(prefs::kForceBrowserSignin); 67 return prefs && prefs->GetBoolean(prefs::kForceBrowserSignin);
66 } 68 }
67 69
68 } // namespace 70 } // namespace
69 71
70 ChromeSigninClient::ChromeSigninClient( 72 ChromeSigninClient::ChromeSigninClient(
71 Profile* profile, 73 Profile* profile,
72 SigninErrorController* signin_error_controller) 74 SigninErrorController* signin_error_controller)
73 : OAuth2TokenService::Consumer("chrome_signin_client"), 75 : OAuth2TokenService::Consumer("chrome_signin_client"),
74 profile_(profile), 76 profile_(profile),
75 signin_error_controller_(signin_error_controller), 77 signin_error_controller_(signin_error_controller) {
76 is_force_signin_enabled_(IsForceSigninEnabled()) {
77 signin_error_controller_->AddObserver(this); 78 signin_error_controller_->AddObserver(this);
78 #if !defined(OS_CHROMEOS) 79 #if !defined(OS_CHROMEOS)
79 net::NetworkChangeNotifier::AddNetworkChangeObserver(this); 80 net::NetworkChangeNotifier::AddNetworkChangeObserver(this);
80 #else 81 #else
81 // UserManager may not exist in unit_tests. 82 // UserManager may not exist in unit_tests.
82 if (!user_manager::UserManager::IsInitialized()) 83 if (!user_manager::UserManager::IsInitialized())
83 return; 84 return;
84 85
85 const user_manager::User* user = 86 const user_manager::User* user =
86 chromeos::ProfileHelper::Get()->GetUserByProfile(profile_); 87 chromeos::ProfileHelper::Get()->GetUserByProfile(profile_);
(...skipping 24 matching lines...) Expand all
111 } 112 }
112 113
113 void ChromeSigninClient::Shutdown() { 114 void ChromeSigninClient::Shutdown() {
114 #if !defined(OS_CHROMEOS) 115 #if !defined(OS_CHROMEOS)
115 net::NetworkChangeNotifier::RemoveNetworkChangeObserver(this); 116 net::NetworkChangeNotifier::RemoveNetworkChangeObserver(this);
116 #endif 117 #endif
117 } 118 }
118 119
119 void ChromeSigninClient::DoFinalInit() { 120 void ChromeSigninClient::DoFinalInit() {
120 MaybeFetchSigninTokenHandle(); 121 MaybeFetchSigninTokenHandle();
122 VerifySyncToken();
121 } 123 }
122 124
123 // static 125 // static
124 bool ChromeSigninClient::ProfileAllowsSigninCookies(Profile* profile) { 126 bool ChromeSigninClient::ProfileAllowsSigninCookies(Profile* profile) {
125 content_settings::CookieSettings* cookie_settings = 127 content_settings::CookieSettings* cookie_settings =
126 CookieSettingsFactory::GetForProfile(profile).get(); 128 CookieSettingsFactory::GetForProfile(profile).get();
127 return signin::SettingsAllowSigninCookies(cookie_settings); 129 return signin::SettingsAllowSigninCookies(cookie_settings);
128 } 130 }
129 131
130 PrefService* ChromeSigninClient::GetPrefs() { return profile_->GetPrefs(); } 132 PrefService* ChromeSigninClient::GetPrefs() { return profile_->GetPrefs(); }
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
273 // Don't store password hash except when lock is available for the user. 275 // Don't store password hash except when lock is available for the user.
274 if (!password.empty() && profiles::IsLockAvailable(profile_)) 276 if (!password.empty() && profiles::IsLockAvailable(profile_))
275 LocalAuth::SetLocalAuthCredentials(profile_, password); 277 LocalAuth::SetLocalAuthCredentials(profile_, password);
276 #endif 278 #endif
277 } 279 }
278 280
279 void ChromeSigninClient::PreSignOut( 281 void ChromeSigninClient::PreSignOut(
280 const base::Callback<void()>& sign_out, 282 const base::Callback<void()>& sign_out,
281 signin_metrics::ProfileSignout signout_source_metric) { 283 signin_metrics::ProfileSignout signout_source_metric) {
282 #if !defined(OS_ANDROID) && !defined(OS_CHROMEOS) 284 #if !defined(OS_ANDROID) && !defined(OS_CHROMEOS)
283 if (is_force_signin_enabled_ && !profile_->IsSystemProfile() && 285 if (signin_util::IsForceSigninEnabled() && !profile_->IsSystemProfile() &&
284 !profile_->IsGuestSession() && !profile_->IsSupervised()) { 286 !profile_->IsGuestSession() && !profile_->IsSupervised()) {
285 // TODO(zmin): force window closing based on the reason of sign-out. 287 // TODO(zmin): force window closing based on the reason of sign-out.
286 // This will be updated after force window closing CL is commited. 288 // This will be updated after force window closing CL is commited.
287 289
288 // User can't abort the window closing unless user sign out manually. 290 // User can't abort the window closing unless user sign out manually.
289 BrowserList::CloseAllBrowsersWithProfile( 291 BrowserList::CloseAllBrowsersWithProfile(
290 profile_, 292 profile_,
291 base::Bind(&ChromeSigninClient::OnCloseBrowsersSuccess, 293 base::Bind(&ChromeSigninClient::OnCloseBrowsersSuccess,
292 base::Unretained(this), sign_out, signout_source_metric), 294 base::Unretained(this), sign_out, signout_source_metric),
293 base::Bind(&ChromeSigninClient::OnCloseBrowsersAborted, 295 base::Bind(&ChromeSigninClient::OnCloseBrowsersAborted,
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
392 #endif 394 #endif
393 } 395 }
394 396
395 std::unique_ptr<GaiaAuthFetcher> ChromeSigninClient::CreateGaiaAuthFetcher( 397 std::unique_ptr<GaiaAuthFetcher> ChromeSigninClient::CreateGaiaAuthFetcher(
396 GaiaAuthConsumer* consumer, 398 GaiaAuthConsumer* consumer,
397 const std::string& source, 399 const std::string& source,
398 net::URLRequestContextGetter* getter) { 400 net::URLRequestContextGetter* getter) {
399 return base::MakeUnique<GaiaAuthFetcher>(consumer, source, getter); 401 return base::MakeUnique<GaiaAuthFetcher>(consumer, source, getter);
400 } 402 }
401 403
404 void ChromeSigninClient::VerifySyncToken() {
405 #if !defined(OS_ANDROID) && !defined(OS_CHROMEOS)
406 if (signin_util::IsForceSigninEnabled())
407 force_signin_verifier_ = base::MakeUnique<ForceSigninVerifier>(profile_);
408 #endif
409 }
410
402 void ChromeSigninClient::MaybeFetchSigninTokenHandle() { 411 void ChromeSigninClient::MaybeFetchSigninTokenHandle() {
403 #if !defined(OS_ANDROID) && !defined(OS_CHROMEOS) 412 #if !defined(OS_ANDROID) && !defined(OS_CHROMEOS)
404 // We get a "handle" that can be used to reference the signin token on the 413 // We get a "handle" that can be used to reference the signin token on the
405 // server. We fetch this if we don't have one so that later we can check 414 // server. We fetch this if we don't have one so that later we can check
406 // it to know if the signin token to which it is attached has been revoked 415 // it to know if the signin token to which it is attached has been revoked
407 // and thus distinguish between a password mismatch due to the password 416 // and thus distinguish between a password mismatch due to the password
408 // being changed and the user simply mis-typing it. 417 // being changed and the user simply mis-typing it.
409 if (profiles::IsLockAvailable(profile_)) { 418 if (profiles::IsLockAvailable(profile_)) {
410 ProfileAttributesStorage& storage = 419 ProfileAttributesStorage& storage =
411 g_browser_process->profile_manager()->GetProfileAttributesStorage(); 420 g_browser_process->profile_manager()->GetProfileAttributesStorage();
412 ProfileAttributesEntry* entry; 421 ProfileAttributesEntry* entry;
413 // If we don't have a token for detecting a password change, create one. 422 // If we don't have a token for detecting a password change, create one.
414 if (storage.GetProfileAttributesWithPath(profile_->GetPath(), &entry) && 423 if (storage.GetProfileAttributesWithPath(profile_->GetPath(), &entry) &&
415 entry->GetPasswordChangeDetectionToken().empty() && !oauth_request_) { 424 entry->GetPasswordChangeDetectionToken().empty() && !oauth_request_) {
416 std::string account_id = SigninManagerFactory::GetForProfile(profile_) 425 std::string account_id = SigninManagerFactory::GetForProfile(profile_)
417 ->GetAuthenticatedAccountId(); 426 ->GetAuthenticatedAccountId();
418 if (!account_id.empty()) { 427 if (!account_id.empty()) {
419 ProfileOAuth2TokenService* token_service = 428 ProfileOAuth2TokenService* token_service =
420 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_); 429 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_);
421 OAuth2TokenService::ScopeSet scopes; 430 OAuth2TokenService::ScopeSet scopes;
422 scopes.insert(GaiaConstants::kGoogleUserInfoEmail); 431 scopes.insert(GaiaConstants::kGoogleUserInfoEmail);
423 oauth_request_ = token_service->StartRequest(account_id, scopes, this); 432 oauth_request_ = token_service->StartRequest(account_id, scopes, this);
424 } 433 }
425 } 434 }
426 } 435 }
427 #endif 436 #endif
428 } 437 }
429 438
430 void ChromeSigninClient::AfterCredentialsCopied() { 439 void ChromeSigninClient::AfterCredentialsCopied() {
431 if (is_force_signin_enabled_) { 440 if (signin_util::IsForceSigninEnabled()) {
432 // The signout after credential copy won't open UserManager after all 441 // The signout after credential copy won't open UserManager after all
433 // browser window are closed. Because the browser window will be opened for 442 // browser window are closed. Because the browser window will be opened for
434 // the new profile soon. 443 // the new profile soon.
435 should_display_user_manager_ = false; 444 should_display_user_manager_ = false;
436 } 445 }
437 } 446 }
438 447
439 void ChromeSigninClient::OnCloseBrowsersSuccess( 448 void ChromeSigninClient::OnCloseBrowsersSuccess(
440 const base::Callback<void()>& sign_out, 449 const base::Callback<void()>& sign_out,
441 const signin_metrics::ProfileSignout signout_source_metric, 450 const signin_metrics::ProfileSignout signout_source_metric,
442 const base::FilePath& profile_path) { 451 const base::FilePath& profile_path) {
452 force_signin_verifier_->Cancel();
443 SigninClient::PreSignOut(sign_out, signout_source_metric); 453 SigninClient::PreSignOut(sign_out, signout_source_metric);
444 454
445 LockForceSigninProfile(profile_path); 455 LockForceSigninProfile(profile_path);
446 // After sign out, lock the profile and show UserManager if necessary. 456 // After sign out, lock the profile and show UserManager if necessary.
447 if (should_display_user_manager_) { 457 if (should_display_user_manager_) {
448 ShowUserManager(profile_path); 458 ShowUserManager(profile_path);
449 } else { 459 } else {
450 should_display_user_manager_ = true; 460 should_display_user_manager_ = true;
451 } 461 }
452 } 462 }
(...skipping 14 matching lines...) Expand all
467 return; 477 return;
468 entry->LockForceSigninProfile(true); 478 entry->LockForceSigninProfile(true);
469 } 479 }
470 480
471 void ChromeSigninClient::ShowUserManager(const base::FilePath& profile_path) { 481 void ChromeSigninClient::ShowUserManager(const base::FilePath& profile_path) {
472 #if !defined(OS_ANDROID) && !defined(OS_CHROMEOS) 482 #if !defined(OS_ANDROID) && !defined(OS_CHROMEOS)
473 UserManager::Show(profile_path, profiles::USER_MANAGER_NO_TUTORIAL, 483 UserManager::Show(profile_path, profiles::USER_MANAGER_NO_TUTORIAL,
474 profiles::USER_MANAGER_SELECT_PROFILE_NO_ACTION); 484 profiles::USER_MANAGER_SELECT_PROFILE_NO_ACTION);
475 #endif 485 #endif
476 } 486 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698