| 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 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 100 &AuthWatcher::DoAuthenticateWithToken, gaia_email, auth_token)); | 100 &AuthWatcher::DoAuthenticateWithToken, gaia_email, auth_token)); |
| 101 } | 101 } |
| 102 | 102 |
| 103 void AuthWatcher::DoAuthenticateWithToken(const std::string& gaia_email, | 103 void AuthWatcher::DoAuthenticateWithToken(const std::string& gaia_email, |
| 104 const std::string& auth_token) { | 104 const std::string& auth_token) { |
| 105 DCHECK_EQ(MessageLoop::current(), message_loop()); | 105 DCHECK_EQ(MessageLoop::current(), message_loop()); |
| 106 | 106 |
| 107 Authenticator auth(scm_, user_settings_); | 107 Authenticator auth(scm_, user_settings_); |
| 108 Authenticator::AuthenticationResult result = | 108 Authenticator::AuthenticationResult result = |
| 109 auth.AuthenticateToken(auth_token); | 109 auth.AuthenticateToken(auth_token); |
| 110 string email = gaia_email; |
| 111 if (auth.display_email() && *auth.display_email()) { |
| 112 email = auth.display_email(); |
| 113 LOG(INFO) << "Auth returned email " << email << " for gaia email " << |
| 114 gaia_email; |
| 115 } |
| 110 AuthWatcherEvent event = {AuthWatcherEvent::ILLEGAL_VALUE , 0}; | 116 AuthWatcherEvent event = {AuthWatcherEvent::ILLEGAL_VALUE , 0}; |
| 111 gaia_->SetUsername(gaia_email); | 117 gaia_->SetUsername(email); |
| 112 gaia_->SetAuthToken(auth_token, SAVE_IN_MEMORY_ONLY); | 118 gaia_->SetAuthToken(auth_token, SAVE_IN_MEMORY_ONLY); |
| 113 const bool was_authenticated = NOT_AUTHENTICATED != status_; | 119 const bool was_authenticated = NOT_AUTHENTICATED != status_; |
| 114 switch (result) { | 120 switch (result) { |
| 115 case Authenticator::SUCCESS: | 121 case Authenticator::SUCCESS: |
| 116 { | 122 { |
| 117 status_ = GAIA_AUTHENTICATED; | 123 status_ = GAIA_AUTHENTICATED; |
| 118 const PathString& share_name = gaia_email; | 124 const PathString& share_name = email; |
| 119 user_settings_->SwitchUser(gaia_email); | 125 user_settings_->SwitchUser(email); |
| 120 | 126 |
| 121 // Set the authentication token for notifications | 127 // Set the authentication token for notifications |
| 122 talk_mediator_->SetAuthToken(gaia_email, auth_token); | 128 talk_mediator_->SetAuthToken(email, auth_token); |
| 123 scm_->set_auth_token(auth_token); | 129 scm_->set_auth_token(auth_token); |
| 124 | 130 |
| 125 if (!was_authenticated) | 131 if (!was_authenticated) |
| 126 LoadDirectoryListAndOpen(share_name); | 132 LoadDirectoryListAndOpen(share_name); |
| 127 NotifyAuthSucceeded(gaia_email); | 133 NotifyAuthSucceeded(email); |
| 128 return; | 134 return; |
| 129 } | 135 } |
| 130 case Authenticator::BAD_AUTH_TOKEN: | 136 case Authenticator::BAD_AUTH_TOKEN: |
| 131 event.what_happened = AuthWatcherEvent::SERVICE_AUTH_FAILED; | 137 event.what_happened = AuthWatcherEvent::SERVICE_AUTH_FAILED; |
| 132 break; | 138 break; |
| 133 case Authenticator::CORRUPT_SERVER_RESPONSE: | 139 case Authenticator::CORRUPT_SERVER_RESPONSE: |
| 134 case Authenticator::SERVICE_DOWN: | 140 case Authenticator::SERVICE_DOWN: |
| 135 event.what_happened = AuthWatcherEvent::SERVICE_CONNECTION_FAILED; | 141 event.what_happened = AuthWatcherEvent::SERVICE_CONNECTION_FAILED; |
| 136 break; | 142 break; |
| 137 case Authenticator::USER_NOT_ACTIVATED: | 143 case Authenticator::USER_NOT_ACTIVATED: |
| 138 event.what_happened = AuthWatcherEvent::SERVICE_USER_NOT_SIGNED_UP; | 144 event.what_happened = AuthWatcherEvent::SERVICE_USER_NOT_SIGNED_UP; |
| 139 break; | 145 break; |
| 140 default: | 146 default: |
| 141 LOG(FATAL) << "Illegal return from AuthenticateToken"; | 147 LOG(FATAL) << "Illegal return from AuthenticateToken"; |
| 142 return; | 148 return; |
| 143 } | 149 } |
| 144 // Always fall back to local authentication. | 150 // Always fall back to local authentication. |
| 145 if (was_authenticated || AuthenticateLocally(gaia_email)) { | 151 if (was_authenticated || AuthenticateLocally(email)) { |
| 146 if (AuthWatcherEvent::SERVICE_CONNECTION_FAILED == event.what_happened) | 152 if (AuthWatcherEvent::SERVICE_CONNECTION_FAILED == event.what_happened) |
| 147 return; | 153 return; |
| 148 } | 154 } |
| 149 DCHECK_NE(event.what_happened, AuthWatcherEvent::ILLEGAL_VALUE); | 155 DCHECK_NE(event.what_happened, AuthWatcherEvent::ILLEGAL_VALUE); |
| 150 NotifyListeners(&event); | 156 NotifyListeners(&event); |
| 151 } | 157 } |
| 152 | 158 |
| 153 bool AuthWatcher::AuthenticateLocally(string email) { | 159 bool AuthWatcher::AuthenticateLocally(string email) { |
| 154 DCHECK_EQ(MessageLoop::current(), message_loop()); | 160 DCHECK_EQ(MessageLoop::current(), message_loop()); |
| 155 user_settings_->GetEmailForSignin(&email); | 161 user_settings_->GetEmailForSignin(&email); |
| (...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 328 string AuthWatcher::email() const { | 334 string AuthWatcher::email() const { |
| 329 return gaia_->email(); | 335 return gaia_->email(); |
| 330 } | 336 } |
| 331 | 337 |
| 332 void AuthWatcher::NotifyListeners(AuthWatcherEvent* event) { | 338 void AuthWatcher::NotifyListeners(AuthWatcherEvent* event) { |
| 333 event->trigger = current_attempt_trigger_; | 339 event->trigger = current_attempt_trigger_; |
| 334 channel_->NotifyListeners(*event); | 340 channel_->NotifyListeners(*event); |
| 335 } | 341 } |
| 336 | 342 |
| 337 } // namespace browser_sync | 343 } // namespace browser_sync |
| OLD | NEW |