| 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 "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/prefs/pref_service.h" | 8 #include "base/prefs/pref_service.h" |
| 9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
| 10 #include "chrome/browser/browser_process.h" | 10 #include "chrome/browser/browser_process.h" |
| (...skipping 21 matching lines...) Expand all Loading... |
| 32 #include "net/url_request/url_request_context_getter.h" | 32 #include "net/url_request/url_request_context_getter.h" |
| 33 #include "url/gurl.h" | 33 #include "url/gurl.h" |
| 34 | 34 |
| 35 #if defined(ENABLE_SUPERVISED_USERS) | 35 #if defined(ENABLE_SUPERVISED_USERS) |
| 36 #include "chrome/browser/supervised_user/supervised_user_constants.h" | 36 #include "chrome/browser/supervised_user/supervised_user_constants.h" |
| 37 #endif | 37 #endif |
| 38 | 38 |
| 39 #if defined(OS_CHROMEOS) | 39 #if defined(OS_CHROMEOS) |
| 40 #include "chrome/browser/chromeos/net/delay_network_call.h" | 40 #include "chrome/browser/chromeos/net/delay_network_call.h" |
| 41 #include "chrome/browser/chromeos/profiles/profile_helper.h" | 41 #include "chrome/browser/chromeos/profiles/profile_helper.h" |
| 42 #include "components/user_manager/known_user.h" |
| 42 #include "components/user_manager/user_manager.h" | 43 #include "components/user_manager/user_manager.h" |
| 43 #endif | 44 #endif |
| 44 | 45 |
| 45 #if !defined(OS_ANDROID) | 46 #if !defined(OS_ANDROID) |
| 46 #include "chrome/browser/first_run/first_run.h" | 47 #include "chrome/browser/first_run/first_run.h" |
| 47 #endif | 48 #endif |
| 48 | 49 |
| 49 ChromeSigninClient::ChromeSigninClient( | 50 ChromeSigninClient::ChromeSigninClient( |
| 50 Profile* profile, SigninErrorController* signin_error_controller) | 51 Profile* profile, SigninErrorController* signin_error_controller) |
| 51 : OAuth2TokenService::Consumer("chrome_signin_client"), | 52 : OAuth2TokenService::Consumer("chrome_signin_client"), |
| 52 profile_(profile), | 53 profile_(profile), |
| 53 signin_error_controller_(signin_error_controller) { | 54 signin_error_controller_(signin_error_controller) { |
| 54 signin_error_controller_->AddObserver(this); | 55 signin_error_controller_->AddObserver(this); |
| 55 #if !defined(OS_CHROMEOS) | 56 #if !defined(OS_CHROMEOS) |
| 56 net::NetworkChangeNotifier::AddNetworkChangeObserver(this); | 57 net::NetworkChangeNotifier::AddNetworkChangeObserver(this); |
| 57 #else | 58 #else |
| 58 // UserManager may not exist in unit_tests. | 59 // UserManager may not exist in unit_tests. |
| 59 if (!user_manager::UserManager::IsInitialized()) | 60 if (!user_manager::UserManager::IsInitialized()) |
| 60 return; | 61 return; |
| 61 | 62 |
| 62 const user_manager::User* user = | 63 const user_manager::User* user = |
| 63 chromeos::ProfileHelper::Get()->GetUserByProfile(profile_); | 64 chromeos::ProfileHelper::Get()->GetUserByProfile(profile_); |
| 64 if (!user) | 65 if (!user) |
| 65 return; | 66 return; |
| 66 auto* user_manager = user_manager::UserManager::Get(); | |
| 67 const AccountId account_id = user->GetAccountId(); | 67 const AccountId account_id = user->GetAccountId(); |
| 68 if (user_manager->GetKnownUserDeviceId(account_id).empty()) { | 68 if (user_manager::known_user::GetKnownUserDeviceId(account_id).empty()) { |
| 69 const std::string legacy_device_id = | 69 const std::string legacy_device_id = |
| 70 GetPrefs()->GetString(prefs::kGoogleServicesSigninScopedDeviceId); | 70 GetPrefs()->GetString(prefs::kGoogleServicesSigninScopedDeviceId); |
| 71 if (!legacy_device_id.empty()) { | 71 if (!legacy_device_id.empty()) { |
| 72 // Need to move device ID from the old location to the new one, if it has | 72 // Need to move device ID from the old location to the new one, if it has |
| 73 // not been done yet. | 73 // not been done yet. |
| 74 user_manager->SetKnownUserDeviceId(account_id, legacy_device_id); | 74 user_manager::known_user::SetKnownUserDeviceId(account_id, |
| 75 legacy_device_id); |
| 75 } else { | 76 } else { |
| 76 user_manager->SetKnownUserDeviceId( | 77 user_manager::known_user::SetKnownUserDeviceId( |
| 77 account_id, | 78 account_id, GenerateSigninScopedDeviceID( |
| 78 GenerateSigninScopedDeviceID( | 79 user_manager::UserManager::Get() |
| 79 user_manager->IsUserNonCryptohomeDataEphemeral(account_id))); | 80 ->IsUserNonCryptohomeDataEphemeral(account_id))); |
| 80 } | 81 } |
| 81 } | 82 } |
| 82 GetPrefs()->SetString(prefs::kGoogleServicesSigninScopedDeviceId, | 83 GetPrefs()->SetString(prefs::kGoogleServicesSigninScopedDeviceId, |
| 83 std::string()); | 84 std::string()); |
| 84 #endif | 85 #endif |
| 85 } | 86 } |
| 86 | 87 |
| 87 ChromeSigninClient::~ChromeSigninClient() { | 88 ChromeSigninClient::~ChromeSigninClient() { |
| 88 signin_error_controller_->RemoveObserver(this); | 89 signin_error_controller_->RemoveObserver(this); |
| 89 } | 90 } |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 147 // UserManager may not exist in unit_tests. | 148 // UserManager may not exist in unit_tests. |
| 148 if (!user_manager::UserManager::IsInitialized()) | 149 if (!user_manager::UserManager::IsInitialized()) |
| 149 return std::string(); | 150 return std::string(); |
| 150 | 151 |
| 151 const user_manager::User* user = | 152 const user_manager::User* user = |
| 152 chromeos::ProfileHelper::Get()->GetUserByProfile(profile_); | 153 chromeos::ProfileHelper::Get()->GetUserByProfile(profile_); |
| 153 if (!user) | 154 if (!user) |
| 154 return std::string(); | 155 return std::string(); |
| 155 | 156 |
| 156 const std::string signin_scoped_device_id = | 157 const std::string signin_scoped_device_id = |
| 157 user_manager::UserManager::Get()->GetKnownUserDeviceId( | 158 user_manager::known_user::GetKnownUserDeviceId(user->GetAccountId()); |
| 158 user->GetAccountId()); | |
| 159 LOG_IF(ERROR, signin_scoped_device_id.empty()) | 159 LOG_IF(ERROR, signin_scoped_device_id.empty()) |
| 160 << "Device ID is not set for user."; | 160 << "Device ID is not set for user."; |
| 161 return signin_scoped_device_id; | 161 return signin_scoped_device_id; |
| 162 #endif | 162 #endif |
| 163 } | 163 } |
| 164 | 164 |
| 165 void ChromeSigninClient::OnSignedOut() { | 165 void ChromeSigninClient::OnSignedOut() { |
| 166 ProfileInfoCache& cache = | 166 ProfileInfoCache& cache = |
| 167 g_browser_process->profile_manager()->GetProfileInfoCache(); | 167 g_browser_process->profile_manager()->GetProfileInfoCache(); |
| 168 size_t index = cache.GetIndexOfProfileWithPath(profile_->GetPath()); | 168 size_t index = cache.GetIndexOfProfileWithPath(profile_->GetPath()); |
| (...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 371 ProfileOAuth2TokenService* token_service = | 371 ProfileOAuth2TokenService* token_service = |
| 372 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_); | 372 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_); |
| 373 OAuth2TokenService::ScopeSet scopes; | 373 OAuth2TokenService::ScopeSet scopes; |
| 374 scopes.insert(GaiaConstants::kGoogleUserInfoEmail); | 374 scopes.insert(GaiaConstants::kGoogleUserInfoEmail); |
| 375 oauth_request_ = token_service->StartRequest(account_id, scopes, this); | 375 oauth_request_ = token_service->StartRequest(account_id, scopes, this); |
| 376 } | 376 } |
| 377 } | 377 } |
| 378 } | 378 } |
| 379 #endif | 379 #endif |
| 380 } | 380 } |
| OLD | NEW |