Chromium Code Reviews| 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/guid.h" | 8 #include "base/guid.h" |
| 9 #include "base/prefs/pref_service.h" | 9 #include "base/prefs/pref_service.h" |
| 10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 26 #include "google_apis/gaia/gaia_urls.h" | 26 #include "google_apis/gaia/gaia_urls.h" |
| 27 #include "net/url_request/url_request_context_getter.h" | 27 #include "net/url_request/url_request_context_getter.h" |
| 28 #include "url/gurl.h" | 28 #include "url/gurl.h" |
| 29 | 29 |
| 30 #if defined(ENABLE_SUPERVISED_USERS) | 30 #if defined(ENABLE_SUPERVISED_USERS) |
| 31 #include "chrome/browser/supervised_user/supervised_user_constants.h" | 31 #include "chrome/browser/supervised_user/supervised_user_constants.h" |
| 32 #endif | 32 #endif |
| 33 | 33 |
| 34 #if defined(OS_CHROMEOS) | 34 #if defined(OS_CHROMEOS) |
| 35 #include "chrome/browser/chromeos/net/delay_network_call.h" | 35 #include "chrome/browser/chromeos/net/delay_network_call.h" |
| 36 #include "chrome/browser/chromeos/profiles/profile_helper.h" | |
| 36 #include "components/user_manager/user_manager.h" | 37 #include "components/user_manager/user_manager.h" |
| 37 #endif | 38 #endif |
| 38 | 39 |
| 39 #if !defined(OS_ANDROID) | 40 #if !defined(OS_ANDROID) |
| 40 #include "chrome/browser/first_run/first_run.h" | 41 #include "chrome/browser/first_run/first_run.h" |
| 41 #endif | 42 #endif |
| 42 | 43 |
| 44 namespace { | |
| 45 const char kEphemeralUserDeviceIDPrefix[] = "t_"; | |
| 46 } | |
| 47 | |
| 43 ChromeSigninClient::ChromeSigninClient( | 48 ChromeSigninClient::ChromeSigninClient( |
| 44 Profile* profile, SigninErrorController* signin_error_controller) | 49 Profile* profile, SigninErrorController* signin_error_controller) |
| 45 : profile_(profile), | 50 : profile_(profile), |
| 46 signin_error_controller_(signin_error_controller) { | 51 signin_error_controller_(signin_error_controller) { |
| 47 signin_error_controller_->AddObserver(this); | 52 signin_error_controller_->AddObserver(this); |
| 48 #if !defined(OS_CHROMEOS) | 53 #if !defined(OS_CHROMEOS) |
| 49 net::NetworkChangeNotifier::AddNetworkChangeObserver(this); | 54 net::NetworkChangeNotifier::AddNetworkChangeObserver(this); |
| 55 #else | |
| 56 // UserManager may not exist in unit_tests. | |
| 57 if (!user_manager::UserManager::IsInitialized()) | |
| 58 return; | |
| 59 | |
| 60 const user_manager::User* user = | |
| 61 chromeos::ProfileHelper::Get()->GetUserByProfile(profile_); | |
| 62 if (!user) | |
| 63 return; | |
| 64 auto* user_manager = user_manager::UserManager::Get(); | |
| 65 const std::string& user_id = user->GetUserID(); | |
| 66 if (user_manager->GetKnownUserDeviceId(user_id).empty()) { | |
| 67 const std::string legacy_device_id = | |
| 68 GetPrefs()->GetString(prefs::kGoogleServicesSigninScopedDeviceId); | |
| 69 if (!legacy_device_id.empty()) { | |
| 70 // Need to move device ID from the old location to the new one, if it has | |
| 71 // not been done yet. | |
| 72 user_manager->SetKnownUserDeviceId(user_id, legacy_device_id); | |
| 73 } else { | |
| 74 user_manager->SetKnownUserDeviceId( | |
| 75 user_id, | |
| 76 GenerateSigninScopedDeviceID( | |
| 77 user_manager->IsUserNonCryptohomeDataEphemeral(user_id))); | |
| 78 } | |
| 79 } | |
| 80 GetPrefs()->SetString(prefs::kGoogleServicesSigninScopedDeviceId, | |
| 81 std::string()); | |
|
Roger Tawa OOO till Jul 10th
2015/05/15 13:50:23
Why is this cros specific? Desktop needs this too
| |
| 50 #endif | 82 #endif |
| 51 } | 83 } |
| 52 | 84 |
| 53 ChromeSigninClient::~ChromeSigninClient() { | 85 ChromeSigninClient::~ChromeSigninClient() { |
| 54 signin_error_controller_->RemoveObserver(this); | 86 signin_error_controller_->RemoveObserver(this); |
| 55 } | 87 } |
| 56 | 88 |
| 57 void ChromeSigninClient::Shutdown() { | 89 void ChromeSigninClient::Shutdown() { |
| 58 #if !defined(OS_CHROMEOS) | 90 #if !defined(OS_CHROMEOS) |
| 59 net::NetworkChangeNotifier::RemoveNetworkChangeObserver(this); | 91 net::NetworkChangeNotifier::RemoveNetworkChangeObserver(this); |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 70 // static | 102 // static |
| 71 bool ChromeSigninClient::SettingsAllowSigninCookies( | 103 bool ChromeSigninClient::SettingsAllowSigninCookies( |
| 72 CookieSettings* cookie_settings) { | 104 CookieSettings* cookie_settings) { |
| 73 GURL gaia_url = GaiaUrls::GetInstance()->gaia_url(); | 105 GURL gaia_url = GaiaUrls::GetInstance()->gaia_url(); |
| 74 GURL google_url = GaiaUrls::GetInstance()->google_url(); | 106 GURL google_url = GaiaUrls::GetInstance()->google_url(); |
| 75 return cookie_settings && | 107 return cookie_settings && |
| 76 cookie_settings->IsSettingCookieAllowed(gaia_url, gaia_url) && | 108 cookie_settings->IsSettingCookieAllowed(gaia_url, gaia_url) && |
| 77 cookie_settings->IsSettingCookieAllowed(google_url, google_url); | 109 cookie_settings->IsSettingCookieAllowed(google_url, google_url); |
| 78 } | 110 } |
| 79 | 111 |
| 112 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.
| |
| 113 bool for_ephemeral) { | |
| 114 std::string guid = base::GenerateGUID(); | |
| 115 return for_ephemeral ? kEphemeralUserDeviceIDPrefix + guid : guid; | |
| 116 } | |
| 117 | |
| 80 PrefService* ChromeSigninClient::GetPrefs() { return profile_->GetPrefs(); } | 118 PrefService* ChromeSigninClient::GetPrefs() { return profile_->GetPrefs(); } |
| 81 | 119 |
| 82 scoped_refptr<TokenWebData> ChromeSigninClient::GetDatabase() { | 120 scoped_refptr<TokenWebData> ChromeSigninClient::GetDatabase() { |
| 83 return WebDataServiceFactory::GetTokenWebDataForProfile( | 121 return WebDataServiceFactory::GetTokenWebDataForProfile( |
| 84 profile_, ServiceAccessType::EXPLICIT_ACCESS); | 122 profile_, ServiceAccessType::EXPLICIT_ACCESS); |
| 85 } | 123 } |
| 86 | 124 |
| 87 bool ChromeSigninClient::CanRevokeCredentials() { | 125 bool ChromeSigninClient::CanRevokeCredentials() { |
| 88 #if defined(OS_CHROMEOS) | 126 #if defined(OS_CHROMEOS) |
| 89 // UserManager may not exist in unit_tests. | 127 // UserManager may not exist in unit_tests. |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 106 #endif | 144 #endif |
| 107 return true; | 145 return true; |
| 108 } | 146 } |
| 109 | 147 |
| 110 std::string ChromeSigninClient::GetSigninScopedDeviceId() { | 148 std::string ChromeSigninClient::GetSigninScopedDeviceId() { |
| 111 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | 149 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 112 switches::kDisableSigninScopedDeviceId)) { | 150 switches::kDisableSigninScopedDeviceId)) { |
| 113 return std::string(); | 151 return std::string(); |
| 114 } | 152 } |
| 115 | 153 |
| 154 #if !defined(OS_CHROMEOS) | |
| 116 std::string signin_scoped_device_id = | 155 std::string signin_scoped_device_id = |
| 117 GetPrefs()->GetString(prefs::kGoogleServicesSigninScopedDeviceId); | 156 GetPrefs()->GetString(prefs::kGoogleServicesSigninScopedDeviceId); |
| 118 if (signin_scoped_device_id.empty()) { | 157 if (signin_scoped_device_id.empty()) { |
| 119 // If device_id doesn't exist then generate new and save in prefs. | 158 // If device_id doesn't exist then generate new and save in prefs. |
| 120 signin_scoped_device_id = base::GenerateGUID(); | 159 signin_scoped_device_id = base::GenerateGUID(); |
| 121 DCHECK(!signin_scoped_device_id.empty()); | 160 DCHECK(!signin_scoped_device_id.empty()); |
| 122 GetPrefs()->SetString(prefs::kGoogleServicesSigninScopedDeviceId, | 161 GetPrefs()->SetString(prefs::kGoogleServicesSigninScopedDeviceId, |
| 123 signin_scoped_device_id); | 162 signin_scoped_device_id); |
| 124 } | 163 } |
| 125 return signin_scoped_device_id; | 164 return signin_scoped_device_id; |
| 165 #else | |
| 166 // UserManager may not exist in unit_tests. | |
| 167 if (!user_manager::UserManager::IsInitialized()) | |
| 168 return std::string(); | |
| 169 | |
| 170 const user_manager::User* user = | |
| 171 chromeos::ProfileHelper::Get()->GetUserByProfile(profile_); | |
| 172 if (!user) | |
| 173 return std::string(); | |
| 174 | |
| 175 const std::string signin_scoped_device_id = | |
| 176 user_manager::UserManager::Get()->GetKnownUserDeviceId(user->GetUserID()); | |
| 177 LOG_IF(ERROR, signin_scoped_device_id.empty()) | |
| 178 << "Device ID is not set for user."; | |
| 179 return signin_scoped_device_id; | |
| 180 #endif | |
|
Roger Tawa OOO till Jul 10th
2015/05/15 13:50:24
This has to be done for desktop too. Desktop's pr
| |
| 126 } | 181 } |
| 127 | 182 |
| 128 void ChromeSigninClient::OnSignedOut() { | 183 void ChromeSigninClient::OnSignedOut() { |
| 129 GetPrefs()->ClearPref(prefs::kGoogleServicesSigninScopedDeviceId); | 184 GetPrefs()->ClearPref(prefs::kGoogleServicesSigninScopedDeviceId); |
| 130 ProfileInfoCache& cache = | 185 ProfileInfoCache& cache = |
| 131 g_browser_process->profile_manager()->GetProfileInfoCache(); | 186 g_browser_process->profile_manager()->GetProfileInfoCache(); |
| 132 size_t index = cache.GetIndexOfProfileWithPath(profile_->GetPath()); | 187 size_t index = cache.GetIndexOfProfileWithPath(profile_->GetPath()); |
| 133 | 188 |
| 134 // If sign out occurs because Sync setup was in progress and the Profile got | 189 // If sign out occurs because Sync setup was in progress and the Profile got |
| 135 // deleted, then the profile's no longer in the ProfileInfoCache. | 190 // deleted, then the profile's no longer in the ProfileInfoCache. |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 259 return; | 314 return; |
| 260 #else | 315 #else |
| 261 // Don't bother if we don't have any kind of network connection. | 316 // Don't bother if we don't have any kind of network connection. |
| 262 if (net::NetworkChangeNotifier::IsOffline()) { | 317 if (net::NetworkChangeNotifier::IsOffline()) { |
| 263 delayed_callbacks_.push_back(callback); | 318 delayed_callbacks_.push_back(callback); |
| 264 } else { | 319 } else { |
| 265 callback.Run(); | 320 callback.Run(); |
| 266 } | 321 } |
| 267 #endif | 322 #endif |
| 268 } | 323 } |
| OLD | NEW |