| OLD | NEW |
| 1 // Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2009 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/sync/engine/auth_watcher.h" | 5 #include "chrome/browser/sync/engine/auth_watcher.h" |
| 6 | 6 |
| 7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
| 8 #include "base/string_util.h" | 8 #include "base/string_util.h" |
| 9 #include "chrome/browser/sync/engine/all_status.h" | 9 #include "chrome/browser/sync/engine/all_status.h" |
| 10 #include "chrome/browser/sync/engine/authenticator.h" | 10 #include "chrome/browser/sync/engine/authenticator.h" |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 101 &AuthWatcher::DoAuthenticateWithToken, gaia_email, auth_token)); | 101 &AuthWatcher::DoAuthenticateWithToken, gaia_email, auth_token)); |
| 102 } | 102 } |
| 103 | 103 |
| 104 void AuthWatcher::DoAuthenticateWithToken(const std::string& gaia_email, | 104 void AuthWatcher::DoAuthenticateWithToken(const std::string& gaia_email, |
| 105 const std::string& auth_token) { | 105 const std::string& auth_token) { |
| 106 DCHECK_EQ(MessageLoop::current(), message_loop()); | 106 DCHECK_EQ(MessageLoop::current(), message_loop()); |
| 107 | 107 |
| 108 Authenticator auth(scm_, user_settings_); | 108 Authenticator auth(scm_, user_settings_); |
| 109 Authenticator::AuthenticationResult result = | 109 Authenticator::AuthenticationResult result = |
| 110 auth.AuthenticateToken(auth_token); | 110 auth.AuthenticateToken(auth_token); |
| 111 string email = gaia_email; | |
| 112 if (auth.display_email() && *auth.display_email()) { | |
| 113 email = auth.display_email(); | |
| 114 LOG(INFO) << "Auth returned email " << email << " for gaia email " << | |
| 115 gaia_email; | |
| 116 } | |
| 117 AuthWatcherEvent event = {AuthWatcherEvent::ILLEGAL_VALUE , 0}; | 111 AuthWatcherEvent event = {AuthWatcherEvent::ILLEGAL_VALUE , 0}; |
| 118 gaia_->SetUsername(email); | 112 gaia_->SetUsername(gaia_email); |
| 119 gaia_->SetAuthToken(auth_token, SAVE_IN_MEMORY_ONLY); | 113 gaia_->SetAuthToken(auth_token, SAVE_IN_MEMORY_ONLY); |
| 120 const bool was_authenticated = NOT_AUTHENTICATED != status_; | 114 const bool was_authenticated = NOT_AUTHENTICATED != status_; |
| 121 switch (result) { | 115 switch (result) { |
| 122 case Authenticator::SUCCESS: | 116 case Authenticator::SUCCESS: |
| 123 { | 117 { |
| 124 status_ = GAIA_AUTHENTICATED; | 118 status_ = GAIA_AUTHENTICATED; |
| 125 PathString share_name; | 119 PathString share_name; |
| 126 CHECK(AppendUTF8ToPathString(email.data(), email.size(), &share_name)); | 120 CHECK(AppendUTF8ToPathString(gaia_email.data(), gaia_email.size(), |
| 127 user_settings_->SwitchUser(email); | 121 &share_name)); |
| 122 user_settings_->SwitchUser(gaia_email); |
| 128 | 123 |
| 129 // Set the authentication token for notifications | 124 // Set the authentication token for notifications |
| 130 talk_mediator_->SetAuthToken(email, auth_token); | 125 talk_mediator_->SetAuthToken(gaia_email, auth_token); |
| 131 scm_->set_auth_token(auth_token); | 126 scm_->set_auth_token(auth_token); |
| 132 | 127 |
| 133 if (!was_authenticated) | 128 if (!was_authenticated) |
| 134 LoadDirectoryListAndOpen(share_name); | 129 LoadDirectoryListAndOpen(share_name); |
| 135 NotifyAuthSucceeded(email); | 130 NotifyAuthSucceeded(gaia_email); |
| 136 return; | 131 return; |
| 137 } | 132 } |
| 138 case Authenticator::BAD_AUTH_TOKEN: | 133 case Authenticator::BAD_AUTH_TOKEN: |
| 139 event.what_happened = AuthWatcherEvent::SERVICE_AUTH_FAILED; | 134 event.what_happened = AuthWatcherEvent::SERVICE_AUTH_FAILED; |
| 140 break; | 135 break; |
| 141 case Authenticator::CORRUPT_SERVER_RESPONSE: | 136 case Authenticator::CORRUPT_SERVER_RESPONSE: |
| 142 case Authenticator::SERVICE_DOWN: | 137 case Authenticator::SERVICE_DOWN: |
| 143 event.what_happened = AuthWatcherEvent::SERVICE_CONNECTION_FAILED; | 138 event.what_happened = AuthWatcherEvent::SERVICE_CONNECTION_FAILED; |
| 144 break; | 139 break; |
| 145 case Authenticator::USER_NOT_ACTIVATED: | 140 case Authenticator::USER_NOT_ACTIVATED: |
| 146 event.what_happened = AuthWatcherEvent::SERVICE_USER_NOT_SIGNED_UP; | 141 event.what_happened = AuthWatcherEvent::SERVICE_USER_NOT_SIGNED_UP; |
| 147 break; | 142 break; |
| 148 default: | 143 default: |
| 149 LOG(FATAL) << "Illegal return from AuthenticateToken"; | 144 LOG(FATAL) << "Illegal return from AuthenticateToken"; |
| 150 return; | 145 return; |
| 151 } | 146 } |
| 152 // Always fall back to local authentication. | 147 // Always fall back to local authentication. |
| 153 if (was_authenticated || AuthenticateLocally(email)) { | 148 if (was_authenticated || AuthenticateLocally(gaia_email)) { |
| 154 if (AuthWatcherEvent::SERVICE_CONNECTION_FAILED == event.what_happened) | 149 if (AuthWatcherEvent::SERVICE_CONNECTION_FAILED == event.what_happened) |
| 155 return; | 150 return; |
| 156 } | 151 } |
| 157 DCHECK_NE(event.what_happened, AuthWatcherEvent::ILLEGAL_VALUE); | 152 DCHECK_NE(event.what_happened, AuthWatcherEvent::ILLEGAL_VALUE); |
| 158 NotifyListeners(&event); | 153 NotifyListeners(&event); |
| 159 } | 154 } |
| 160 | 155 |
| 161 bool AuthWatcher::AuthenticateLocally(string email) { | 156 bool AuthWatcher::AuthenticateLocally(string email) { |
| 162 DCHECK_EQ(MessageLoop::current(), message_loop()); | 157 DCHECK_EQ(MessageLoop::current(), message_loop()); |
| 163 user_settings_->GetEmailForSignin(&email); | 158 user_settings_->GetEmailForSignin(&email); |
| (...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 329 string AuthWatcher::email() const { | 324 string AuthWatcher::email() const { |
| 330 return gaia_->email(); | 325 return gaia_->email(); |
| 331 } | 326 } |
| 332 | 327 |
| 333 void AuthWatcher::NotifyListeners(AuthWatcherEvent* event) { | 328 void AuthWatcher::NotifyListeners(AuthWatcherEvent* event) { |
| 334 event->trigger = current_attempt_trigger_; | 329 event->trigger = current_attempt_trigger_; |
| 335 channel_->NotifyListeners(*event); | 330 channel_->NotifyListeners(*event); |
| 336 } | 331 } |
| 337 | 332 |
| 338 } // namespace browser_sync | 333 } // namespace browser_sync |
| OLD | NEW |