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

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

Issue 2802373002: Add ForceSigninVerifier. (Closed)
Patch Set: rogers' 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 15 matching lines...) Expand all
51 #include "chrome/browser/chromeos/net/delay_network_call.h" 53 #include "chrome/browser/chromeos/net/delay_network_call.h"
52 #include "chrome/browser/chromeos/profiles/profile_helper.h" 54 #include "chrome/browser/chromeos/profiles/profile_helper.h"
53 #include "components/user_manager/known_user.h" 55 #include "components/user_manager/known_user.h"
54 #include "components/user_manager/user_manager.h" 56 #include "components/user_manager/user_manager.h"
55 #endif 57 #endif
56 58
57 #if !defined(OS_ANDROID) 59 #if !defined(OS_ANDROID)
58 #include "chrome/browser/first_run/first_run.h" 60 #include "chrome/browser/first_run/first_run.h"
59 #endif 61 #endif
60 62
61 namespace {
62
63 bool IsForceSigninEnabled() {
64 PrefService* prefs = g_browser_process->local_state();
65 return prefs && prefs->GetBoolean(prefs::kForceBrowserSignin);
66 }
67
68 } // namespace
69
70 ChromeSigninClient::ChromeSigninClient( 63 ChromeSigninClient::ChromeSigninClient(
71 Profile* profile, 64 Profile* profile,
72 SigninErrorController* signin_error_controller) 65 SigninErrorController* signin_error_controller)
73 : OAuth2TokenService::Consumer("chrome_signin_client"), 66 : OAuth2TokenService::Consumer("chrome_signin_client"),
74 profile_(profile), 67 profile_(profile),
75 signin_error_controller_(signin_error_controller), 68 signin_error_controller_(signin_error_controller) {
76 is_force_signin_enabled_(IsForceSigninEnabled()) {
77 signin_error_controller_->AddObserver(this); 69 signin_error_controller_->AddObserver(this);
78 #if !defined(OS_CHROMEOS) 70 #if !defined(OS_CHROMEOS)
79 net::NetworkChangeNotifier::AddNetworkChangeObserver(this); 71 net::NetworkChangeNotifier::AddNetworkChangeObserver(this);
80 #else 72 #else
81 // UserManager may not exist in unit_tests. 73 // UserManager may not exist in unit_tests.
82 if (!user_manager::UserManager::IsInitialized()) 74 if (!user_manager::UserManager::IsInitialized())
83 return; 75 return;
84 76
85 const user_manager::User* user = 77 const user_manager::User* user =
86 chromeos::ProfileHelper::Get()->GetUserByProfile(profile_); 78 chromeos::ProfileHelper::Get()->GetUserByProfile(profile_);
(...skipping 24 matching lines...) Expand all
111 } 103 }
112 104
113 void ChromeSigninClient::Shutdown() { 105 void ChromeSigninClient::Shutdown() {
114 #if !defined(OS_CHROMEOS) 106 #if !defined(OS_CHROMEOS)
115 net::NetworkChangeNotifier::RemoveNetworkChangeObserver(this); 107 net::NetworkChangeNotifier::RemoveNetworkChangeObserver(this);
116 #endif 108 #endif
117 } 109 }
118 110
119 void ChromeSigninClient::DoFinalInit() { 111 void ChromeSigninClient::DoFinalInit() {
120 MaybeFetchSigninTokenHandle(); 112 MaybeFetchSigninTokenHandle();
113 VerifySyncToken();
121 } 114 }
122 115
123 // static 116 // static
124 bool ChromeSigninClient::ProfileAllowsSigninCookies(Profile* profile) { 117 bool ChromeSigninClient::ProfileAllowsSigninCookies(Profile* profile) {
125 content_settings::CookieSettings* cookie_settings = 118 content_settings::CookieSettings* cookie_settings =
126 CookieSettingsFactory::GetForProfile(profile).get(); 119 CookieSettingsFactory::GetForProfile(profile).get();
127 return signin::SettingsAllowSigninCookies(cookie_settings); 120 return signin::SettingsAllowSigninCookies(cookie_settings);
128 } 121 }
129 122
130 PrefService* ChromeSigninClient::GetPrefs() { return profile_->GetPrefs(); } 123 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. 266 // Don't store password hash except when lock is available for the user.
274 if (!password.empty() && profiles::IsLockAvailable(profile_)) 267 if (!password.empty() && profiles::IsLockAvailable(profile_))
275 LocalAuth::SetLocalAuthCredentials(profile_, password); 268 LocalAuth::SetLocalAuthCredentials(profile_, password);
276 #endif 269 #endif
277 } 270 }
278 271
279 void ChromeSigninClient::PreSignOut( 272 void ChromeSigninClient::PreSignOut(
280 const base::Callback<void()>& sign_out, 273 const base::Callback<void()>& sign_out,
281 signin_metrics::ProfileSignout signout_source_metric) { 274 signin_metrics::ProfileSignout signout_source_metric) {
282 #if !defined(OS_ANDROID) && !defined(OS_CHROMEOS) 275 #if !defined(OS_ANDROID) && !defined(OS_CHROMEOS)
283 if (is_force_signin_enabled_ && !profile_->IsSystemProfile() && 276 if (signin_util::IsForceSigninEnabled() && !profile_->IsSystemProfile() &&
284 !profile_->IsGuestSession() && !profile_->IsSupervised()) { 277 !profile_->IsGuestSession() && !profile_->IsSupervised()) {
285 // TODO(zmin): force window closing based on the reason of sign-out. 278 // TODO(zmin): force window closing based on the reason of sign-out.
286 // This will be updated after force window closing CL is commited. 279 // This will be updated after force window closing CL is commited.
287 280
288 // User can't abort the window closing unless user sign out manually. 281 // User can't abort the window closing unless user sign out manually.
289 BrowserList::CloseAllBrowsersWithProfile( 282 BrowserList::CloseAllBrowsersWithProfile(
290 profile_, 283 profile_,
291 base::Bind(&ChromeSigninClient::OnCloseBrowsersSuccess, 284 base::Bind(&ChromeSigninClient::OnCloseBrowsersSuccess,
292 base::Unretained(this), sign_out, signout_source_metric), 285 base::Unretained(this), sign_out, signout_source_metric),
293 base::Bind(&ChromeSigninClient::OnCloseBrowsersAborted, 286 base::Bind(&ChromeSigninClient::OnCloseBrowsersAborted,
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
392 #endif 385 #endif
393 } 386 }
394 387
395 std::unique_ptr<GaiaAuthFetcher> ChromeSigninClient::CreateGaiaAuthFetcher( 388 std::unique_ptr<GaiaAuthFetcher> ChromeSigninClient::CreateGaiaAuthFetcher(
396 GaiaAuthConsumer* consumer, 389 GaiaAuthConsumer* consumer,
397 const std::string& source, 390 const std::string& source,
398 net::URLRequestContextGetter* getter) { 391 net::URLRequestContextGetter* getter) {
399 return base::MakeUnique<GaiaAuthFetcher>(consumer, source, getter); 392 return base::MakeUnique<GaiaAuthFetcher>(consumer, source, getter);
400 } 393 }
401 394
395 void ChromeSigninClient::VerifySyncToken() {
396 #if !defined(OS_ANDROID) && !defined(OS_CHROMEOS)
397 if (signin_util::IsForceSigninEnabled())
398 force_signin_verifier_ = base::MakeUnique<ForceSigninVerifier>(profile_);
399 #endif
400 }
401
402 void ChromeSigninClient::MaybeFetchSigninTokenHandle() { 402 void ChromeSigninClient::MaybeFetchSigninTokenHandle() {
403 #if !defined(OS_ANDROID) && !defined(OS_CHROMEOS) 403 #if !defined(OS_ANDROID) && !defined(OS_CHROMEOS)
404 // We get a "handle" that can be used to reference the signin token on the 404 // 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 405 // 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 406 // 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 407 // and thus distinguish between a password mismatch due to the password
408 // being changed and the user simply mis-typing it. 408 // being changed and the user simply mis-typing it.
409 if (profiles::IsLockAvailable(profile_)) { 409 if (profiles::IsLockAvailable(profile_)) {
410 ProfileAttributesStorage& storage = 410 ProfileAttributesStorage& storage =
411 g_browser_process->profile_manager()->GetProfileAttributesStorage(); 411 g_browser_process->profile_manager()->GetProfileAttributesStorage();
412 ProfileAttributesEntry* entry; 412 ProfileAttributesEntry* entry;
413 // If we don't have a token for detecting a password change, create one. 413 // If we don't have a token for detecting a password change, create one.
414 if (storage.GetProfileAttributesWithPath(profile_->GetPath(), &entry) && 414 if (storage.GetProfileAttributesWithPath(profile_->GetPath(), &entry) &&
415 entry->GetPasswordChangeDetectionToken().empty() && !oauth_request_) { 415 entry->GetPasswordChangeDetectionToken().empty() && !oauth_request_) {
416 std::string account_id = SigninManagerFactory::GetForProfile(profile_) 416 std::string account_id = SigninManagerFactory::GetForProfile(profile_)
417 ->GetAuthenticatedAccountId(); 417 ->GetAuthenticatedAccountId();
418 if (!account_id.empty()) { 418 if (!account_id.empty()) {
419 ProfileOAuth2TokenService* token_service = 419 ProfileOAuth2TokenService* token_service =
420 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_); 420 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_);
421 OAuth2TokenService::ScopeSet scopes; 421 OAuth2TokenService::ScopeSet scopes;
422 scopes.insert(GaiaConstants::kGoogleUserInfoEmail); 422 scopes.insert(GaiaConstants::kGoogleUserInfoEmail);
423 oauth_request_ = token_service->StartRequest(account_id, scopes, this); 423 oauth_request_ = token_service->StartRequest(account_id, scopes, this);
424 } 424 }
425 } 425 }
426 } 426 }
427 #endif 427 #endif
428 } 428 }
429 429
430 void ChromeSigninClient::AfterCredentialsCopied() { 430 void ChromeSigninClient::AfterCredentialsCopied() {
431 if (is_force_signin_enabled_) { 431 if (signin_util::IsForceSigninEnabled()) {
432 // The signout after credential copy won't open UserManager after all 432 // The signout after credential copy won't open UserManager after all
433 // browser window are closed. Because the browser window will be opened for 433 // browser window are closed. Because the browser window will be opened for
434 // the new profile soon. 434 // the new profile soon.
435 should_display_user_manager_ = false; 435 should_display_user_manager_ = false;
436 } 436 }
437 } 437 }
438 438
439 void ChromeSigninClient::OnCloseBrowsersSuccess( 439 void ChromeSigninClient::OnCloseBrowsersSuccess(
440 const base::Callback<void()>& sign_out, 440 const base::Callback<void()>& sign_out,
441 const signin_metrics::ProfileSignout signout_source_metric, 441 const signin_metrics::ProfileSignout signout_source_metric,
442 const base::FilePath& profile_path) { 442 const base::FilePath& profile_path) {
443 #if !defined(OS_ANDROID) && !defined(OS_CHROMEOS)
444 if (signin_util::IsForceSigninEnabled() && force_signin_verifier_.get())
445 force_signin_verifier_->Cancel();
446 #endif
443 SigninClient::PreSignOut(sign_out, signout_source_metric); 447 SigninClient::PreSignOut(sign_out, signout_source_metric);
444 448
445 LockForceSigninProfile(profile_path); 449 LockForceSigninProfile(profile_path);
446 // After sign out, lock the profile and show UserManager if necessary. 450 // After sign out, lock the profile and show UserManager if necessary.
447 if (should_display_user_manager_) { 451 if (should_display_user_manager_) {
448 ShowUserManager(profile_path); 452 ShowUserManager(profile_path);
449 } else { 453 } else {
450 should_display_user_manager_ = true; 454 should_display_user_manager_ = true;
451 } 455 }
452 } 456 }
(...skipping 14 matching lines...) Expand all
467 return; 471 return;
468 entry->LockForceSigninProfile(true); 472 entry->LockForceSigninProfile(true);
469 } 473 }
470 474
471 void ChromeSigninClient::ShowUserManager(const base::FilePath& profile_path) { 475 void ChromeSigninClient::ShowUserManager(const base::FilePath& profile_path) {
472 #if !defined(OS_ANDROID) && !defined(OS_CHROMEOS) 476 #if !defined(OS_ANDROID) && !defined(OS_CHROMEOS)
473 UserManager::Show(profile_path, profiles::USER_MANAGER_NO_TUTORIAL, 477 UserManager::Show(profile_path, profiles::USER_MANAGER_NO_TUTORIAL,
474 profiles::USER_MANAGER_SELECT_PROFILE_NO_ACTION); 478 profiles::USER_MANAGER_SELECT_PROFILE_NO_ACTION);
475 #endif 479 #endif
476 } 480 }
OLDNEW
« no previous file with comments | « chrome/browser/signin/chrome_signin_client.h ('k') | chrome/browser/signin/chrome_signin_client_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698