summaryrefslogtreecommitdiffstats
path: root/net/websockets
diff options
context:
space:
mode:
authorukai@chromium.org <ukai@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-07-22 10:25:34 +0000
committerukai@chromium.org <ukai@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-07-22 10:25:34 +0000
commit5dc90e57abcc7f0489e7ae09a3e687e9c6f4fad5 (patch)
tree03695c30212b216094ce69dc44351d2c55a5aea4 /net/websockets
parent97e2e3fa960ebb1e7a57a163656fecf9dd0eae21 (diff)
downloadchromium_src-5dc90e57abcc7f0489e7ae09a3e687e9c6f4fad5.zip
chromium_src-5dc90e57abcc7f0489e7ae09a3e687e9c6f4fad5.tar.gz
chromium_src-5dc90e57abcc7f0489e7ae09a3e687e9c6f4fad5.tar.bz2
Use ScopedRunnableMethodFactory in WebSocketJob
Don't post SendPending if it is already posted. BUG=89795 TEST=none Review URL: http://codereview.chromium.org/7488007 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@93599 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/websockets')
-rw-r--r--net/websockets/websocket_job.cc16
-rw-r--r--net/websockets/websocket_job.h2
2 files changed, 13 insertions, 5 deletions
diff --git a/net/websockets/websocket_job.cc b/net/websockets/websocket_job.cc
index 60b3c42..7646a14 100644
--- a/net/websockets/websocket_job.cc
+++ b/net/websockets/websocket_job.cc
@@ -82,7 +82,8 @@ WebSocketJob::WebSocketJob(SocketStream::Delegate* delegate)
handshake_request_sent_(0),
response_cookies_save_index_(0),
send_frame_handler_(new WebSocketFrameHandler),
- receive_frame_handler_(new WebSocketFrameHandler) {
+ receive_frame_handler_(new WebSocketFrameHandler),
+ ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)) {
}
WebSocketJob::~WebSocketJob() {
@@ -228,9 +229,12 @@ void WebSocketJob::OnSentData(SocketStream* socket, int amount_sent) {
DCHECK_GT(amount_sent, 0);
current_buffer_ = NULL;
send_frame_handler_->ReleaseCurrentBuffer();
+ if (method_factory_.empty()) {
+ MessageLoopForIO::current()->PostTask(
+ FROM_HERE,
+ method_factory_.NewRunnableMethod(&WebSocketJob::SendPending));
+ }
delegate_->OnSentData(socket, amount_sent);
- MessageLoopForIO::current()->PostTask(
- FROM_HERE, NewRunnableMethod(this, &WebSocketJob::SendPending));
}
}
@@ -593,7 +597,7 @@ void WebSocketJob::Wakeup() {
DCHECK(callback_);
MessageLoopForIO::current()->PostTask(
FROM_HERE,
- NewRunnableMethod(this, &WebSocketJob::RetryPendingIO));
+ method_factory_.NewRunnableMethod(&WebSocketJob::RetryPendingIO));
}
void WebSocketJob::RetryPendingIO() {
@@ -618,7 +622,9 @@ void WebSocketJob::CompleteIO(int result) {
bool WebSocketJob::SendDataInternal(const char* data, int length) {
if (spdy_websocket_stream_.get())
return ERR_IO_PENDING == spdy_websocket_stream_->SendData(data, length);
- return socket_->SendData(data, length);
+ if (socket_.get())
+ return socket_->SendData(data, length);
+ return false;
}
void WebSocketJob::CloseInternal() {
diff --git a/net/websockets/websocket_job.h b/net/websockets/websocket_job.h
index f0e67c6..2b02d6e 100644
--- a/net/websockets/websocket_job.h
+++ b/net/websockets/websocket_job.h
@@ -133,6 +133,8 @@ class NET_API WebSocketJob
scoped_ptr<SpdyWebSocketStream> spdy_websocket_stream_;
std::string challenge_;
+ ScopedRunnableMethodFactory<WebSocketJob> method_factory_;
+
DISALLOW_COPY_AND_ASSIGN(WebSocketJob);
};