| OLD | NEW |
| 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/command_line.h" | 11 #include "base/command_line.h" |
| 11 #include "base/strings/utf_string_conversions.h" | 12 #include "base/strings/utf_string_conversions.h" |
| 12 #include "build/build_config.h" | 13 #include "build/build_config.h" |
| 13 #include "chrome/browser/browser_process.h" | 14 #include "chrome/browser/browser_process.h" |
| 14 #include "chrome/browser/content_settings/cookie_settings_factory.h" | 15 #include "chrome/browser/content_settings/cookie_settings_factory.h" |
| 15 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" | 16 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" |
| 16 #include "chrome/browser/profiles/profile_attributes_entry.h" | 17 #include "chrome/browser/profiles/profile_attributes_entry.h" |
| 17 #include "chrome/browser/profiles/profile_attributes_storage.h" | 18 #include "chrome/browser/profiles/profile_attributes_storage.h" |
| 18 #include "chrome/browser/profiles/profile_manager.h" | 19 #include "chrome/browser/profiles/profile_manager.h" |
| 19 #include "chrome/browser/profiles/profile_metrics.h" | 20 #include "chrome/browser/profiles/profile_metrics.h" |
| 20 #include "chrome/browser/profiles/profile_window.h" | 21 #include "chrome/browser/profiles/profile_window.h" |
| 21 #include "chrome/browser/signin/local_auth.h" | 22 #include "chrome/browser/signin/local_auth.h" |
| 22 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" | 23 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" |
| 23 #include "chrome/browser/signin/signin_manager_factory.h" | 24 #include "chrome/browser/signin/signin_manager_factory.h" |
| 25 #include "chrome/browser/ui/browser_list.h" |
| 26 #include "chrome/browser/ui/user_manager.h" |
| 24 #include "chrome/browser/web_data_service_factory.h" | 27 #include "chrome/browser/web_data_service_factory.h" |
| 25 #include "chrome/common/channel_info.h" | 28 #include "chrome/common/channel_info.h" |
| 26 #include "chrome/common/features.h" | 29 #include "chrome/common/features.h" |
| 30 #include "chrome/common/pref_names.h" |
| 27 #include "components/content_settings/core/browser/cookie_settings.h" | 31 #include "components/content_settings/core/browser/cookie_settings.h" |
| 28 #include "components/metrics/metrics_service.h" | 32 #include "components/metrics/metrics_service.h" |
| 29 #include "components/prefs/pref_service.h" | 33 #include "components/prefs/pref_service.h" |
| 30 #include "components/signin/core/browser/profile_oauth2_token_service.h" | 34 #include "components/signin/core/browser/profile_oauth2_token_service.h" |
| 31 #include "components/signin/core/browser/signin_cookie_changed_subscription.h" | 35 #include "components/signin/core/browser/signin_cookie_changed_subscription.h" |
| 32 #include "components/signin/core/browser/signin_header_helper.h" | 36 #include "components/signin/core/browser/signin_header_helper.h" |
| 33 #include "components/signin/core/common/profile_management_switches.h" | 37 #include "components/signin/core/common/profile_management_switches.h" |
| 34 #include "components/signin/core/common/signin_pref_names.h" | 38 #include "components/signin/core/common/signin_pref_names.h" |
| 35 #include "components/signin/core/common/signin_switches.h" | 39 #include "components/signin/core/common/signin_switches.h" |
| 36 #include "google_apis/gaia/gaia_constants.h" | 40 #include "google_apis/gaia/gaia_constants.h" |
| 37 #include "google_apis/gaia/gaia_urls.h" | 41 #include "google_apis/gaia/gaia_urls.h" |
| 38 #include "net/url_request/url_request_context_getter.h" | 42 #include "net/url_request/url_request_context_getter.h" |
| 39 #include "url/gurl.h" | 43 #include "url/gurl.h" |
| 40 | 44 |
| 41 #if BUILDFLAG(ENABLE_SUPERVISED_USERS) | 45 #if BUILDFLAG(ENABLE_SUPERVISED_USERS) |
| 42 #include "chrome/browser/supervised_user/supervised_user_constants.h" | 46 #include "chrome/browser/supervised_user/supervised_user_constants.h" |
| 43 #endif | 47 #endif |
| 44 | 48 |
| 45 #if defined(OS_CHROMEOS) | 49 #if defined(OS_CHROMEOS) |
| 46 #include "chrome/browser/chromeos/net/delay_network_call.h" | 50 #include "chrome/browser/chromeos/net/delay_network_call.h" |
| 47 #include "chrome/browser/chromeos/profiles/profile_helper.h" | 51 #include "chrome/browser/chromeos/profiles/profile_helper.h" |
| 48 #include "components/user_manager/known_user.h" | 52 #include "components/user_manager/known_user.h" |
| 49 #include "components/user_manager/user_manager.h" | 53 #include "components/user_manager/user_manager.h" |
| 50 #endif | 54 #endif |
| 51 | 55 |
| 52 #if !defined(OS_ANDROID) | 56 #if !defined(OS_ANDROID) |
| 53 #include "chrome/browser/first_run/first_run.h" | 57 #include "chrome/browser/first_run/first_run.h" |
| 54 #endif | 58 #endif |
| 55 | 59 |
| 60 namespace { |
| 61 |
| 62 bool IsForceSigninEnabled() { |
| 63 PrefService* prefs = g_browser_process->local_state(); |
| 64 return prefs && prefs->GetBoolean(prefs::kForceBrowserSignin); |
| 65 } |
| 66 |
| 67 } // namespace |
| 68 |
| 56 ChromeSigninClient::ChromeSigninClient( | 69 ChromeSigninClient::ChromeSigninClient( |
| 57 Profile* profile, SigninErrorController* signin_error_controller) | 70 Profile* profile, |
| 71 SigninErrorController* signin_error_controller) |
| 58 : OAuth2TokenService::Consumer("chrome_signin_client"), | 72 : OAuth2TokenService::Consumer("chrome_signin_client"), |
| 59 profile_(profile), | 73 profile_(profile), |
| 60 signin_error_controller_(signin_error_controller) { | 74 signin_error_controller_(signin_error_controller), |
| 75 is_force_signin_enabled_(IsForceSigninEnabled()) { |
| 61 signin_error_controller_->AddObserver(this); | 76 signin_error_controller_->AddObserver(this); |
| 62 #if !defined(OS_CHROMEOS) | 77 #if !defined(OS_CHROMEOS) |
| 63 net::NetworkChangeNotifier::AddNetworkChangeObserver(this); | 78 net::NetworkChangeNotifier::AddNetworkChangeObserver(this); |
| 64 #else | 79 #else |
| 65 // UserManager may not exist in unit_tests. | 80 // UserManager may not exist in unit_tests. |
| 66 if (!user_manager::UserManager::IsInitialized()) | 81 if (!user_manager::UserManager::IsInitialized()) |
| 67 return; | 82 return; |
| 68 | 83 |
| 69 const user_manager::User* user = | 84 const user_manager::User* user = |
| 70 chromeos::ProfileHelper::Get()->GetUserByProfile(profile_); | 85 chromeos::ProfileHelper::Get()->GetUserByProfile(profile_); |
| (...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 253 void ChromeSigninClient::PostSignedIn(const std::string& account_id, | 268 void ChromeSigninClient::PostSignedIn(const std::string& account_id, |
| 254 const std::string& username, | 269 const std::string& username, |
| 255 const std::string& password) { | 270 const std::string& password) { |
| 256 #if !defined(OS_ANDROID) && !defined(OS_CHROMEOS) | 271 #if !defined(OS_ANDROID) && !defined(OS_CHROMEOS) |
| 257 // Don't store password hash except when lock is available for the user. | 272 // Don't store password hash except when lock is available for the user. |
| 258 if (!password.empty() && profiles::IsLockAvailable(profile_)) | 273 if (!password.empty() && profiles::IsLockAvailable(profile_)) |
| 259 LocalAuth::SetLocalAuthCredentials(profile_, password); | 274 LocalAuth::SetLocalAuthCredentials(profile_, password); |
| 260 #endif | 275 #endif |
| 261 } | 276 } |
| 262 | 277 |
| 278 void ChromeSigninClient::PreSignOut(const base::Callback<void()>& sign_out) { |
| 279 #if !defined(OS_ANDROID) && !defined(OS_CHROMEOS) |
| 280 if (is_force_signin_enabled_ && !profile_->IsSystemProfile() && |
| 281 !profile_->IsGuestSession()) { |
| 282 BrowserList::CloseAllBrowsersWithProfile( |
| 283 profile_, base::Bind(&ChromeSigninClient::OnCloseBrowsersSuccess, |
| 284 base::Unretained(this), sign_out), |
| 285 base::Bind(&ChromeSigninClient::OnCloseBrowsersAborted, |
| 286 base::Unretained(this))); |
| 287 } else { |
| 288 #else |
| 289 { |
| 290 #endif |
| 291 SigninClient::PreSignOut(sign_out); |
| 292 } |
| 293 } |
| 294 |
| 263 void ChromeSigninClient::OnErrorChanged() { | 295 void ChromeSigninClient::OnErrorChanged() { |
| 264 // Some tests don't have a ProfileManager. | 296 // Some tests don't have a ProfileManager. |
| 265 if (g_browser_process->profile_manager() == nullptr) | 297 if (g_browser_process->profile_manager() == nullptr) |
| 266 return; | 298 return; |
| 267 | 299 |
| 268 ProfileAttributesEntry* entry; | 300 ProfileAttributesEntry* entry; |
| 269 | 301 |
| 270 if (!g_browser_process->profile_manager()->GetProfileAttributesStorage(). | 302 if (!g_browser_process->profile_manager()->GetProfileAttributesStorage(). |
| 271 GetProfileAttributesWithPath(profile_->GetPath(), &entry)) { | 303 GetProfileAttributesWithPath(profile_->GetPath(), &entry)) { |
| 272 return; | 304 return; |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 378 ProfileOAuth2TokenService* token_service = | 410 ProfileOAuth2TokenService* token_service = |
| 379 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_); | 411 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_); |
| 380 OAuth2TokenService::ScopeSet scopes; | 412 OAuth2TokenService::ScopeSet scopes; |
| 381 scopes.insert(GaiaConstants::kGoogleUserInfoEmail); | 413 scopes.insert(GaiaConstants::kGoogleUserInfoEmail); |
| 382 oauth_request_ = token_service->StartRequest(account_id, scopes, this); | 414 oauth_request_ = token_service->StartRequest(account_id, scopes, this); |
| 383 } | 415 } |
| 384 } | 416 } |
| 385 } | 417 } |
| 386 #endif | 418 #endif |
| 387 } | 419 } |
| 420 |
| 421 void ChromeSigninClient::AfterCredentialsCopied() { |
| 422 if (is_force_signin_enabled_) { |
| 423 // The signout after credential copy won't open UserManager after all |
| 424 // browser window are closed. Because the browser window will be opened for |
| 425 // the new profile soon. |
| 426 should_display_user_manager_ = false; |
| 427 } |
| 428 } |
| 429 |
| 430 void ChromeSigninClient::OnCloseBrowsersSuccess( |
| 431 const base::Callback<void()>& sign_out, |
| 432 const base::FilePath& profile_path) { |
| 433 SigninClient::PreSignOut(sign_out); |
| 434 |
| 435 LockProfile(profile_path); |
| 436 // After sign out, lock the profile and show UserManager if necessary. |
| 437 if (should_display_user_manager_) { |
| 438 ShowUserManager(profile_path); |
| 439 } else { |
| 440 should_display_user_manager_ = true; |
| 441 } |
| 442 } |
| 443 |
| 444 void ChromeSigninClient::OnCloseBrowsersAborted( |
| 445 const base::FilePath& profile_path) { |
| 446 should_display_user_manager_ = true; |
| 447 } |
| 448 |
| 449 void ChromeSigninClient::LockProfile(const base::FilePath& profile_path) { |
| 450 ProfileAttributesEntry* entry; |
| 451 bool has_entry = |
| 452 g_browser_process->profile_manager() |
| 453 ->GetProfileAttributesStorage() |
| 454 .GetProfileAttributesWithPath(profile_->GetPath(), &entry); |
| 455 if (!has_entry) |
| 456 return; |
| 457 entry->SetIsSigninRequired(true); |
| 458 } |
| 459 |
| 460 void ChromeSigninClient::ShowUserManager(const base::FilePath& profile_path) { |
| 461 #if !defined(OS_ANDROID) && !defined(OS_CHROMEOS) |
| 462 UserManager::Show(profile_path, profiles::USER_MANAGER_NO_TUTORIAL, |
| 463 profiles::USER_MANAGER_SELECT_PROFILE_NO_ACTION); |
| 464 #endif |
| 465 } |
| OLD | NEW |