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_manager_base.h" | 5 #include "components/signin/core/browser/signin_manager_base.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
(...skipping 23 matching lines...) Expand all Loading... |
34 | 34 |
35 // If the user is clearing the token service from the command line, then | 35 // If the user is clearing the token service from the command line, then |
36 // clear their login info also (not valid to be logged in without any | 36 // clear their login info also (not valid to be logged in without any |
37 // tokens). | 37 // tokens). |
38 CommandLine* cmd_line = CommandLine::ForCurrentProcess(); | 38 CommandLine* cmd_line = CommandLine::ForCurrentProcess(); |
39 if (cmd_line->HasSwitch(switches::kClearTokenService)) | 39 if (cmd_line->HasSwitch(switches::kClearTokenService)) |
40 client_->GetPrefs()->ClearPref(prefs::kGoogleServicesUsername); | 40 client_->GetPrefs()->ClearPref(prefs::kGoogleServicesUsername); |
41 | 41 |
42 std::string user = | 42 std::string user = |
43 client_->GetPrefs()->GetString(prefs::kGoogleServicesUsername); | 43 client_->GetPrefs()->GetString(prefs::kGoogleServicesUsername); |
44 if (!user.empty()) { | 44 if (!user.empty()) |
45 #if defined(OS_IOS) | |
46 // Prior to M38, Chrome on iOS did not normalize the email before setting | |
47 // it in SigninManager. |AccountReconcilor| expects the authenticated email | |
48 // to be normalized as it used as an account identifier and is compared | |
49 // to the accounts available in the cookies. | |
50 user = gaia::CanonicalizeEmail(gaia::SanitizeEmail(user)); | |
51 #endif | |
52 SetAuthenticatedUsername(user); | 45 SetAuthenticatedUsername(user); |
53 } | |
54 } | 46 } |
55 | 47 |
56 bool SigninManagerBase::IsInitialized() const { return initialized_; } | 48 bool SigninManagerBase::IsInitialized() const { return initialized_; } |
57 | 49 |
58 bool SigninManagerBase::IsSigninAllowed() const { | 50 bool SigninManagerBase::IsSigninAllowed() const { |
59 return client_->GetPrefs()->GetBoolean(prefs::kSigninAllowed); | 51 return client_->GetPrefs()->GetBoolean(prefs::kSigninAllowed); |
60 } | 52 } |
61 | 53 |
62 const std::string& SigninManagerBase::GetAuthenticatedUsername() const { | 54 const std::string& SigninManagerBase::GetAuthenticatedUsername() const { |
63 return authenticated_username_; | 55 return authenticated_username_; |
64 } | 56 } |
65 | 57 |
66 const std::string& SigninManagerBase::GetAuthenticatedAccountId() const { | 58 const std::string& SigninManagerBase::GetAuthenticatedAccountId() const { |
67 return GetAuthenticatedUsername(); | 59 return authenticated_account_id_; |
68 } | 60 } |
69 | 61 |
70 void SigninManagerBase::SetAuthenticatedUsername(const std::string& username) { | 62 void SigninManagerBase::SetAuthenticatedUsername(const std::string& username) { |
71 if (!authenticated_username_.empty()) { | 63 if (!authenticated_username_.empty()) { |
72 DLOG_IF(ERROR, !gaia::AreEmailsSame(username, authenticated_username_)) | 64 DLOG_IF(ERROR, !gaia::AreEmailsSame(username, authenticated_username_)) |
73 << "Tried to change the authenticated username to something different: " | 65 << "Tried to change the authenticated username to something different: " |
74 << "Current: " << authenticated_username_ << ", New: " << username; | 66 << "Current: " << authenticated_username_ << ", New: " << username; |
75 | 67 |
76 #if defined(OS_IOS) | 68 #if defined(OS_IOS) |
77 // Prior to M26, chrome on iOS did not normalize the email before setting | 69 // Prior to M26, chrome on iOS did not normalize the email before setting |
78 // it in SigninManager. If the emails are the same as given by | 70 // it in SigninManager. If the emails are the same as given by |
79 // gaia::AreEmailsSame() but not the same as given by std::string::op==(), | 71 // gaia::AreEmailsSame() but not the same as given by std::string::op==(), |
80 // make sure to set the authenticated name below. | 72 // make sure to set the authenticated name below. |
81 if (!gaia::AreEmailsSame(username, authenticated_username_) || | 73 if (!gaia::AreEmailsSame(username, authenticated_username_) || |
82 username == authenticated_username_) { | 74 username == authenticated_username_) { |
83 return; | 75 return; |
84 } | 76 } |
85 #else | 77 #else |
86 return; | 78 return; |
87 #endif | 79 #endif |
88 } | 80 } |
89 std::string pref_username = | 81 std::string pref_username = |
90 client_->GetPrefs()->GetString(prefs::kGoogleServicesUsername); | 82 client_->GetPrefs()->GetString(prefs::kGoogleServicesUsername); |
91 DCHECK(pref_username.empty() || gaia::AreEmailsSame(username, pref_username)) | 83 DCHECK(pref_username.empty() || gaia::AreEmailsSame(username, pref_username)) |
92 << "username: " << username << "; pref_username: " << pref_username; | 84 << "username: " << username << "; pref_username: " << pref_username; |
93 authenticated_username_ = username; | 85 authenticated_username_ = username; |
| 86 |
| 87 // Some tests don't use a real email address for the username. To support |
| 88 // these cases, don't try to canonicalize these strings. |
| 89 authenticated_account_id_ = (username.find('@') == std::string::npos) ? |
| 90 username : gaia::CanonicalizeEmail(username); |
94 client_->GetPrefs()->SetString(prefs::kGoogleServicesUsername, username); | 91 client_->GetPrefs()->SetString(prefs::kGoogleServicesUsername, username); |
95 NotifyDiagnosticsObservers(USERNAME, username); | 92 NotifyDiagnosticsObservers(USERNAME, username); |
96 | 93 |
97 // Go ahead and update the last signed in username here as well. Once a | 94 // Go ahead and update the last signed in username here as well. Once a |
98 // user is signed in the two preferences should match. Doing it here as | 95 // user is signed in the two preferences should match. Doing it here as |
99 // opposed to on signin allows us to catch the upgrade scenario. | 96 // opposed to on signin allows us to catch the upgrade scenario. |
100 client_->GetPrefs()->SetString(prefs::kGoogleServicesLastUsername, username); | 97 client_->GetPrefs()->SetString(prefs::kGoogleServicesLastUsername, username); |
101 } | 98 } |
102 | 99 |
103 void SigninManagerBase::clear_authenticated_username() { | 100 void SigninManagerBase::ClearAuthenticatedUsername() { |
104 authenticated_username_.clear(); | 101 authenticated_username_.clear(); |
| 102 authenticated_account_id_.clear(); |
105 } | 103 } |
106 | 104 |
107 bool SigninManagerBase::IsAuthenticated() const { | 105 bool SigninManagerBase::IsAuthenticated() const { |
108 return !GetAuthenticatedAccountId().empty(); | 106 return !authenticated_account_id_.empty(); |
109 } | 107 } |
110 | 108 |
111 bool SigninManagerBase::AuthInProgress() const { | 109 bool SigninManagerBase::AuthInProgress() const { |
112 // SigninManagerBase never kicks off auth processes itself. | 110 // SigninManagerBase never kicks off auth processes itself. |
113 return false; | 111 return false; |
114 } | 112 } |
115 | 113 |
116 void SigninManagerBase::Shutdown() {} | 114 void SigninManagerBase::Shutdown() {} |
117 | 115 |
118 void SigninManagerBase::AddObserver(Observer* observer) { | 116 void SigninManagerBase::AddObserver(Observer* observer) { |
(...skipping 22 matching lines...) Expand all Loading... |
141 NotifySigninValueChanged(field, value)); | 139 NotifySigninValueChanged(field, value)); |
142 } | 140 } |
143 | 141 |
144 void SigninManagerBase::NotifyDiagnosticsObservers( | 142 void SigninManagerBase::NotifyDiagnosticsObservers( |
145 const TimedSigninStatusField& field, | 143 const TimedSigninStatusField& field, |
146 const std::string& value) { | 144 const std::string& value) { |
147 FOR_EACH_OBSERVER(SigninDiagnosticsObserver, | 145 FOR_EACH_OBSERVER(SigninDiagnosticsObserver, |
148 signin_diagnostics_observers_, | 146 signin_diagnostics_observers_, |
149 NotifySigninValueChanged(field, value)); | 147 NotifySigninValueChanged(field, value)); |
150 } | 148 } |
OLD | NEW |