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

Side by Side Diff: Source/modules/websockets/NewWebSocketChannelImpl.cpp

Issue 311993006: [WebSocket] bufferedAmount should not decrease inside a task. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 6 years, 6 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 unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2013 Google Inc. All rights reserved. 2 * Copyright (C) 2013 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
184 184
185 WebSocketChannel::SendResult NewWebSocketChannelImpl::send(const String& message ) 185 WebSocketChannel::SendResult NewWebSocketChannelImpl::send(const String& message )
186 { 186 {
187 WTF_LOG(Network, "NewWebSocketChannelImpl %p sendText(%s)", this, message.ut f8().data()); 187 WTF_LOG(Network, "NewWebSocketChannelImpl %p sendText(%s)", this, message.ut f8().data());
188 if (m_identifier) { 188 if (m_identifier) {
189 // FIXME: Change the inspector API to show the entire message instead 189 // FIXME: Change the inspector API to show the entire message instead
190 // of individual frames. 190 // of individual frames.
191 CString data = message.utf8(); 191 CString data = message.utf8();
192 InspectorInstrumentation::didSendWebSocketFrame(document(), m_identifier , WebSocketFrame::OpCodeText, true, data.data(), data.length()); 192 InspectorInstrumentation::didSendWebSocketFrame(document(), m_identifier , WebSocketFrame::OpCodeText, true, data.data(), data.length());
193 } 193 }
194 if (m_client)
195 m_client->didIncreaseBufferedAmount(message.utf8().length());
194 m_messages.append(adoptPtr(new Message(message))); 196 m_messages.append(adoptPtr(new Message(message)));
195 sendInternal(); 197 sendInternal();
196 return SendSuccess; 198 return SendSuccess;
197 } 199 }
198 200
199 WebSocketChannel::SendResult NewWebSocketChannelImpl::send(PassRefPtr<BlobDataHa ndle> blobDataHandle) 201 WebSocketChannel::SendResult NewWebSocketChannelImpl::send(PassRefPtr<BlobDataHa ndle> blobDataHandle)
200 { 202 {
201 WTF_LOG(Network, "NewWebSocketChannelImpl %p sendBlob(%s, %s, %llu)", this, blobDataHandle->uuid().utf8().data(), blobDataHandle->type().utf8().data(), blob DataHandle->size()); 203 WTF_LOG(Network, "NewWebSocketChannelImpl %p sendBlob(%s, %s, %llu)", this, blobDataHandle->uuid().utf8().data(), blobDataHandle->type().utf8().data(), blob DataHandle->size());
202 if (m_identifier) { 204 if (m_identifier) {
203 // FIXME: Change the inspector API to show the entire message instead 205 // FIXME: Change the inspector API to show the entire message instead
204 // of individual frames. 206 // of individual frames.
205 // FIXME: We can't access the data here. 207 // FIXME: We can't access the data here.
206 // Since Binary data are not displayed in Inspector, this does not 208 // Since Binary data are not displayed in Inspector, this does not
207 // affect actual behavior. 209 // affect actual behavior.
208 InspectorInstrumentation::didSendWebSocketFrame(document(), m_identifier , WebSocketFrame::OpCodeBinary, true, "", 0); 210 InspectorInstrumentation::didSendWebSocketFrame(document(), m_identifier , WebSocketFrame::OpCodeBinary, true, "", 0);
209 } 211 }
212 if (m_client)
213 m_client->didIncreaseBufferedAmount(blobDataHandle->size());
210 m_messages.append(adoptPtr(new Message(blobDataHandle))); 214 m_messages.append(adoptPtr(new Message(blobDataHandle)));
211 sendInternal(); 215 sendInternal();
212 return SendSuccess; 216 return SendSuccess;
213 } 217 }
214 218
215 WebSocketChannel::SendResult NewWebSocketChannelImpl::send(const ArrayBuffer& bu ffer, unsigned byteOffset, unsigned byteLength) 219 WebSocketChannel::SendResult NewWebSocketChannelImpl::send(const ArrayBuffer& bu ffer, unsigned byteOffset, unsigned byteLength)
216 { 220 {
217 WTF_LOG(Network, "NewWebSocketChannelImpl %p sendArrayBuffer(%p, %u, %u)", t his, buffer.data(), byteOffset, byteLength); 221 WTF_LOG(Network, "NewWebSocketChannelImpl %p sendArrayBuffer(%p, %u, %u)", t his, buffer.data(), byteOffset, byteLength);
218 if (m_identifier) { 222 if (m_identifier) {
219 // FIXME: Change the inspector API to show the entire message instead 223 // FIXME: Change the inspector API to show the entire message instead
220 // of individual frames. 224 // of individual frames.
221 InspectorInstrumentation::didSendWebSocketFrame(document(), m_identifier , WebSocketFrame::OpCodeBinary, true, static_cast<const char*>(buffer.data()) + byteOffset, byteLength); 225 InspectorInstrumentation::didSendWebSocketFrame(document(), m_identifier , WebSocketFrame::OpCodeBinary, true, static_cast<const char*>(buffer.data()) + byteOffset, byteLength);
222 } 226 }
227 if (m_client)
228 m_client->didIncreaseBufferedAmount(byteLength);
223 // buffer.slice copies its contents. 229 // buffer.slice copies its contents.
224 // FIXME: Reduce copy by sending the data immediately when we don't need to 230 // FIXME: Reduce copy by sending the data immediately when we don't need to
225 // queue the data. 231 // queue the data.
226 m_messages.append(adoptPtr(new Message(buffer.slice(byteOffset, byteOffset + byteLength)))); 232 m_messages.append(adoptPtr(new Message(buffer.slice(byteOffset, byteOffset + byteLength))));
227 sendInternal(); 233 sendInternal();
228 return SendSuccess; 234 return SendSuccess;
229 } 235 }
230 236
231 WebSocketChannel::SendResult NewWebSocketChannelImpl::send(PassOwnPtr<Vector<cha r> > data) 237 WebSocketChannel::SendResult NewWebSocketChannelImpl::send(PassOwnPtr<Vector<cha r> > data)
232 { 238 {
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
310 : type(MessageTypeArrayBuffer) 316 : type(MessageTypeArrayBuffer)
311 , arrayBuffer(arrayBuffer) { } 317 , arrayBuffer(arrayBuffer) { }
312 318
313 NewWebSocketChannelImpl::Message::Message(PassOwnPtr<Vector<char> > vectorData) 319 NewWebSocketChannelImpl::Message::Message(PassOwnPtr<Vector<char> > vectorData)
314 : type(MessageTypeVector) 320 : type(MessageTypeVector)
315 , vectorData(vectorData) { } 321 , vectorData(vectorData) { }
316 322
317 void NewWebSocketChannelImpl::sendInternal() 323 void NewWebSocketChannelImpl::sendInternal()
318 { 324 {
319 ASSERT(m_handle); 325 ASSERT(m_handle);
320 unsigned long bufferedAmount = m_bufferedAmount; 326 int64_t quota = m_sendingQuota;
321 while (!m_messages.isEmpty() && m_sendingQuota > 0 && !m_blobLoader) { 327 while (!m_messages.isEmpty() && m_sendingQuota > 0 && !m_blobLoader) {
322 bool final = false; 328 bool final = false;
323 Message* message = m_messages.first().get(); 329 Message* message = m_messages.first().get();
324 switch (message->type) { 330 switch (message->type) {
325 case MessageTypeText: { 331 case MessageTypeText: {
326 WebSocketHandle::MessageType type = 332 WebSocketHandle::MessageType type =
327 m_sentSizeOfTopMessage ? WebSocketHandle::MessageTypeContinuatio n : WebSocketHandle::MessageTypeText; 333 m_sentSizeOfTopMessage ? WebSocketHandle::MessageTypeContinuatio n : WebSocketHandle::MessageTypeText;
328 size_t size = std::min(static_cast<size_t>(m_sendingQuota), message- >text.length() - m_sentSizeOfTopMessage); 334 size_t size = std::min(static_cast<size_t>(m_sendingQuota), message- >text.length() - m_sentSizeOfTopMessage);
329 final = (m_sentSizeOfTopMessage + size == message->text.length()); 335 final = (m_sentSizeOfTopMessage + size == message->text.length());
330 m_handle->send(final, type, message->text.data() + m_sentSizeOfTopMe ssage, size); 336 m_handle->send(final, type, message->text.data() + m_sentSizeOfTopMe ssage, size);
(...skipping 24 matching lines...) Expand all
355 m_sentSizeOfTopMessage += size; 361 m_sentSizeOfTopMessage += size;
356 m_sendingQuota -= size; 362 m_sendingQuota -= size;
357 break; 363 break;
358 } 364 }
359 } 365 }
360 if (final) { 366 if (final) {
361 m_messages.removeFirst(); 367 m_messages.removeFirst();
362 m_sentSizeOfTopMessage = 0; 368 m_sentSizeOfTopMessage = 0;
363 } 369 }
364 } 370 }
365 if (m_client && m_bufferedAmount != bufferedAmount) { 371 if (m_client && quota != m_sendingQuota) {
366 m_client->didUpdateBufferedAmount(m_bufferedAmount); 372 unsigned long diff = quota - m_sendingQuota;
373 m_client->didDecreaseBufferedAmount(diff);
367 } 374 }
368 } 375 }
369 376
370 void NewWebSocketChannelImpl::flowControlIfNecessary() 377 void NewWebSocketChannelImpl::flowControlIfNecessary()
371 { 378 {
372 if (!m_handle || m_receivedDataSizeForFlowControl < receivedDataSizeForFlowC ontrolHighWaterMark) { 379 if (!m_handle || m_receivedDataSizeForFlowControl < receivedDataSizeForFlowC ontrolHighWaterMark) {
373 return; 380 return;
374 } 381 }
375 m_handle->flowControl(m_receivedDataSizeForFlowControl); 382 m_handle->flowControl(m_receivedDataSizeForFlowControl);
376 m_receivedDataSizeForFlowControl = 0; 383 m_receivedDataSizeForFlowControl = 0;
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after
562 // |this| can be deleted here. 569 // |this| can be deleted here.
563 } 570 }
564 571
565 void NewWebSocketChannelImpl::trace(Visitor* visitor) 572 void NewWebSocketChannelImpl::trace(Visitor* visitor)
566 { 573 {
567 visitor->trace(m_blobLoader); 574 visitor->trace(m_blobLoader);
568 WebSocketChannel::trace(visitor); 575 WebSocketChannel::trace(visitor);
569 } 576 }
570 577
571 } // namespace WebCore 578 } // namespace WebCore
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698