OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 #include "net/websockets/websocket_job.h" | 5 #include "net/websockets/websocket_job.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/lazy_instance.h" | 9 #include "base/lazy_instance.h" |
10 #include "base/string_tokenizer.h" | 10 #include "base/string_tokenizer.h" |
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
227 std::string received_data; | 227 std::string received_data; |
228 receive_frame_handler_->AppendData(data, len); | 228 receive_frame_handler_->AppendData(data, len); |
229 // Don't buffer receiving data for now. | 229 // Don't buffer receiving data for now. |
230 // TODO(ukai): fix performance of WebSocketFrameHandler. | 230 // TODO(ukai): fix performance of WebSocketFrameHandler. |
231 while (receive_frame_handler_->UpdateCurrentBuffer(false) > 0) { | 231 while (receive_frame_handler_->UpdateCurrentBuffer(false) > 0) { |
232 received_data += | 232 received_data += |
233 std::string(receive_frame_handler_->GetCurrentBuffer()->data(), | 233 std::string(receive_frame_handler_->GetCurrentBuffer()->data(), |
234 receive_frame_handler_->GetCurrentBufferSize()); | 234 receive_frame_handler_->GetCurrentBufferSize()); |
235 receive_frame_handler_->ReleaseCurrentBuffer(); | 235 receive_frame_handler_->ReleaseCurrentBuffer(); |
236 } | 236 } |
237 if (delegate_ && received_data.size() > 0) | 237 if (delegate_ && !received_data.empty()) |
238 delegate_->OnReceivedData( | 238 delegate_->OnReceivedData( |
239 socket, received_data.data(), received_data.size()); | 239 socket, received_data.data(), received_data.size()); |
240 } | 240 } |
241 | 241 |
242 void WebSocketJob::OnClose(SocketStream* socket) { | 242 void WebSocketJob::OnClose(SocketStream* socket) { |
243 state_ = CLOSED; | 243 state_ = CLOSED; |
244 WebSocketThrottle::GetInstance()->RemoveFromQueue(this); | 244 WebSocketThrottle::GetInstance()->RemoveFromQueue(this); |
245 WebSocketThrottle::GetInstance()->WakeupSocketIfNecessary(); | 245 WebSocketThrottle::GetInstance()->WakeupSocketIfNecessary(); |
246 | 246 |
247 scoped_refptr<WebSocketJob> protect(this); | 247 scoped_refptr<WebSocketJob> protect(this); |
(...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
503 socket_->Close(); | 503 socket_->Close(); |
504 return; | 504 return; |
505 } | 505 } |
506 current_buffer_ = new DrainableIOBuffer( | 506 current_buffer_ = new DrainableIOBuffer( |
507 send_frame_handler_->GetCurrentBuffer(), | 507 send_frame_handler_->GetCurrentBuffer(), |
508 send_frame_handler_->GetCurrentBufferSize()); | 508 send_frame_handler_->GetCurrentBufferSize()); |
509 socket_->SendData(current_buffer_->data(), current_buffer_->BytesRemaining()); | 509 socket_->SendData(current_buffer_->data(), current_buffer_->BytesRemaining()); |
510 } | 510 } |
511 | 511 |
512 } // namespace net | 512 } // namespace net |
OLD | NEW |