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

Side by Side Diff: sync/engine/net/server_connection_manager.cc

Issue 23717047: Retry: sync: Gracefully handle early shutdown (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Renames Created 7 years, 3 months 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 | « sync/engine/net/server_connection_manager.h ('k') | sync/engine/sync_scheduler.h » ('j') | 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) 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>
11 #include <vector> 11 #include <vector>
12 12
13 #include "base/metrics/histogram.h" 13 #include "base/metrics/histogram.h"
14 #include "build/build_config.h" 14 #include "build/build_config.h"
15 #include "net/base/net_errors.h" 15 #include "net/base/net_errors.h"
16 #include "net/http/http_status_code.h" 16 #include "net/http/http_status_code.h"
17 #include "sync/engine/net/url_translator.h" 17 #include "sync/engine/net/url_translator.h"
18 #include "sync/engine/syncer.h" 18 #include "sync/engine/syncer.h"
19 #include "sync/internal_api/public/base/cancelation_signal.h"
19 #include "sync/protocol/sync.pb.h" 20 #include "sync/protocol/sync.pb.h"
20 #include "sync/syncable/directory.h" 21 #include "sync/syncable/directory.h"
21 #include "url/gurl.h" 22 #include "url/gurl.h"
22 23
23 namespace syncer { 24 namespace syncer {
24 25
25 using std::ostream; 26 using std::ostream;
26 using std::string; 27 using std::string;
27 using std::vector; 28 using std::vector;
28 29
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
170 } 171 }
171 172
172 ScopedServerStatusWatcher::~ScopedServerStatusWatcher() { 173 ScopedServerStatusWatcher::~ScopedServerStatusWatcher() {
173 conn_mgr_->SetServerStatus(response_->server_status); 174 conn_mgr_->SetServerStatus(response_->server_status);
174 } 175 }
175 176
176 ServerConnectionManager::ServerConnectionManager( 177 ServerConnectionManager::ServerConnectionManager(
177 const string& server, 178 const string& server,
178 int port, 179 int port,
179 bool use_ssl, 180 bool use_ssl,
180 bool use_oauth2_token) 181 bool use_oauth2_token,
182 CancelationSignal* cancelation_signal)
181 : sync_server_(server), 183 : sync_server_(server),
182 sync_server_port_(port), 184 sync_server_port_(port),
183 use_ssl_(use_ssl), 185 use_ssl_(use_ssl),
184 use_oauth2_token_(use_oauth2_token), 186 use_oauth2_token_(use_oauth2_token),
185 proto_sync_path_(kSyncServerSyncPath), 187 proto_sync_path_(kSyncServerSyncPath),
186 server_status_(HttpResponse::NONE), 188 server_status_(HttpResponse::NONE),
187 terminated_(false), 189 terminated_(false),
188 active_connection_(NULL) { 190 active_connection_(NULL),
191 cancelation_signal_(cancelation_signal),
192 signal_handler_registered_(false) {
193 signal_handler_registered_ = cancelation_signal_->TryRegisterHandler(this);
194 if (!signal_handler_registered_) {
195 // Calling a virtual function from a constructor. We can get away with it
196 // here because ServerConnectionManager::OnSignalReceived() is the function
197 // we want to call.
198 OnSignalReceived();
199 }
189 } 200 }
190 201
191 ServerConnectionManager::~ServerConnectionManager() { 202 ServerConnectionManager::~ServerConnectionManager() {
203 if (signal_handler_registered_) {
204 cancelation_signal_->UnregisterHandler(this);
205 }
192 } 206 }
193 207
194 ServerConnectionManager::Connection* 208 ServerConnectionManager::Connection*
195 ServerConnectionManager::MakeActiveConnection() { 209 ServerConnectionManager::MakeActiveConnection() {
196 base::AutoLock lock(terminate_connection_lock_); 210 base::AutoLock lock(terminate_connection_lock_);
197 DCHECK(!active_connection_); 211 DCHECK(!active_connection_);
198 if (terminated_) 212 if (terminated_)
199 return NULL; 213 return NULL;
200 214
201 active_connection_ = MakeConnection(); 215 active_connection_ = MakeConnection();
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
341 ServerConnectionEventListener* listener) { 355 ServerConnectionEventListener* listener) {
342 DCHECK(thread_checker_.CalledOnValidThread()); 356 DCHECK(thread_checker_.CalledOnValidThread());
343 listeners_.RemoveObserver(listener); 357 listeners_.RemoveObserver(listener);
344 } 358 }
345 359
346 ServerConnectionManager::Connection* ServerConnectionManager::MakeConnection() 360 ServerConnectionManager::Connection* ServerConnectionManager::MakeConnection()
347 { 361 {
348 return NULL; // For testing. 362 return NULL; // For testing.
349 } 363 }
350 364
351 void ServerConnectionManager::TerminateAllIO() { 365 void ServerConnectionManager::OnSignalReceived() {
352 base::AutoLock lock(terminate_connection_lock_); 366 base::AutoLock lock(terminate_connection_lock_);
353 terminated_ = true; 367 terminated_ = true;
354 if (active_connection_) 368 if (active_connection_)
355 active_connection_->Abort(); 369 active_connection_->Abort();
356 370
357 // Sever our ties to this connection object. Note that it still may exist, 371 // Sever our ties to this connection object. Note that it still may exist,
358 // since we don't own it, but it has been neutered. 372 // since we don't own it, but it has been neutered.
359 active_connection_ = NULL; 373 active_connection_ = NULL;
360 } 374 }
361 375
362 std::ostream& operator << (std::ostream& s, const struct HttpResponse& hr) { 376 std::ostream& operator << (std::ostream& s, const struct HttpResponse& hr) {
363 s << " Response Code (bogus on error): " << hr.response_code; 377 s << " Response Code (bogus on error): " << hr.response_code;
364 s << " Content-Length (bogus on error): " << hr.content_length; 378 s << " Content-Length (bogus on error): " << hr.content_length;
365 s << " Server Status: " 379 s << " Server Status: "
366 << HttpResponse::GetServerConnectionCodeString(hr.server_status); 380 << HttpResponse::GetServerConnectionCodeString(hr.server_status);
367 return s; 381 return s;
368 } 382 }
369 383
370 } // namespace syncer 384 } // namespace syncer
OLDNEW
« no previous file with comments | « sync/engine/net/server_connection_manager.h ('k') | sync/engine/sync_scheduler.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698