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 | |
guohui
2014/10/07 04:06:03
nits: i think the chromium code style is to have o
Roger Tawa OOO till Jul 10th
2014/10/07 21:38:30
Done.
| |
91 : gaia::CanonicalizeEmail(gaia::SanitizeEmail(username)); | |
94 client_->GetPrefs()->SetString(prefs::kGoogleServicesUsername, username); | 92 client_->GetPrefs()->SetString(prefs::kGoogleServicesUsername, username); |
95 NotifyDiagnosticsObservers(USERNAME, username); | 93 NotifyDiagnosticsObservers(USERNAME, username); |
96 | 94 |
97 // Go ahead and update the last signed in username here as well. Once a | 95 // 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 | 96 // 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. | 97 // opposed to on signin allows us to catch the upgrade scenario. |
100 client_->GetPrefs()->SetString(prefs::kGoogleServicesLastUsername, username); | 98 client_->GetPrefs()->SetString(prefs::kGoogleServicesLastUsername, username); |
101 } | 99 } |
102 | 100 |
103 void SigninManagerBase::clear_authenticated_username() { | 101 void SigninManagerBase::ClearAuthenticatedUsername() { |
104 authenticated_username_.clear(); | 102 authenticated_username_.clear(); |
103 authenticated_account_id_.clear(); | |
105 } | 104 } |
106 | 105 |
107 bool SigninManagerBase::IsAuthenticated() const { | 106 bool SigninManagerBase::IsAuthenticated() const { |
108 return !GetAuthenticatedAccountId().empty(); | 107 return !authenticated_account_id_.empty(); |
109 } | 108 } |
110 | 109 |
111 bool SigninManagerBase::AuthInProgress() const { | 110 bool SigninManagerBase::AuthInProgress() const { |
112 // SigninManagerBase never kicks off auth processes itself. | 111 // SigninManagerBase never kicks off auth processes itself. |
113 return false; | 112 return false; |
114 } | 113 } |
115 | 114 |
116 void SigninManagerBase::Shutdown() {} | 115 void SigninManagerBase::Shutdown() {} |
117 | 116 |
118 void SigninManagerBase::AddObserver(Observer* observer) { | 117 void SigninManagerBase::AddObserver(Observer* observer) { |
(...skipping 22 matching lines...) Expand all Loading... | |
141 NotifySigninValueChanged(field, value)); | 140 NotifySigninValueChanged(field, value)); |
142 } | 141 } |
143 | 142 |
144 void SigninManagerBase::NotifyDiagnosticsObservers( | 143 void SigninManagerBase::NotifyDiagnosticsObservers( |
145 const TimedSigninStatusField& field, | 144 const TimedSigninStatusField& field, |
146 const std::string& value) { | 145 const std::string& value) { |
147 FOR_EACH_OBSERVER(SigninDiagnosticsObserver, | 146 FOR_EACH_OBSERVER(SigninDiagnosticsObserver, |
148 signin_diagnostics_observers_, | 147 signin_diagnostics_observers_, |
149 NotifySigninValueChanged(field, value)); | 148 NotifySigninValueChanged(field, value)); |
150 } | 149 } |
OLD | NEW |