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

Unified Diff: net/socket_stream/socket_stream.cc

Issue 15989003: Support delegate deleting itself from OnError (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Fixes from tyoshino review. Created 7 years, 7 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | net/socket_stream/socket_stream_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/socket_stream/socket_stream.cc
diff --git a/net/socket_stream/socket_stream.cc b/net/socket_stream/socket_stream.cc
index 98c41666933c24f4f7dbafdedc8b1f829c05a8e6..6428232c694a70bd54187fedaa85fdc13b30f10a 100644
--- a/net/socket_stream/socket_stream.cc
+++ b/net/socket_stream/socket_stream.cc
@@ -292,6 +292,10 @@ void SocketStream::DetachDelegate() {
if (!delegate_)
return;
delegate_ = NULL;
+ // Prevent the rest of the function from executing if we are being called from
+ // within Finish().
+ if (next_state_ == STATE_NONE)
+ return;
net_log_.AddEvent(NetLog::TYPE_CANCELLED);
// We don't need to send pending data when client detach the delegate.
pending_write_bufs_.clear();
@@ -369,14 +373,13 @@ void SocketStream::Finish(int result) {
DVLOG(1) << "Finish result=" << ErrorToString(result);
metrics_->OnClose();
- Delegate* delegate = delegate_;
+
+ if (result != ERR_CONNECTION_CLOSED && delegate_)
+ delegate_->OnError(this, result);
+ if (result != ERR_PROTOCOL_SWITCHED && delegate_)
+ delegate_->OnClose(this);
delegate_ = NULL;
- if (delegate) {
- if (result != ERR_CONNECTION_CLOSED)
- delegate->OnError(this, result);
- if (result != ERR_PROTOCOL_SWITCHED)
- delegate->OnClose(this);
- }
+
Release();
}
« no previous file with comments | « no previous file | net/socket_stream/socket_stream_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698