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

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 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
108 // |this| is deleted here. 108 // |this| is deleted here.
109 } 109 }
110 110
111 NewWebSocketChannelImpl::NewWebSocketChannelImpl(ExecutionContext* context, WebS ocketChannelClient* client, const String& sourceURL, unsigned lineNumber) 111 NewWebSocketChannelImpl::NewWebSocketChannelImpl(ExecutionContext* context, WebS ocketChannelClient* client, const String& sourceURL, unsigned lineNumber)
112 : ContextLifecycleObserver(context) 112 : ContextLifecycleObserver(context)
113 , m_handle(adoptPtr(blink::Platform::current()->createWebSocketHandle())) 113 , m_handle(adoptPtr(blink::Platform::current()->createWebSocketHandle()))
114 , m_client(client) 114 , m_client(client)
115 , m_identifier(0) 115 , m_identifier(0)
116 , m_sendingQuota(0) 116 , m_sendingQuota(0)
117 , m_receivedDataSizeForFlowControl(receivedDataSizeForFlowControlHighWaterMa rk * 2) // initial quota 117 , m_receivedDataSizeForFlowControl(receivedDataSizeForFlowControlHighWaterMa rk * 2) // initial quota
118 , m_bufferedAmount(0)
119 , m_sentSizeOfTopMessage(0) 118 , m_sentSizeOfTopMessage(0)
120 , m_sourceURLAtConstruction(sourceURL) 119 , m_sourceURLAtConstruction(sourceURL)
121 , m_lineNumberAtConstruction(lineNumber) 120 , m_lineNumberAtConstruction(lineNumber)
122 { 121 {
123 if (context->isDocument() && toDocument(context)->page()) 122 if (context->isDocument() && toDocument(context)->page())
124 m_identifier = createUniqueIdentifier(); 123 m_identifier = createUniqueIdentifier();
125 } 124 }
126 125
127 NewWebSocketChannelImpl::~NewWebSocketChannelImpl() 126 NewWebSocketChannelImpl::~NewWebSocketChannelImpl()
128 { 127 {
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
234 if (m_identifier) { 233 if (m_identifier) {
235 // FIXME: Change the inspector API to show the entire message instead 234 // FIXME: Change the inspector API to show the entire message instead
236 // of individual frames. 235 // of individual frames.
237 InspectorInstrumentation::didSendWebSocketFrame(document(), m_identifier , WebSocketFrame::OpCodeBinary, true, data->data(), data->size()); 236 InspectorInstrumentation::didSendWebSocketFrame(document(), m_identifier , WebSocketFrame::OpCodeBinary, true, data->data(), data->size());
238 } 237 }
239 m_messages.append(adoptPtr(new Message(data))); 238 m_messages.append(adoptPtr(new Message(data)));
240 sendInternal(); 239 sendInternal();
241 return SendSuccess; 240 return SendSuccess;
242 } 241 }
243 242
244 unsigned long NewWebSocketChannelImpl::bufferedAmount() const
245 {
246 WTF_LOG(Network, "NewWebSocketChannelImpl %p bufferedAmount()", this);
247 return m_bufferedAmount;
248 }
249
250 void NewWebSocketChannelImpl::close(int code, const String& reason) 243 void NewWebSocketChannelImpl::close(int code, const String& reason)
251 { 244 {
252 WTF_LOG(Network, "NewWebSocketChannelImpl %p close(%d, %s)", this, code, rea son.utf8().data()); 245 WTF_LOG(Network, "NewWebSocketChannelImpl %p close(%d, %s)", this, code, rea son.utf8().data());
253 ASSERT(m_handle); 246 ASSERT(m_handle);
254 unsigned short codeToSend = static_cast<unsigned short>(code == CloseEventCo deNotSpecified ? CloseEventCodeNoStatusRcvd : code); 247 unsigned short codeToSend = static_cast<unsigned short>(code == CloseEventCo deNotSpecified ? CloseEventCodeNoStatusRcvd : code);
255 m_handle->close(codeToSend, reason); 248 m_handle->close(codeToSend, reason);
256 } 249 }
257 250
258 void NewWebSocketChannelImpl::fail(const String& reason, MessageLevel level, con st String& sourceURL, unsigned lineNumber) 251 void NewWebSocketChannelImpl::fail(const String& reason, MessageLevel level, con st String& sourceURL, unsigned lineNumber)
259 { 252 {
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
310 : type(MessageTypeArrayBuffer) 303 : type(MessageTypeArrayBuffer)
311 , arrayBuffer(arrayBuffer) { } 304 , arrayBuffer(arrayBuffer) { }
312 305
313 NewWebSocketChannelImpl::Message::Message(PassOwnPtr<Vector<char> > vectorData) 306 NewWebSocketChannelImpl::Message::Message(PassOwnPtr<Vector<char> > vectorData)
314 : type(MessageTypeVector) 307 : type(MessageTypeVector)
315 , vectorData(vectorData) { } 308 , vectorData(vectorData) { }
316 309
317 void NewWebSocketChannelImpl::sendInternal() 310 void NewWebSocketChannelImpl::sendInternal()
318 { 311 {
319 ASSERT(m_handle); 312 ASSERT(m_handle);
320 unsigned long bufferedAmount = m_bufferedAmount; 313 unsigned long consumedBufferedAmount = 0;
321 while (!m_messages.isEmpty() && m_sendingQuota > 0 && !m_blobLoader) { 314 while (!m_messages.isEmpty() && m_sendingQuota > 0 && !m_blobLoader) {
322 bool final = false; 315 bool final = false;
323 Message* message = m_messages.first().get(); 316 Message* message = m_messages.first().get();
324 switch (message->type) { 317 switch (message->type) {
325 case MessageTypeText: { 318 case MessageTypeText: {
326 WebSocketHandle::MessageType type = 319 WebSocketHandle::MessageType type =
327 m_sentSizeOfTopMessage ? WebSocketHandle::MessageTypeContinuatio n : WebSocketHandle::MessageTypeText; 320 m_sentSizeOfTopMessage ? WebSocketHandle::MessageTypeContinuatio n : WebSocketHandle::MessageTypeText;
328 size_t size = std::min(static_cast<size_t>(m_sendingQuota), message- >text.length() - m_sentSizeOfTopMessage); 321 size_t size = std::min(static_cast<size_t>(m_sendingQuota), message- >text.length() - m_sentSizeOfTopMessage);
329 final = (m_sentSizeOfTopMessage + size == message->text.length()); 322 final = (m_sentSizeOfTopMessage + size == message->text.length());
330 m_handle->send(final, type, message->text.data() + m_sentSizeOfTopMe ssage, size); 323 m_handle->send(final, type, message->text.data() + m_sentSizeOfTopMe ssage, size);
331 m_sentSizeOfTopMessage += size; 324 m_sentSizeOfTopMessage += size;
332 m_sendingQuota -= size; 325 m_sendingQuota -= size;
326 consumedBufferedAmount += size;
333 break; 327 break;
334 } 328 }
335 case MessageTypeBlob: 329 case MessageTypeBlob:
336 ASSERT(!m_blobLoader); 330 ASSERT(!m_blobLoader);
337 m_blobLoader = adoptPtrWillBeNoop(new BlobLoader(message->blobDataHa ndle, this)); 331 m_blobLoader = adoptPtrWillBeNoop(new BlobLoader(message->blobDataHa ndle, this));
338 break; 332 break;
339 case MessageTypeArrayBuffer: { 333 case MessageTypeArrayBuffer: {
340 WebSocketHandle::MessageType type = 334 WebSocketHandle::MessageType type =
341 m_sentSizeOfTopMessage ? WebSocketHandle::MessageTypeContinuatio n : WebSocketHandle::MessageTypeBinary; 335 m_sentSizeOfTopMessage ? WebSocketHandle::MessageTypeContinuatio n : WebSocketHandle::MessageTypeBinary;
342 size_t size = std::min(static_cast<size_t>(m_sendingQuota), message- >arrayBuffer->byteLength() - m_sentSizeOfTopMessage); 336 size_t size = std::min(static_cast<size_t>(m_sendingQuota), message- >arrayBuffer->byteLength() - m_sentSizeOfTopMessage);
343 final = (m_sentSizeOfTopMessage + size == message->arrayBuffer->byte Length()); 337 final = (m_sentSizeOfTopMessage + size == message->arrayBuffer->byte Length());
344 m_handle->send(final, type, static_cast<const char*>(message->arrayB uffer->data()) + m_sentSizeOfTopMessage, size); 338 m_handle->send(final, type, static_cast<const char*>(message->arrayB uffer->data()) + m_sentSizeOfTopMessage, size);
345 m_sentSizeOfTopMessage += size; 339 m_sentSizeOfTopMessage += size;
346 m_sendingQuota -= size; 340 m_sendingQuota -= size;
341 consumedBufferedAmount += size;
347 break; 342 break;
348 } 343 }
349 case MessageTypeVector: { 344 case MessageTypeVector: {
350 WebSocketHandle::MessageType type = 345 WebSocketHandle::MessageType type =
351 m_sentSizeOfTopMessage ? WebSocketHandle::MessageTypeContinuatio n : WebSocketHandle::MessageTypeBinary; 346 m_sentSizeOfTopMessage ? WebSocketHandle::MessageTypeContinuatio n : WebSocketHandle::MessageTypeBinary;
352 size_t size = std::min(static_cast<size_t>(m_sendingQuota), message- >vectorData->size() - m_sentSizeOfTopMessage); 347 size_t size = std::min(static_cast<size_t>(m_sendingQuota), message- >vectorData->size() - m_sentSizeOfTopMessage);
353 final = (m_sentSizeOfTopMessage + size == message->vectorData->size( )); 348 final = (m_sentSizeOfTopMessage + size == message->vectorData->size( ));
354 m_handle->send(final, type, message->vectorData->data() + m_sentSize OfTopMessage, size); 349 m_handle->send(final, type, message->vectorData->data() + m_sentSize OfTopMessage, size);
355 m_sentSizeOfTopMessage += size; 350 m_sentSizeOfTopMessage += size;
356 m_sendingQuota -= size; 351 m_sendingQuota -= size;
352 consumedBufferedAmount += size;
357 break; 353 break;
358 } 354 }
359 } 355 }
360 if (final) { 356 if (final) {
361 m_messages.removeFirst(); 357 m_messages.removeFirst();
362 m_sentSizeOfTopMessage = 0; 358 m_sentSizeOfTopMessage = 0;
363 } 359 }
364 } 360 }
365 if (m_client && m_bufferedAmount != bufferedAmount) { 361 if (m_client && consumedBufferedAmount > 0)
366 m_client->didUpdateBufferedAmount(m_bufferedAmount); 362 m_client->didConsumeBufferedAmount(consumedBufferedAmount);
367 }
368 } 363 }
369 364
370 void NewWebSocketChannelImpl::flowControlIfNecessary() 365 void NewWebSocketChannelImpl::flowControlIfNecessary()
371 { 366 {
372 if (!m_handle || m_receivedDataSizeForFlowControl < receivedDataSizeForFlowC ontrolHighWaterMark) { 367 if (!m_handle || m_receivedDataSizeForFlowControl < receivedDataSizeForFlowC ontrolHighWaterMark) {
373 return; 368 return;
374 } 369 }
375 m_handle->flowControl(m_receivedDataSizeForFlowControl); 370 m_handle->flowControl(m_receivedDataSizeForFlowControl);
376 m_receivedDataSizeForFlowControl = 0; 371 m_receivedDataSizeForFlowControl = 0;
377 } 372 }
(...skipping 10 matching lines...) Expand all
388 { 383 {
389 m_handle.clear(); 384 m_handle.clear();
390 abortAsyncOperations(); 385 abortAsyncOperations();
391 if (!m_client) { 386 if (!m_client) {
392 return; 387 return;
393 } 388 }
394 WebSocketChannelClient* client = m_client; 389 WebSocketChannelClient* client = m_client;
395 m_client = 0; 390 m_client = 0;
396 WebSocketChannelClient::ClosingHandshakeCompletionStatus status = 391 WebSocketChannelClient::ClosingHandshakeCompletionStatus status =
397 wasClean ? WebSocketChannelClient::ClosingHandshakeComplete : WebSocketC hannelClient::ClosingHandshakeIncomplete; 392 wasClean ? WebSocketChannelClient::ClosingHandshakeComplete : WebSocketC hannelClient::ClosingHandshakeIncomplete;
398 client->didClose(m_bufferedAmount, status, code, reason); 393 client->didClose(status, code, reason);
399 // client->didClose may delete this object. 394 // client->didClose may delete this object.
400 } 395 }
401 396
402 Document* NewWebSocketChannelImpl::document() 397 Document* NewWebSocketChannelImpl::document()
403 { 398 {
404 ASSERT(m_identifier); 399 ASSERT(m_identifier);
405 ExecutionContext* context = executionContext(); 400 ExecutionContext* context = executionContext();
406 ASSERT(context->isDocument()); 401 ASSERT(context->isDocument());
407 return toDocument(context); 402 return toDocument(context);
408 } 403 }
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
562 // |this| can be deleted here. 557 // |this| can be deleted here.
563 } 558 }
564 559
565 void NewWebSocketChannelImpl::trace(Visitor* visitor) 560 void NewWebSocketChannelImpl::trace(Visitor* visitor)
566 { 561 {
567 visitor->trace(m_blobLoader); 562 visitor->trace(m_blobLoader);
568 WebSocketChannel::trace(visitor); 563 WebSocketChannel::trace(visitor);
569 } 564 }
570 565
571 } // namespace WebCore 566 } // namespace WebCore
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698