| 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 "components/sync/engine_impl/net/server_connection_manager.h" | 5 #include "components/sync/engine_impl/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 <vector> | 10 #include <vector> |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 151 const string& server, | 151 const string& server, |
| 152 int port, | 152 int port, |
| 153 bool use_ssl, | 153 bool use_ssl, |
| 154 CancelationSignal* cancelation_signal) | 154 CancelationSignal* cancelation_signal) |
| 155 : sync_server_(server), | 155 : sync_server_(server), |
| 156 sync_server_port_(port), | 156 sync_server_port_(port), |
| 157 use_ssl_(use_ssl), | 157 use_ssl_(use_ssl), |
| 158 proto_sync_path_(kSyncServerSyncPath), | 158 proto_sync_path_(kSyncServerSyncPath), |
| 159 server_status_(HttpResponse::NONE), | 159 server_status_(HttpResponse::NONE), |
| 160 terminated_(false), | 160 terminated_(false), |
| 161 active_connection_(NULL), | 161 active_connection_(nullptr), |
| 162 cancelation_signal_(cancelation_signal), | 162 cancelation_signal_(cancelation_signal), |
| 163 signal_handler_registered_(false) { | 163 signal_handler_registered_(false) { |
| 164 signal_handler_registered_ = cancelation_signal_->TryRegisterHandler(this); | 164 signal_handler_registered_ = cancelation_signal_->TryRegisterHandler(this); |
| 165 if (!signal_handler_registered_) { | 165 if (!signal_handler_registered_) { |
| 166 // Calling a virtual function from a constructor. We can get away with it | 166 // Calling a virtual function from a constructor. We can get away with it |
| 167 // here because ServerConnectionManager::OnSignalReceived() is the function | 167 // here because ServerConnectionManager::OnSignalReceived() is the function |
| 168 // we want to call. | 168 // we want to call. |
| 169 OnSignalReceived(); | 169 OnSignalReceived(); |
| 170 } | 170 } |
| 171 } | 171 } |
| 172 | 172 |
| 173 ServerConnectionManager::~ServerConnectionManager() { | 173 ServerConnectionManager::~ServerConnectionManager() { |
| 174 if (signal_handler_registered_) { | 174 if (signal_handler_registered_) { |
| 175 cancelation_signal_->UnregisterHandler(this); | 175 cancelation_signal_->UnregisterHandler(this); |
| 176 } | 176 } |
| 177 } | 177 } |
| 178 | 178 |
| 179 ServerConnectionManager::Connection* | 179 ServerConnectionManager::Connection* |
| 180 ServerConnectionManager::MakeActiveConnection() { | 180 ServerConnectionManager::MakeActiveConnection() { |
| 181 base::AutoLock lock(terminate_connection_lock_); | 181 base::AutoLock lock(terminate_connection_lock_); |
| 182 DCHECK(!active_connection_); | 182 DCHECK(!active_connection_); |
| 183 if (terminated_) | 183 if (terminated_) |
| 184 return NULL; | 184 return nullptr; |
| 185 | 185 |
| 186 active_connection_ = MakeConnection(); | 186 active_connection_ = MakeConnection(); |
| 187 return active_connection_; | 187 return active_connection_; |
| 188 } | 188 } |
| 189 | 189 |
| 190 void ServerConnectionManager::OnConnectionDestroyed(Connection* connection) { | 190 void ServerConnectionManager::OnConnectionDestroyed(Connection* connection) { |
| 191 DCHECK(connection); | 191 DCHECK(connection); |
| 192 base::AutoLock lock(terminate_connection_lock_); | 192 base::AutoLock lock(terminate_connection_lock_); |
| 193 // |active_connection_| can be NULL already if it was aborted. Also, | 193 // |active_connection_| can be null already if it was aborted. Also, |
| 194 // it can legitimately be a different Connection object if a new Connection | 194 // it can legitimately be a different Connection object if a new Connection |
| 195 // was created after a previous one was Aborted and destroyed. | 195 // was created after a previous one was Aborted and destroyed. |
| 196 if (active_connection_ != connection) | 196 if (active_connection_ != connection) |
| 197 return; | 197 return; |
| 198 | 198 |
| 199 active_connection_ = NULL; | 199 active_connection_ = nullptr; |
| 200 } | 200 } |
| 201 | 201 |
| 202 bool ServerConnectionManager::SetAuthToken(const std::string& auth_token) { | 202 bool ServerConnectionManager::SetAuthToken(const std::string& auth_token) { |
| 203 DCHECK(thread_checker_.CalledOnValidThread()); | 203 DCHECK(thread_checker_.CalledOnValidThread()); |
| 204 if (previously_invalidated_token != auth_token) { | 204 if (previously_invalidated_token != auth_token) { |
| 205 auth_token_.assign(auth_token); | 205 auth_token_.assign(auth_token); |
| 206 previously_invalidated_token = std::string(); | 206 previously_invalidated_token = std::string(); |
| 207 return true; | 207 return true; |
| 208 } | 208 } |
| 209 | 209 |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 305 listeners_.AddObserver(listener); | 305 listeners_.AddObserver(listener); |
| 306 } | 306 } |
| 307 | 307 |
| 308 void ServerConnectionManager::RemoveListener( | 308 void ServerConnectionManager::RemoveListener( |
| 309 ServerConnectionEventListener* listener) { | 309 ServerConnectionEventListener* listener) { |
| 310 DCHECK(thread_checker_.CalledOnValidThread()); | 310 DCHECK(thread_checker_.CalledOnValidThread()); |
| 311 listeners_.RemoveObserver(listener); | 311 listeners_.RemoveObserver(listener); |
| 312 } | 312 } |
| 313 | 313 |
| 314 ServerConnectionManager::Connection* ServerConnectionManager::MakeConnection() { | 314 ServerConnectionManager::Connection* ServerConnectionManager::MakeConnection() { |
| 315 return NULL; // For testing. | 315 return nullptr; // For testing. |
| 316 } | 316 } |
| 317 | 317 |
| 318 void ServerConnectionManager::OnSignalReceived() { | 318 void ServerConnectionManager::OnSignalReceived() { |
| 319 base::AutoLock lock(terminate_connection_lock_); | 319 base::AutoLock lock(terminate_connection_lock_); |
| 320 terminated_ = true; | 320 terminated_ = true; |
| 321 if (active_connection_) | 321 if (active_connection_) |
| 322 active_connection_->Abort(); | 322 active_connection_->Abort(); |
| 323 | 323 |
| 324 // Sever our ties to this connection object. Note that it still may exist, | 324 // Sever our ties to this connection object. Note that it still may exist, |
| 325 // since we don't own it, but it has been neutered. | 325 // since we don't own it, but it has been neutered. |
| 326 active_connection_ = NULL; | 326 active_connection_ = nullptr; |
| 327 } | 327 } |
| 328 | 328 |
| 329 std::ostream& operator<<(std::ostream& s, const struct HttpResponse& hr) { | 329 std::ostream& operator<<(std::ostream& s, const struct HttpResponse& hr) { |
| 330 s << " Response Code (bogus on error): " << hr.response_code; | 330 s << " Response Code (bogus on error): " << hr.response_code; |
| 331 s << " Content-Length (bogus on error): " << hr.content_length; | 331 s << " Content-Length (bogus on error): " << hr.content_length; |
| 332 s << " Server Status: " | 332 s << " Server Status: " |
| 333 << HttpResponse::GetServerConnectionCodeString(hr.server_status); | 333 << HttpResponse::GetServerConnectionCodeString(hr.server_status); |
| 334 return s; | 334 return s; |
| 335 } | 335 } |
| 336 | 336 |
| 337 } // namespace syncer | 337 } // namespace syncer |
| OLD | NEW |