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

Side by Side Diff: Source/modules/websockets/WebSocket.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) 2011 Google Inc. All rights reserved. 2 * Copyright (C) 2011 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 209 matching lines...) Expand 10 before | Expand all | Expand 10 after
220 220
221 const char* WebSocket::subprotocolSeperator() 221 const char* WebSocket::subprotocolSeperator()
222 { 222 {
223 return ", "; 223 return ", ";
224 } 224 }
225 225
226 WebSocket::WebSocket(ExecutionContext* context) 226 WebSocket::WebSocket(ExecutionContext* context)
227 : ActiveDOMObject(context) 227 : ActiveDOMObject(context)
228 , m_state(CONNECTING) 228 , m_state(CONNECTING)
229 , m_bufferedAmount(0) 229 , m_bufferedAmount(0)
230 , m_bufferedAmountDecrease(0)
230 , m_bufferedAmountAfterClose(0) 231 , m_bufferedAmountAfterClose(0)
231 , m_binaryType(BinaryTypeBlob) 232 , m_binaryType(BinaryTypeBlob)
232 , m_subprotocol("") 233 , m_subprotocol("")
233 , m_extensions("") 234 , m_extensions("")
234 , m_eventQueue(EventQueue::create(this)) 235 , m_eventQueue(EventQueue::create(this))
236 , m_bufferedAmountDecreaseTimer(this, &WebSocket::decreaseBufferedAmount)
235 { 237 {
236 ScriptWrappable::init(this); 238 ScriptWrappable::init(this);
237 } 239 }
238 240
239 WebSocket::~WebSocket() 241 WebSocket::~WebSocket()
240 { 242 {
241 ASSERT(!m_channel); 243 ASSERT(!m_channel);
242 } 244 }
243 245
244 void WebSocket::logError(const String& message) 246 void WebSocket::logError(const String& message)
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
365 } 367 }
366 368
367 void WebSocket::updateBufferedAmountAfterClose(unsigned long payloadSize) 369 void WebSocket::updateBufferedAmountAfterClose(unsigned long payloadSize)
368 { 370 {
369 m_bufferedAmountAfterClose = saturateAdd(m_bufferedAmountAfterClose, payload Size); 371 m_bufferedAmountAfterClose = saturateAdd(m_bufferedAmountAfterClose, payload Size);
370 m_bufferedAmountAfterClose = saturateAdd(m_bufferedAmountAfterClose, getFram ingOverhead(payloadSize)); 372 m_bufferedAmountAfterClose = saturateAdd(m_bufferedAmountAfterClose, getFram ingOverhead(payloadSize));
371 373
372 logError("WebSocket is already in CLOSING or CLOSED state."); 374 logError("WebSocket is already in CLOSING or CLOSED state.");
373 } 375 }
374 376
377 void WebSocket::decreaseBufferedAmount(Timer<WebSocket>*)
378 {
379 ASSERT(m_bufferedAmount >= m_bufferedAmountDecrease);
380 WTF_LOG(Network, "WebSocket %p decreaseBufferedAmount() %lu => %lu", this, m _bufferedAmount, m_bufferedAmount - m_bufferedAmountDecrease);
381
382 m_bufferedAmount -= m_bufferedAmountDecrease;
383 m_bufferedAmountDecrease = 0;
384 }
385
375 void WebSocket::releaseChannel() 386 void WebSocket::releaseChannel()
376 { 387 {
377 ASSERT(m_channel); 388 ASSERT(m_channel);
378 m_channel->disconnect(); 389 m_channel->disconnect();
379 m_channel = nullptr; 390 m_channel = nullptr;
380 } 391 }
381 392
382 void WebSocket::send(const String& message, ExceptionState& exceptionState) 393 void WebSocket::send(const String& message, ExceptionState& exceptionState)
383 { 394 {
384 WTF_LOG(Network, "WebSocket %p send() Sending String '%s'", this, message.ut f8().data()); 395 WTF_LOG(Network, "WebSocket %p send() Sending String '%s'", this, message.ut f8().data());
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after
632 } 643 }
633 } 644 }
634 645
635 void WebSocket::didReceiveMessageError() 646 void WebSocket::didReceiveMessageError()
636 { 647 {
637 WTF_LOG(Network, "WebSocket %p didReceiveMessageError()", this); 648 WTF_LOG(Network, "WebSocket %p didReceiveMessageError()", this);
638 m_state = CLOSED; 649 m_state = CLOSED;
639 m_eventQueue->dispatch(Event::create(EventTypeNames::error)); 650 m_eventQueue->dispatch(Event::create(EventTypeNames::error));
640 } 651 }
641 652
642 void WebSocket::didUpdateBufferedAmount(unsigned long bufferedAmount) 653 void WebSocket::didIncreaseBufferedAmount(unsigned long amount)
643 { 654 {
644 WTF_LOG(Network, "WebSocket %p didUpdateBufferedAmount() New bufferedAmount is %lu", this, bufferedAmount); 655 WTF_LOG(Network, "WebSocket %p didIncreaseBufferedAmount() %lu => %lu", this , m_bufferedAmount, m_bufferedAmount + amount);
645 if (m_state == CLOSED) 656 if (m_state == CLOSED)
646 return; 657 return;
647 m_bufferedAmount = bufferedAmount; 658 m_bufferedAmount += amount;
659 }
660
661 void WebSocket::didDecreaseBufferedAmount(unsigned long amount)
662 {
663 ASSERT(m_bufferedAmount >= amount);
664 WTF_LOG(Network, "WebSocket %p didDecreaseBufferedAmount(%lu)", this, amount );
665 if (m_state == CLOSED)
666 return;
667 m_bufferedAmountDecrease += amount;
668 if (!m_bufferedAmountDecreaseTimer.isActive())
669 m_bufferedAmountDecreaseTimer.startOneShot(0, FROM_HERE);
648 } 670 }
649 671
650 void WebSocket::didStartClosingHandshake() 672 void WebSocket::didStartClosingHandshake()
651 { 673 {
652 WTF_LOG(Network, "WebSocket %p didStartClosingHandshake()", this); 674 WTF_LOG(Network, "WebSocket %p didStartClosingHandshake()", this);
653 m_state = CLOSING; 675 m_state = CLOSING;
654 } 676 }
655 677
656 void WebSocket::didClose(unsigned long unhandledBufferedAmount, ClosingHandshake CompletionStatus closingHandshakeCompletion, unsigned short code, const String& reason) 678 void WebSocket::didClose(unsigned long unhandledBufferedAmount, ClosingHandshake CompletionStatus closingHandshakeCompletion, unsigned short code, const String& reason)
657 { 679 {
658 WTF_LOG(Network, "WebSocket %p didClose()", this); 680 WTF_LOG(Network, "WebSocket %p didClose()", this);
659 if (!m_channel) 681 if (!m_channel)
660 return; 682 return;
661 bool wasClean = m_state == CLOSING && !unhandledBufferedAmount && closingHan dshakeCompletion == ClosingHandshakeComplete && code != WebSocketChannel::CloseE ventCodeAbnormalClosure; 683 bool wasClean = m_state == CLOSING && !unhandledBufferedAmount && closingHan dshakeCompletion == ClosingHandshakeComplete && code != WebSocketChannel::CloseE ventCodeAbnormalClosure;
662
663 m_state = CLOSED; 684 m_state = CLOSED;
tyoshino (SeeGerritForStatus) 2014/06/09 09:24:26 is this change accidental? anyway i'm fine with e
yhirano 2014/06/09 11:59:51 Reverted
664 m_bufferedAmount = unhandledBufferedAmount; 685 m_bufferedAmount = unhandledBufferedAmount;
tyoshino (SeeGerritForStatus) 2014/06/09 09:24:26 is it possible unhandledBufferedAmount and m_buffe
yhirano 2014/06/09 11:59:51 I noticed I didn't understand why unhandledBuffere
tyoshino (SeeGerritForStatus) 2014/06/10 07:24:56 Took a look at the code and history of it. I agree
665 m_eventQueue->dispatch(CloseEvent::create(wasClean, code, reason)); 686 m_eventQueue->dispatch(CloseEvent::create(wasClean, code, reason));
666 releaseChannel(); 687 releaseChannel();
667 } 688 }
668 689
669 size_t WebSocket::getFramingOverhead(size_t payloadSize) 690 size_t WebSocket::getFramingOverhead(size_t payloadSize)
670 { 691 {
671 static const size_t hybiBaseFramingOverhead = 2; // Every frame has at least two-byte header. 692 static const size_t hybiBaseFramingOverhead = 2; // Every frame has at least two-byte header.
672 static const size_t hybiMaskingKeyLength = 4; // Every frame from client mus t have masking key. 693 static const size_t hybiMaskingKeyLength = 4; // Every frame from client mus t have masking key.
673 static const size_t minimumPayloadSizeWithTwoByteExtendedPayloadLength = 126 ; 694 static const size_t minimumPayloadSizeWithTwoByteExtendedPayloadLength = 126 ;
674 static const size_t minimumPayloadSizeWithEightByteExtendedPayloadLength = 0 x10000; 695 static const size_t minimumPayloadSizeWithEightByteExtendedPayloadLength = 0 x10000;
675 size_t overhead = hybiBaseFramingOverhead + hybiMaskingKeyLength; 696 size_t overhead = hybiBaseFramingOverhead + hybiMaskingKeyLength;
676 if (payloadSize >= minimumPayloadSizeWithEightByteExtendedPayloadLength) 697 if (payloadSize >= minimumPayloadSizeWithEightByteExtendedPayloadLength)
677 overhead += 8; 698 overhead += 8;
678 else if (payloadSize >= minimumPayloadSizeWithTwoByteExtendedPayloadLength) 699 else if (payloadSize >= minimumPayloadSizeWithTwoByteExtendedPayloadLength)
679 overhead += 2; 700 overhead += 2;
680 return overhead; 701 return overhead;
681 } 702 }
682 703
683 void WebSocket::trace(Visitor* visitor) 704 void WebSocket::trace(Visitor* visitor)
684 { 705 {
685 visitor->trace(m_channel); 706 visitor->trace(m_channel);
686 visitor->trace(m_eventQueue); 707 visitor->trace(m_eventQueue);
687 EventTargetWithInlineData::trace(visitor); 708 EventTargetWithInlineData::trace(visitor);
688 } 709 }
689 710
690 } // namespace WebCore 711 } // namespace WebCore
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698