| 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 "components/signin/core/browser/signin_client.h" | 5 #include "components/signin/core/browser/signin_client.h" |
| 6 | 6 |
| 7 #include "base/guid.h" | 7 #include "base/guid.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/prefs/pref_service.h" | 9 #include "components/prefs/pref_service.h" |
| 10 #include "components/signin/core/common/signin_pref_names.h" | 10 #include "components/signin/core/common/signin_pref_names.h" |
| 11 | 11 |
| 12 namespace { | 12 namespace { |
| 13 const char kEphemeralUserDeviceIDPrefix[] = "t_"; | 13 const char kEphemeralUserDeviceIDPrefix[] = "t_"; |
| 14 } | 14 } |
| 15 | 15 |
| 16 // static | 16 // static |
| 17 std::string SigninClient::GenerateSigninScopedDeviceID(bool for_ephemeral) { | 17 std::string SigninClient::GenerateSigninScopedDeviceID(bool for_ephemeral) { |
| 18 std::string guid = base::GenerateGUID(); | 18 std::string guid = base::GenerateGUID(); |
| 19 return for_ephemeral ? kEphemeralUserDeviceIDPrefix + guid : guid; | 19 return for_ephemeral ? kEphemeralUserDeviceIDPrefix + guid : guid; |
| 20 } | 20 } |
| 21 | 21 |
| 22 std::string SigninClient::GetOrCreateScopedDeviceIdPref(PrefService* prefs) { | 22 std::string SigninClient::GetOrCreateScopedDeviceIdPref(PrefService* prefs) { |
| 23 std::string signin_scoped_device_id = | 23 std::string signin_scoped_device_id = |
| 24 prefs->GetString(prefs::kGoogleServicesSigninScopedDeviceId); | 24 prefs->GetString(prefs::kGoogleServicesSigninScopedDeviceId); |
| 25 if (signin_scoped_device_id.empty()) { | 25 if (signin_scoped_device_id.empty()) { |
| 26 // If device_id doesn't exist then generate new and save in prefs. | 26 // If device_id doesn't exist then generate new and save in prefs. |
| 27 signin_scoped_device_id = GenerateSigninScopedDeviceID(false); | 27 signin_scoped_device_id = GenerateSigninScopedDeviceID(false); |
| 28 DCHECK(!signin_scoped_device_id.empty()); | 28 DCHECK(!signin_scoped_device_id.empty()); |
| 29 prefs->SetString(prefs::kGoogleServicesSigninScopedDeviceId, | 29 prefs->SetString(prefs::kGoogleServicesSigninScopedDeviceId, |
| 30 signin_scoped_device_id); | 30 signin_scoped_device_id); |
| 31 } | 31 } |
| 32 return signin_scoped_device_id; | 32 return signin_scoped_device_id; |
| 33 } | 33 } |
| 34 | 34 |
| 35 void SigninClient::SignOut() { | 35 void SigninClient::SignOut() { |
| 36 GetPrefs()->ClearPref(prefs::kGoogleServicesSigninScopedDeviceId); | 36 GetPrefs()->ClearPref(prefs::kGoogleServicesSigninScopedDeviceId); |
| 37 OnSignedOut(); | 37 OnSignedOut(); |
| 38 } | 38 } |
| OLD | NEW |