diff options
-rw-r--r-- | net/spdy/spdy_session.cc | 12 | ||||
-rw-r--r-- | net/spdy/spdy_session.h | 7 |
2 files changed, 15 insertions, 4 deletions
diff --git a/net/spdy/spdy_session.cc b/net/spdy/spdy_session.cc index 53d1b5a..ed3d3462 100644 --- a/net/spdy/spdy_session.cc +++ b/net/spdy/spdy_session.cc @@ -224,6 +224,7 @@ SpdySession::SpdySession(const HostPortProxyPair& host_port_proxy_pair, read_callback_(this, &SpdySession::OnReadComplete)), ALLOW_THIS_IN_INITIALIZER_LIST( write_callback_(this, &SpdySession::OnWriteComplete)), + ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)), host_port_proxy_pair_(host_port_proxy_pair), spdy_session_pool_(spdy_session_pool), spdy_settings_(spdy_settings), @@ -670,8 +671,10 @@ net::Error SpdySession::ReadSocket() { // Schedule the work through the message loop to avoid recursive // callbacks. read_pending_ = true; - MessageLoop::current()->PostTask(FROM_HERE, NewRunnableMethod( - this, &SpdySession::OnReadComplete, bytes_read)); + MessageLoop::current()->PostTask( + FROM_HERE, + method_factory_.NewRunnableMethod( + &SpdySession::OnReadComplete, bytes_read)); break; } return OK; @@ -685,8 +688,9 @@ void SpdySession::WriteSocketLater() { return; delayed_write_pending_ = true; - MessageLoop::current()->PostTask(FROM_HERE, NewRunnableMethod( - this, &SpdySession::WriteSocket)); + MessageLoop::current()->PostTask( + FROM_HERE, + method_factory_.NewRunnableMethod(&SpdySession::WriteSocket)); } void SpdySession::WriteSocket() { diff --git a/net/spdy/spdy_session.h b/net/spdy/spdy_session.h index 2894471..313440c 100644 --- a/net/spdy/spdy_session.h +++ b/net/spdy/spdy_session.h @@ -15,6 +15,7 @@ #include "base/gtest_prod_util.h" #include "base/linked_ptr.h" #include "base/ref_counted.h" +#include "base/task.h" #include "net/base/io_buffer.h" #include "net/base/load_states.h" #include "net/base/net_errors.h" @@ -284,6 +285,12 @@ class SpdySession : public base::RefCounted<SpdySession>, CompletionCallbackImpl<SpdySession> read_callback_; CompletionCallbackImpl<SpdySession> write_callback_; + // Used for posting asynchronous IO tasks. We use this even though + // SpdySession is refcounted because we don't need to keep the SpdySession + // alive if the last reference is within a RunnableMethod. Just revoke the + // method. + ScopedRunnableMethodFactory<SpdySession> method_factory_; + // The domain this session is connected to. const HostPortProxyPair host_port_proxy_pair_; |