Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "sync/engine/net/server_connection_manager.h" | 5 #include "sync/engine/net/server_connection_manager.h" |
| 6 | 6 |
| 7 #include <errno.h> | 7 #include <errno.h> |
| 8 | 8 |
| 9 #include <ostream> | 9 #include <ostream> |
| 10 #include <string> | 10 #include <string> |
| (...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 226 active_connection_ = NULL; | 226 active_connection_ = NULL; |
| 227 } | 227 } |
| 228 | 228 |
| 229 bool ServerConnectionManager::SetAuthToken(const std::string& auth_token) { | 229 bool ServerConnectionManager::SetAuthToken(const std::string& auth_token) { |
| 230 DCHECK(thread_checker_.CalledOnValidThread()); | 230 DCHECK(thread_checker_.CalledOnValidThread()); |
| 231 if (previously_invalidated_token != auth_token) { | 231 if (previously_invalidated_token != auth_token) { |
| 232 auth_token_.assign(auth_token); | 232 auth_token_.assign(auth_token); |
| 233 previously_invalidated_token = std::string(); | 233 previously_invalidated_token = std::string(); |
| 234 return true; | 234 return true; |
| 235 } | 235 } |
| 236 | |
| 237 // This could happen in case like server outage/bug. E.g. token returned by | |
| 238 // first request is considered invalid by authentication server and because | |
|
tim (not reviewing)
2013/11/07 22:07:13
invalid by 'sync server' ?
haitaol1
2013/11/08 15:23:03
Done.
| |
| 239 // of token server's caching policy, etc, same token is returned on second | |
| 240 // request. Need to notify sync frontend again to request new token, | |
| 241 // otherwise backend will stay in SYNC_AUTH_ERROR state while fronend thinks | |
|
tim (not reviewing)
2013/11/07 22:07:13
nit - while frontend*
haitaol1
2013/11/08 15:23:03
Done.
| |
| 242 // everything is fine and takes no actions. | |
| 243 SetServerStatus(HttpResponse::SYNC_AUTH_ERROR); | |
| 236 return false; | 244 return false; |
| 237 } | 245 } |
| 238 | 246 |
| 239 void ServerConnectionManager::OnInvalidationCredentialsRejected() { | 247 void ServerConnectionManager::OnInvalidationCredentialsRejected() { |
| 240 InvalidateAndClearAuthToken(); | 248 InvalidateAndClearAuthToken(); |
| 241 SetServerStatus(HttpResponse::SYNC_AUTH_ERROR); | 249 SetServerStatus(HttpResponse::SYNC_AUTH_ERROR); |
| 242 } | 250 } |
| 243 | 251 |
| 244 void ServerConnectionManager::InvalidateAndClearAuthToken() { | 252 void ServerConnectionManager::InvalidateAndClearAuthToken() { |
| 245 DCHECK(thread_checker_.CalledOnValidThread()); | 253 DCHECK(thread_checker_.CalledOnValidThread()); |
| 246 // Copy over the token to previous invalid token. | 254 // Copy over the token to previous invalid token. |
| 247 if (!auth_token_.empty()) { | 255 if (!auth_token_.empty()) { |
| 248 previously_invalidated_token.assign(auth_token_); | 256 previously_invalidated_token.assign(auth_token_); |
| 249 auth_token_ = std::string(); | 257 auth_token_ = std::string(); |
| 250 } | 258 } |
| 251 } | 259 } |
| 252 | 260 |
| 253 void ServerConnectionManager::SetServerStatus( | 261 void ServerConnectionManager::SetServerStatus( |
| 254 HttpResponse::ServerConnectionCode server_status) { | 262 HttpResponse::ServerConnectionCode server_status) { |
| 255 if (server_status_ == server_status) | 263 // SYNC_AUTH_ERROR is permanent error. Need to notify observer to take |
| 264 // action externally to resolve. | |
| 265 if (server_status != HttpResponse::SYNC_AUTH_ERROR && | |
| 266 server_status_ == server_status) { | |
| 256 return; | 267 return; |
| 268 } | |
| 257 server_status_ = server_status; | 269 server_status_ = server_status; |
| 258 NotifyStatusChanged(); | 270 NotifyStatusChanged(); |
| 259 } | 271 } |
| 260 | 272 |
| 261 void ServerConnectionManager::NotifyStatusChanged() { | 273 void ServerConnectionManager::NotifyStatusChanged() { |
| 262 DCHECK(thread_checker_.CalledOnValidThread()); | 274 DCHECK(thread_checker_.CalledOnValidThread()); |
| 263 FOR_EACH_OBSERVER(ServerConnectionEventListener, listeners_, | 275 FOR_EACH_OBSERVER(ServerConnectionEventListener, listeners_, |
| 264 OnServerConnectionEvent( | 276 OnServerConnectionEvent( |
| 265 ServerConnectionEvent(server_status_))); | 277 ServerConnectionEvent(server_status_))); |
| 266 } | 278 } |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 373 | 385 |
| 374 std::ostream& operator << (std::ostream& s, const struct HttpResponse& hr) { | 386 std::ostream& operator << (std::ostream& s, const struct HttpResponse& hr) { |
| 375 s << " Response Code (bogus on error): " << hr.response_code; | 387 s << " Response Code (bogus on error): " << hr.response_code; |
| 376 s << " Content-Length (bogus on error): " << hr.content_length; | 388 s << " Content-Length (bogus on error): " << hr.content_length; |
| 377 s << " Server Status: " | 389 s << " Server Status: " |
| 378 << HttpResponse::GetServerConnectionCodeString(hr.server_status); | 390 << HttpResponse::GetServerConnectionCodeString(hr.server_status); |
| 379 return s; | 391 return s; |
| 380 } | 392 } |
| 381 | 393 |
| 382 } // namespace syncer | 394 } // namespace syncer |
| OLD | NEW |