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 274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
285 | 285 |
286 MessageLoop::current()->PostTask( | 286 MessageLoop::current()->PostTask( |
287 FROM_HERE, | 287 FROM_HERE, |
288 base::Bind(&SocketStream::DoRestartWithAuth, this)); | 288 base::Bind(&SocketStream::DoRestartWithAuth, this)); |
289 } | 289 } |
290 | 290 |
291 void SocketStream::DetachDelegate() { | 291 void SocketStream::DetachDelegate() { |
292 if (!delegate_) | 292 if (!delegate_) |
293 return; | 293 return; |
294 delegate_ = NULL; | 294 delegate_ = NULL; |
| 295 // Prevent the rest of the function from executing if we are being called from |
| 296 // within Finish(). |
| 297 if (next_state_ == STATE_NONE) |
| 298 return; |
295 net_log_.AddEvent(NetLog::TYPE_CANCELLED); | 299 net_log_.AddEvent(NetLog::TYPE_CANCELLED); |
296 // We don't need to send pending data when client detach the delegate. | 300 // We don't need to send pending data when client detach the delegate. |
297 pending_write_bufs_.clear(); | 301 pending_write_bufs_.clear(); |
298 Close(); | 302 Close(); |
299 } | 303 } |
300 | 304 |
301 const ProxyServer& SocketStream::proxy_server() const { | 305 const ProxyServer& SocketStream::proxy_server() const { |
302 return proxy_info_.proxy_server(); | 306 return proxy_info_.proxy_server(); |
303 } | 307 } |
304 | 308 |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
362 "The current MessageLoop must exist"; | 366 "The current MessageLoop must exist"; |
363 DCHECK_EQ(MessageLoop::TYPE_IO, MessageLoop::current()->type()) << | 367 DCHECK_EQ(MessageLoop::TYPE_IO, MessageLoop::current()->type()) << |
364 "The current MessageLoop must be TYPE_IO"; | 368 "The current MessageLoop must be TYPE_IO"; |
365 DCHECK_LE(result, OK); | 369 DCHECK_LE(result, OK); |
366 if (result == OK) | 370 if (result == OK) |
367 result = ERR_CONNECTION_CLOSED; | 371 result = ERR_CONNECTION_CLOSED; |
368 DCHECK_EQ(next_state_, STATE_NONE); | 372 DCHECK_EQ(next_state_, STATE_NONE); |
369 DVLOG(1) << "Finish result=" << ErrorToString(result); | 373 DVLOG(1) << "Finish result=" << ErrorToString(result); |
370 | 374 |
371 metrics_->OnClose(); | 375 metrics_->OnClose(); |
372 Delegate* delegate = delegate_; | 376 |
| 377 if (result != ERR_CONNECTION_CLOSED && delegate_) |
| 378 delegate_->OnError(this, result); |
| 379 if (result != ERR_PROTOCOL_SWITCHED && delegate_) |
| 380 delegate_->OnClose(this); |
373 delegate_ = NULL; | 381 delegate_ = NULL; |
374 if (delegate) { | 382 |
375 if (result != ERR_CONNECTION_CLOSED) | |
376 delegate->OnError(this, result); | |
377 if (result != ERR_PROTOCOL_SWITCHED) | |
378 delegate->OnClose(this); | |
379 } | |
380 Release(); | 383 Release(); |
381 } | 384 } |
382 | 385 |
383 int SocketStream::DidEstablishConnection() { | 386 int SocketStream::DidEstablishConnection() { |
384 if (!socket_.get() || !socket_->IsConnected()) { | 387 if (!socket_.get() || !socket_->IsConnected()) { |
385 next_state_ = STATE_CLOSE; | 388 next_state_ = STATE_CLOSE; |
386 return ERR_CONNECTION_FAILED; | 389 return ERR_CONNECTION_FAILED; |
387 } | 390 } |
388 next_state_ = STATE_READ_WRITE; | 391 next_state_ = STATE_READ_WRITE; |
389 metrics_->OnConnected(); | 392 metrics_->OnConnected(); |
(...skipping 931 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1321 | 1324 |
1322 SSLConfigService* SocketStream::ssl_config_service() const { | 1325 SSLConfigService* SocketStream::ssl_config_service() const { |
1323 return context_->ssl_config_service(); | 1326 return context_->ssl_config_service(); |
1324 } | 1327 } |
1325 | 1328 |
1326 ProxyService* SocketStream::proxy_service() const { | 1329 ProxyService* SocketStream::proxy_service() const { |
1327 return context_->proxy_service(); | 1330 return context_->proxy_service(); |
1328 } | 1331 } |
1329 | 1332 |
1330 } // namespace net | 1333 } // namespace net |
OLD | NEW |