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 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
156 } | 156 } |
157 | 157 |
158 int ServerConnectionManager::Connection::ReadResponse(string* out_buffer, | 158 int ServerConnectionManager::Connection::ReadResponse(string* out_buffer, |
159 int length) { | 159 int length) { |
160 int bytes_read = buffer_.length(); | 160 int bytes_read = buffer_.length(); |
161 CHECK(length <= bytes_read); | 161 CHECK(length <= bytes_read); |
162 out_buffer->assign(buffer_); | 162 out_buffer->assign(buffer_); |
163 return bytes_read; | 163 return bytes_read; |
164 } | 164 } |
165 | 165 |
166 ScopedServerStatusWatcher::ScopedServerStatusWatcher( | |
167 ServerConnectionManager* conn_mgr, HttpResponse* response) | |
168 : conn_mgr_(conn_mgr), | |
169 response_(response) { | |
170 response->server_status = conn_mgr->server_status_; | |
171 } | |
172 | |
173 ScopedServerStatusWatcher::~ScopedServerStatusWatcher() { | |
174 conn_mgr_->SetServerStatus(response_->server_status); | |
175 } | |
176 | |
177 ServerConnectionManager::ServerConnectionManager( | 166 ServerConnectionManager::ServerConnectionManager( |
178 const string& server, | 167 const string& server, |
179 int port, | 168 int port, |
180 bool use_ssl, | 169 bool use_ssl, |
181 CancelationSignal* cancelation_signal) | 170 CancelationSignal* cancelation_signal) |
182 : sync_server_(server), | 171 : sync_server_(server), |
183 sync_server_port_(port), | 172 sync_server_port_(port), |
184 use_ssl_(use_ssl), | 173 use_ssl_(use_ssl), |
185 proto_sync_path_(kSyncServerSyncPath), | 174 proto_sync_path_(kSyncServerSyncPath), |
186 server_status_(HttpResponse::NONE), | 175 server_status_(HttpResponse::NONE), |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
266 } | 255 } |
267 | 256 |
268 void ServerConnectionManager::NotifyStatusChanged() { | 257 void ServerConnectionManager::NotifyStatusChanged() { |
269 DCHECK(thread_checker_.CalledOnValidThread()); | 258 DCHECK(thread_checker_.CalledOnValidThread()); |
270 FOR_EACH_OBSERVER(ServerConnectionEventListener, listeners_, | 259 FOR_EACH_OBSERVER(ServerConnectionEventListener, listeners_, |
271 OnServerConnectionEvent( | 260 OnServerConnectionEvent( |
272 ServerConnectionEvent(server_status_))); | 261 ServerConnectionEvent(server_status_))); |
273 } | 262 } |
274 | 263 |
275 bool ServerConnectionManager::PostBufferWithCachedAuth( | 264 bool ServerConnectionManager::PostBufferWithCachedAuth( |
276 PostBufferParams* params, ScopedServerStatusWatcher* watcher) { | 265 PostBufferParams* params) { |
277 DCHECK(thread_checker_.CalledOnValidThread()); | 266 DCHECK(thread_checker_.CalledOnValidThread()); |
278 string path = | 267 string path = |
279 MakeSyncServerPath(proto_sync_path(), MakeSyncQueryString(client_id_)); | 268 MakeSyncServerPath(proto_sync_path(), MakeSyncQueryString(client_id_)); |
280 return PostBufferToPath(params, path, auth_token(), watcher); | 269 bool result = PostBufferToPath(params, path, auth_token()); |
| 270 SetServerStatus(params->response.server_status); |
| 271 return result; |
281 } | 272 } |
282 | 273 |
283 bool ServerConnectionManager::PostBufferToPath(PostBufferParams* params, | 274 bool ServerConnectionManager::PostBufferToPath(PostBufferParams* params, |
284 const string& path, const string& auth_token, | 275 const string& path, |
285 ScopedServerStatusWatcher* watcher) { | 276 const string& auth_token) { |
286 DCHECK(thread_checker_.CalledOnValidThread()); | 277 DCHECK(thread_checker_.CalledOnValidThread()); |
287 DCHECK(watcher != NULL); | |
288 | 278 |
289 // TODO(pavely): crbug.com/273096. Check for "credentials_lost" is added as | 279 // TODO(pavely): crbug.com/273096. Check for "credentials_lost" is added as |
290 // workaround for M29 blocker to avoid sending RPC to sync with known invalid | 280 // workaround for M29 blocker to avoid sending RPC to sync with known invalid |
291 // token but instead to trigger refreshing token in ProfileSyncService. Need | 281 // token but instead to trigger refreshing token in ProfileSyncService. Need |
292 // to clean it. | 282 // to clean it. |
293 if (auth_token.empty() || auth_token == "credentials_lost") { | 283 if (auth_token.empty() || auth_token == "credentials_lost") { |
294 params->response.server_status = HttpResponse::SYNC_AUTH_ERROR; | 284 params->response.server_status = HttpResponse::SYNC_AUTH_ERROR; |
295 // Print a log to distinguish this "known failure" from others. | 285 // Print a log to distinguish this "known failure" from others. |
296 LOG(WARNING) << "ServerConnectionManager forcing SYNC_AUTH_ERROR"; | 286 LOG(WARNING) << "ServerConnectionManager forcing SYNC_AUTH_ERROR"; |
297 return false; | 287 return false; |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
357 DCHECK(thread_checker_.CalledOnValidThread()); | 347 DCHECK(thread_checker_.CalledOnValidThread()); |
358 listeners_.AddObserver(listener); | 348 listeners_.AddObserver(listener); |
359 } | 349 } |
360 | 350 |
361 void ServerConnectionManager::RemoveListener( | 351 void ServerConnectionManager::RemoveListener( |
362 ServerConnectionEventListener* listener) { | 352 ServerConnectionEventListener* listener) { |
363 DCHECK(thread_checker_.CalledOnValidThread()); | 353 DCHECK(thread_checker_.CalledOnValidThread()); |
364 listeners_.RemoveObserver(listener); | 354 listeners_.RemoveObserver(listener); |
365 } | 355 } |
366 | 356 |
367 ServerConnectionManager::Connection* ServerConnectionManager::MakeConnection() | 357 ServerConnectionManager::Connection* ServerConnectionManager::MakeConnection() { |
368 { | |
369 return NULL; // For testing. | 358 return NULL; // For testing. |
370 } | 359 } |
371 | 360 |
372 void ServerConnectionManager::OnSignalReceived() { | 361 void ServerConnectionManager::OnSignalReceived() { |
373 base::AutoLock lock(terminate_connection_lock_); | 362 base::AutoLock lock(terminate_connection_lock_); |
374 terminated_ = true; | 363 terminated_ = true; |
375 if (active_connection_) | 364 if (active_connection_) |
376 active_connection_->Abort(); | 365 active_connection_->Abort(); |
377 | 366 |
378 // Sever our ties to this connection object. Note that it still may exist, | 367 // Sever our ties to this connection object. Note that it still may exist, |
379 // since we don't own it, but it has been neutered. | 368 // since we don't own it, but it has been neutered. |
380 active_connection_ = NULL; | 369 active_connection_ = NULL; |
381 } | 370 } |
382 | 371 |
383 std::ostream& operator << (std::ostream& s, const struct HttpResponse& hr) { | 372 std::ostream& operator << (std::ostream& s, const struct HttpResponse& hr) { |
384 s << " Response Code (bogus on error): " << hr.response_code; | 373 s << " Response Code (bogus on error): " << hr.response_code; |
385 s << " Content-Length (bogus on error): " << hr.content_length; | 374 s << " Content-Length (bogus on error): " << hr.content_length; |
386 s << " Server Status: " | 375 s << " Server Status: " |
387 << HttpResponse::GetServerConnectionCodeString(hr.server_status); | 376 << HttpResponse::GetServerConnectionCodeString(hr.server_status); |
388 return s; | 377 return s; |
389 } | 378 } |
390 | 379 |
391 } // namespace syncer | 380 } // namespace syncer |
OLD | NEW |