| 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 // TODO(ukai): code is similar with http_network_transaction.cc. We should | 5 // TODO(ukai): code is similar with http_network_transaction.cc. We should |
| 6 // think about ways to share code, if possible. | 6 // think about ways to share code, if possible. |
| 7 | 7 |
| 8 #include "net/socket_stream/socket_stream.h" | 8 #include "net/socket_stream/socket_stream.h" |
| 9 | 9 |
| 10 #include <set> | 10 #include <set> |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 104 io_callback_(base::Bind(&SocketStream::OnIOCompleted, | 104 io_callback_(base::Bind(&SocketStream::OnIOCompleted, |
| 105 base::Unretained(this))), | 105 base::Unretained(this))), |
| 106 read_buf_(NULL), | 106 read_buf_(NULL), |
| 107 current_write_buf_(NULL), | 107 current_write_buf_(NULL), |
| 108 waiting_for_write_completion_(false), | 108 waiting_for_write_completion_(false), |
| 109 closing_(false), | 109 closing_(false), |
| 110 server_closed_(false), | 110 server_closed_(false), |
| 111 metrics_(new SocketStreamMetrics(url)) { | 111 metrics_(new SocketStreamMetrics(url)) { |
| 112 DCHECK(base::MessageLoop::current()) | 112 DCHECK(base::MessageLoop::current()) |
| 113 << "The current base::MessageLoop must exist"; | 113 << "The current base::MessageLoop must exist"; |
| 114 DCHECK_EQ(base::MessageLoop::TYPE_IO, base::MessageLoop::current()->type()) | 114 DCHECK(base::MessageLoopForIO::IsCurrent()) |
| 115 << "The current base::MessageLoop must be TYPE_IO"; | 115 << "The current base::MessageLoop must be TYPE_IO"; |
| 116 DCHECK(delegate_); | 116 DCHECK(delegate_); |
| 117 } | 117 } |
| 118 | 118 |
| 119 SocketStream::UserData* SocketStream::GetUserData( | 119 SocketStream::UserData* SocketStream::GetUserData( |
| 120 const void* key) const { | 120 const void* key) const { |
| 121 UserDataMap::const_iterator found = user_data_.find(key); | 121 UserDataMap::const_iterator found = user_data_.find(key); |
| 122 if (found != user_data_.end()) | 122 if (found != user_data_.end()) |
| 123 return found->second.get(); | 123 return found->second.get(); |
| 124 return NULL; | 124 return NULL; |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 163 privacy_mode_ = enable ? kPrivacyModeEnabled : kPrivacyModeDisabled; | 163 privacy_mode_ = enable ? kPrivacyModeEnabled : kPrivacyModeDisabled; |
| 164 // Disable Channel ID if privacy mode is enabled. | 164 // Disable Channel ID if privacy mode is enabled. |
| 165 if (enable) | 165 if (enable) |
| 166 server_ssl_config_.channel_id_enabled = false; | 166 server_ssl_config_.channel_id_enabled = false; |
| 167 } | 167 } |
| 168 } | 168 } |
| 169 | 169 |
| 170 void SocketStream::Connect() { | 170 void SocketStream::Connect() { |
| 171 DCHECK(base::MessageLoop::current()) | 171 DCHECK(base::MessageLoop::current()) |
| 172 << "The current base::MessageLoop must exist"; | 172 << "The current base::MessageLoop must exist"; |
| 173 DCHECK_EQ(base::MessageLoop::TYPE_IO, base::MessageLoop::current()->type()) | 173 DCHECK(base::MessageLoopForIO::IsCurrent()) |
| 174 << "The current base::MessageLoop must be TYPE_IO"; | 174 << "The current base::MessageLoop must be TYPE_IO"; |
| 175 if (context_) { | 175 if (context_) { |
| 176 context_->ssl_config_service()->GetSSLConfig(&server_ssl_config_); | 176 context_->ssl_config_service()->GetSSLConfig(&server_ssl_config_); |
| 177 proxy_ssl_config_ = server_ssl_config_; | 177 proxy_ssl_config_ = server_ssl_config_; |
| 178 } | 178 } |
| 179 CheckPrivacyMode(); | 179 CheckPrivacyMode(); |
| 180 | 180 |
| 181 DCHECK_EQ(next_state_, STATE_NONE); | 181 DCHECK_EQ(next_state_, STATE_NONE); |
| 182 | 182 |
| 183 AddRef(); // Released in Finish() | 183 AddRef(); // Released in Finish() |
| (...skipping 12 matching lines...) Expand all Loading... |
| 196 for (PendingDataQueue::const_iterator iter = pending_write_bufs_.begin(); | 196 for (PendingDataQueue::const_iterator iter = pending_write_bufs_.begin(); |
| 197 iter != pending_write_bufs_.end(); | 197 iter != pending_write_bufs_.end(); |
| 198 ++iter) | 198 ++iter) |
| 199 total_size += (*iter)->size(); | 199 total_size += (*iter)->size(); |
| 200 return total_size; | 200 return total_size; |
| 201 } | 201 } |
| 202 | 202 |
| 203 bool SocketStream::SendData(const char* data, int len) { | 203 bool SocketStream::SendData(const char* data, int len) { |
| 204 DCHECK(base::MessageLoop::current()) | 204 DCHECK(base::MessageLoop::current()) |
| 205 << "The current base::MessageLoop must exist"; | 205 << "The current base::MessageLoop must exist"; |
| 206 DCHECK_EQ(base::MessageLoop::TYPE_IO, base::MessageLoop::current()->type()) | 206 DCHECK(base::MessageLoopForIO::IsCurrent()) |
| 207 << "The current base::MessageLoop must be TYPE_IO"; | 207 << "The current base::MessageLoop must be TYPE_IO"; |
| 208 DCHECK_GT(len, 0); | 208 DCHECK_GT(len, 0); |
| 209 | 209 |
| 210 if (!connection_->socket() || | 210 if (!connection_->socket() || |
| 211 !connection_->socket()->IsConnected() || next_state_ == STATE_NONE) { | 211 !connection_->socket()->IsConnected() || next_state_ == STATE_NONE) { |
| 212 return false; | 212 return false; |
| 213 } | 213 } |
| 214 | 214 |
| 215 int total_buffered_bytes = len; | 215 int total_buffered_bytes = len; |
| 216 if (current_write_buf_.get()) { | 216 if (current_write_buf_.get()) { |
| (...skipping 26 matching lines...) Expand all Loading... |
| 243 base::MessageLoop::current()->PostTask( | 243 base::MessageLoop::current()->PostTask( |
| 244 FROM_HERE, base::Bind(&SocketStream::DoLoop, this, OK)); | 244 FROM_HERE, base::Bind(&SocketStream::DoLoop, this, OK)); |
| 245 } | 245 } |
| 246 | 246 |
| 247 return true; | 247 return true; |
| 248 } | 248 } |
| 249 | 249 |
| 250 void SocketStream::Close() { | 250 void SocketStream::Close() { |
| 251 DCHECK(base::MessageLoop::current()) | 251 DCHECK(base::MessageLoop::current()) |
| 252 << "The current base::MessageLoop must exist"; | 252 << "The current base::MessageLoop must exist"; |
| 253 DCHECK_EQ(base::MessageLoop::TYPE_IO, base::MessageLoop::current()->type()) | 253 DCHECK(base::MessageLoopForIO::IsCurrent()) |
| 254 << "The current base::MessageLoop must be TYPE_IO"; | 254 << "The current base::MessageLoop must be TYPE_IO"; |
| 255 // If next_state_ is STATE_NONE, the socket was not opened, or already | 255 // If next_state_ is STATE_NONE, the socket was not opened, or already |
| 256 // closed. So, return immediately. | 256 // closed. So, return immediately. |
| 257 // Otherwise, it might call Finish() more than once, so breaks balance | 257 // Otherwise, it might call Finish() more than once, so breaks balance |
| 258 // of AddRef() and Release() in Connect() and Finish(), respectively. | 258 // of AddRef() and Release() in Connect() and Finish(), respectively. |
| 259 if (next_state_ == STATE_NONE) | 259 if (next_state_ == STATE_NONE) |
| 260 return; | 260 return; |
| 261 base::MessageLoop::current()->PostTask( | 261 base::MessageLoop::current()->PostTask( |
| 262 FROM_HERE, base::Bind(&SocketStream::DoClose, this)); | 262 FROM_HERE, base::Bind(&SocketStream::DoClose, this)); |
| 263 } | 263 } |
| 264 | 264 |
| 265 void SocketStream::RestartWithAuth(const AuthCredentials& credentials) { | 265 void SocketStream::RestartWithAuth(const AuthCredentials& credentials) { |
| 266 DCHECK(base::MessageLoop::current()) | 266 DCHECK(base::MessageLoop::current()) |
| 267 << "The current base::MessageLoop must exist"; | 267 << "The current base::MessageLoop must exist"; |
| 268 DCHECK_EQ(base::MessageLoop::TYPE_IO, base::MessageLoop::current()->type()) | 268 DCHECK(base::MessageLoopForIO::IsCurrent()) |
| 269 << "The current base::MessageLoop must be TYPE_IO"; | 269 << "The current base::MessageLoop must be TYPE_IO"; |
| 270 DCHECK(proxy_auth_controller_.get()); | 270 DCHECK(proxy_auth_controller_.get()); |
| 271 if (!connection_->socket()) { | 271 if (!connection_->socket()) { |
| 272 DVLOG(1) << "Socket is closed before restarting with auth."; | 272 DVLOG(1) << "Socket is closed before restarting with auth."; |
| 273 return; | 273 return; |
| 274 } | 274 } |
| 275 | 275 |
| 276 proxy_auth_controller_->ResetAuth(credentials); | 276 proxy_auth_controller_->ResetAuth(credentials); |
| 277 | 277 |
| 278 base::MessageLoop::current()->PostTask( | 278 base::MessageLoop::current()->PostTask( |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 351 if (next_state_ == STATE_READ_WRITE && !current_write_buf_.get()) | 351 if (next_state_ == STATE_READ_WRITE && !current_write_buf_.get()) |
| 352 DoLoop(ERR_ABORTED); | 352 DoLoop(ERR_ABORTED); |
| 353 | 353 |
| 354 // In other next_state_, we'll wait for callback of other APIs, such as | 354 // In other next_state_, we'll wait for callback of other APIs, such as |
| 355 // ResolveProxy(). | 355 // ResolveProxy(). |
| 356 } | 356 } |
| 357 | 357 |
| 358 void SocketStream::Finish(int result) { | 358 void SocketStream::Finish(int result) { |
| 359 DCHECK(base::MessageLoop::current()) | 359 DCHECK(base::MessageLoop::current()) |
| 360 << "The current base::MessageLoop must exist"; | 360 << "The current base::MessageLoop must exist"; |
| 361 DCHECK_EQ(base::MessageLoop::TYPE_IO, base::MessageLoop::current()->type()) | 361 DCHECK(base::MessageLoopForIO::IsCurrent()) |
| 362 << "The current base::MessageLoop must be TYPE_IO"; | 362 << "The current base::MessageLoop must be TYPE_IO"; |
| 363 DCHECK_LE(result, OK); | 363 DCHECK_LE(result, OK); |
| 364 if (result == OK) | 364 if (result == OK) |
| 365 result = ERR_CONNECTION_CLOSED; | 365 result = ERR_CONNECTION_CLOSED; |
| 366 DCHECK_EQ(next_state_, STATE_NONE); | 366 DCHECK_EQ(next_state_, STATE_NONE); |
| 367 DVLOG(1) << "Finish result=" << ErrorToString(result); | 367 DVLOG(1) << "Finish result=" << ErrorToString(result); |
| 368 | 368 |
| 369 metrics_->OnClose(); | 369 metrics_->OnClose(); |
| 370 | 370 |
| 371 if (result != ERR_CONNECTION_CLOSED && delegate_) | 371 if (result != ERR_CONNECTION_CLOSED && delegate_) |
| (...skipping 964 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1336 context_->transport_security_state()->GetDomainState(url_.host(), | 1336 context_->transport_security_state()->GetDomainState(url_.host(), |
| 1337 SSLConfigService::IsSNIAvailable(context_->ssl_config_service()), | 1337 SSLConfigService::IsSNIAvailable(context_->ssl_config_service()), |
| 1338 &domain_state) && | 1338 &domain_state) && |
| 1339 domain_state.ShouldSSLErrorsBeFatal(); | 1339 domain_state.ShouldSSLErrorsBeFatal(); |
| 1340 | 1340 |
| 1341 delegate_->OnSSLCertificateError(this, ssl_info, fatal); | 1341 delegate_->OnSSLCertificateError(this, ssl_info, fatal); |
| 1342 return ERR_IO_PENDING; | 1342 return ERR_IO_PENDING; |
| 1343 } | 1343 } |
| 1344 | 1344 |
| 1345 } // namespace net | 1345 } // namespace net |
| OLD | NEW |