Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(371)

Side by Side Diff: chrome/browser/sync/engine/auth_watcher.cc

Issue 392016: This change is patched from http://codereview.chromium.org/276071 by randy.po... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 11 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 }
116 AuthWatcherEvent event = {AuthWatcherEvent::ILLEGAL_VALUE , 0}; 110 AuthWatcherEvent event = {AuthWatcherEvent::ILLEGAL_VALUE , 0};
117 gaia_->SetUsername(email); 111 gaia_->SetUsername(gaia_email);
118 gaia_->SetAuthToken(auth_token, SAVE_IN_MEMORY_ONLY); 112 gaia_->SetAuthToken(auth_token, SAVE_IN_MEMORY_ONLY);
119 const bool was_authenticated = NOT_AUTHENTICATED != status_; 113 const bool was_authenticated = NOT_AUTHENTICATED != status_;
120 switch (result) { 114 switch (result) {
121 case Authenticator::SUCCESS: 115 case Authenticator::SUCCESS:
122 { 116 {
123 status_ = GAIA_AUTHENTICATED; 117 status_ = GAIA_AUTHENTICATED;
124 const PathString& share_name = email; 118 const PathString& share_name = gaia_email;
125 user_settings_->SwitchUser(email); 119 user_settings_->SwitchUser(gaia_email);
126 120
127 // Set the authentication token for notifications 121 // Set the authentication token for notifications
128 talk_mediator_->SetAuthToken(email, auth_token); 122 talk_mediator_->SetAuthToken(gaia_email, auth_token);
129 scm_->set_auth_token(auth_token); 123 scm_->set_auth_token(auth_token);
130 124
131 if (!was_authenticated) 125 if (!was_authenticated)
132 LoadDirectoryListAndOpen(share_name); 126 LoadDirectoryListAndOpen(share_name);
133 NotifyAuthSucceeded(email); 127 NotifyAuthSucceeded(gaia_email);
134 return; 128 return;
135 } 129 }
136 case Authenticator::BAD_AUTH_TOKEN: 130 case Authenticator::BAD_AUTH_TOKEN:
137 event.what_happened = AuthWatcherEvent::SERVICE_AUTH_FAILED; 131 event.what_happened = AuthWatcherEvent::SERVICE_AUTH_FAILED;
138 break; 132 break;
139 case Authenticator::CORRUPT_SERVER_RESPONSE: 133 case Authenticator::CORRUPT_SERVER_RESPONSE:
140 case Authenticator::SERVICE_DOWN: 134 case Authenticator::SERVICE_DOWN:
141 event.what_happened = AuthWatcherEvent::SERVICE_CONNECTION_FAILED; 135 event.what_happened = AuthWatcherEvent::SERVICE_CONNECTION_FAILED;
142 break; 136 break;
143 case Authenticator::USER_NOT_ACTIVATED: 137 case Authenticator::USER_NOT_ACTIVATED:
144 event.what_happened = AuthWatcherEvent::SERVICE_USER_NOT_SIGNED_UP; 138 event.what_happened = AuthWatcherEvent::SERVICE_USER_NOT_SIGNED_UP;
145 break; 139 break;
146 default: 140 default:
147 LOG(FATAL) << "Illegal return from AuthenticateToken"; 141 LOG(FATAL) << "Illegal return from AuthenticateToken";
148 return; 142 return;
149 } 143 }
150 // Always fall back to local authentication. 144 // Always fall back to local authentication.
151 if (was_authenticated || AuthenticateLocally(email)) { 145 if (was_authenticated || AuthenticateLocally(gaia_email)) {
152 if (AuthWatcherEvent::SERVICE_CONNECTION_FAILED == event.what_happened) 146 if (AuthWatcherEvent::SERVICE_CONNECTION_FAILED == event.what_happened)
153 return; 147 return;
154 } 148 }
155 DCHECK_NE(event.what_happened, AuthWatcherEvent::ILLEGAL_VALUE); 149 DCHECK_NE(event.what_happened, AuthWatcherEvent::ILLEGAL_VALUE);
156 NotifyListeners(&event); 150 NotifyListeners(&event);
157 } 151 }
158 152
159 bool AuthWatcher::AuthenticateLocally(string email) { 153 bool AuthWatcher::AuthenticateLocally(string email) {
160 DCHECK_EQ(MessageLoop::current(), message_loop()); 154 DCHECK_EQ(MessageLoop::current(), message_loop());
161 user_settings_->GetEmailForSignin(&email); 155 user_settings_->GetEmailForSignin(&email);
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after
334 string AuthWatcher::email() const { 328 string AuthWatcher::email() const {
335 return gaia_->email(); 329 return gaia_->email();
336 } 330 }
337 331
338 void AuthWatcher::NotifyListeners(AuthWatcherEvent* event) { 332 void AuthWatcher::NotifyListeners(AuthWatcherEvent* event) {
339 event->trigger = current_attempt_trigger_; 333 event->trigger = current_attempt_trigger_;
340 channel_->NotifyListeners(*event); 334 channel_->NotifyListeners(*event);
341 } 335 }
342 336
343 } // namespace browser_sync 337 } // namespace browser_sync
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698