Chromium Code Reviews| Index: chrome/browser/signin/chrome_signin_client.cc |
| diff --git a/chrome/browser/signin/chrome_signin_client.cc b/chrome/browser/signin/chrome_signin_client.cc |
| index a98dd89930a065fbedb05edce03982d03b268889..caba8cd27a19e5c4365c8d88b6009d0485af1c4c 100644 |
| --- a/chrome/browser/signin/chrome_signin_client.cc |
| +++ b/chrome/browser/signin/chrome_signin_client.cc |
| @@ -33,6 +33,7 @@ |
| #if defined(OS_CHROMEOS) |
| #include "chrome/browser/chromeos/net/delay_network_call.h" |
| +#include "chrome/browser/chromeos/profiles/profile_helper.h" |
| #include "components/user_manager/user_manager.h" |
| #endif |
| @@ -40,6 +41,10 @@ |
| #include "chrome/browser/first_run/first_run.h" |
| #endif |
| +namespace { |
| +const char kEphemeralUserDeviceIDPrefix[] = "t_"; |
| +} |
| + |
| ChromeSigninClient::ChromeSigninClient( |
| Profile* profile, SigninErrorController* signin_error_controller) |
| : profile_(profile), |
| @@ -47,6 +52,33 @@ ChromeSigninClient::ChromeSigninClient( |
| signin_error_controller_->AddObserver(this); |
| #if !defined(OS_CHROMEOS) |
| net::NetworkChangeNotifier::AddNetworkChangeObserver(this); |
| +#else |
| + // UserManager may not exist in unit_tests. |
| + if (!user_manager::UserManager::IsInitialized()) |
| + return; |
| + |
| + const user_manager::User* user = |
| + chromeos::ProfileHelper::Get()->GetUserByProfile(profile_); |
| + if (!user) |
| + return; |
| + auto* user_manager = user_manager::UserManager::Get(); |
| + const std::string& user_id = user->GetUserID(); |
| + if (user_manager->GetKnownUserDeviceId(user_id).empty()) { |
| + const std::string legacy_device_id = |
| + GetPrefs()->GetString(prefs::kGoogleServicesSigninScopedDeviceId); |
| + if (!legacy_device_id.empty()) { |
| + // Need to move device ID from the old location to the new one, if it has |
| + // not been done yet. |
| + user_manager->SetKnownUserDeviceId(user_id, legacy_device_id); |
| + } else { |
| + user_manager->SetKnownUserDeviceId( |
| + user_id, |
| + GenerateSigninScopedDeviceID( |
| + user_manager->IsUserNonCryptohomeDataEphemeral(user_id))); |
| + } |
| + } |
| + GetPrefs()->SetString(prefs::kGoogleServicesSigninScopedDeviceId, |
| + std::string()); |
|
Roger Tawa OOO till Jul 10th
2015/05/15 13:50:23
Why is this cros specific? Desktop needs this too
|
| #endif |
| } |
| @@ -77,6 +109,12 @@ bool ChromeSigninClient::SettingsAllowSigninCookies( |
| cookie_settings->IsSettingCookieAllowed(google_url, google_url); |
| } |
| +std::string ChromeSigninClient::GenerateSigninScopedDeviceID( |
|
Roger Tawa OOO till Jul 10th
2015/05/15 13:50:23
nit: please add "// static" comment
dzhioev (left Google)
2015/05/15 20:05:38
Done.
|
| + bool for_ephemeral) { |
| + std::string guid = base::GenerateGUID(); |
| + return for_ephemeral ? kEphemeralUserDeviceIDPrefix + guid : guid; |
| +} |
| + |
| PrefService* ChromeSigninClient::GetPrefs() { return profile_->GetPrefs(); } |
| scoped_refptr<TokenWebData> ChromeSigninClient::GetDatabase() { |
| @@ -113,6 +151,7 @@ std::string ChromeSigninClient::GetSigninScopedDeviceId() { |
| return std::string(); |
| } |
| +#if !defined(OS_CHROMEOS) |
| std::string signin_scoped_device_id = |
| GetPrefs()->GetString(prefs::kGoogleServicesSigninScopedDeviceId); |
| if (signin_scoped_device_id.empty()) { |
| @@ -123,6 +162,22 @@ std::string ChromeSigninClient::GetSigninScopedDeviceId() { |
| signin_scoped_device_id); |
| } |
| return signin_scoped_device_id; |
| +#else |
| + // UserManager may not exist in unit_tests. |
| + if (!user_manager::UserManager::IsInitialized()) |
| + return std::string(); |
| + |
| + const user_manager::User* user = |
| + chromeos::ProfileHelper::Get()->GetUserByProfile(profile_); |
| + if (!user) |
| + return std::string(); |
| + |
| + const std::string signin_scoped_device_id = |
| + user_manager::UserManager::Get()->GetKnownUserDeviceId(user->GetUserID()); |
| + LOG_IF(ERROR, signin_scoped_device_id.empty()) |
| + << "Device ID is not set for user."; |
| + return signin_scoped_device_id; |
| +#endif |
|
Roger Tawa OOO till Jul 10th
2015/05/15 13:50:24
This has to be done for desktop too. Desktop's pr
|
| } |
| void ChromeSigninClient::OnSignedOut() { |