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

Side by Side Diff: third_party/WebKit/Source/modules/websockets/DOMWebSocket.cpp

Issue 1652983005: Remove Enumeration Histograms from the Blink Platform API. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master_blink_histograms_5a
Patch Set: Fix misplaced bracket on android Created 4 years, 10 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 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 #include "core/events/MessageEvent.h" 42 #include "core/events/MessageEvent.h"
43 #include "core/fileapi/Blob.h" 43 #include "core/fileapi/Blob.h"
44 #include "core/frame/ConsoleTypes.h" 44 #include "core/frame/ConsoleTypes.h"
45 #include "core/frame/LocalDOMWindow.h" 45 #include "core/frame/LocalDOMWindow.h"
46 #include "core/frame/LocalFrame.h" 46 #include "core/frame/LocalFrame.h"
47 #include "core/frame/UseCounter.h" 47 #include "core/frame/UseCounter.h"
48 #include "core/frame/csp/ContentSecurityPolicy.h" 48 #include "core/frame/csp/ContentSecurityPolicy.h"
49 #include "core/inspector/ConsoleMessage.h" 49 #include "core/inspector/ConsoleMessage.h"
50 #include "core/inspector/ScriptCallStack.h" 50 #include "core/inspector/ScriptCallStack.h"
51 #include "modules/websockets/CloseEvent.h" 51 #include "modules/websockets/CloseEvent.h"
52 #include "platform/Histogram.h"
52 #include "platform/Logging.h" 53 #include "platform/Logging.h"
53 #include "platform/blob/BlobData.h" 54 #include "platform/blob/BlobData.h"
54 #include "platform/heap/Handle.h" 55 #include "platform/heap/Handle.h"
55 #include "platform/weborigin/SecurityOrigin.h" 56 #include "platform/weborigin/SecurityOrigin.h"
56 #include "public/platform/Platform.h" 57 #include "public/platform/Platform.h"
57 #include "wtf/Assertions.h" 58 #include "wtf/Assertions.h"
58 #include "wtf/HashSet.h" 59 #include "wtf/HashSet.h"
59 #include "wtf/PassOwnPtr.h" 60 #include "wtf/PassOwnPtr.h"
60 #include "wtf/StdLibExtras.h" 61 #include "wtf/StdLibExtras.h"
61 #include "wtf/text/CString.h" 62 #include "wtf/text/CString.h"
(...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after
385 WTF_LOG(Network, "WebSocket %p send() Sending String '%s'", this, encodedMes sage.data()); 386 WTF_LOG(Network, "WebSocket %p send() Sending String '%s'", this, encodedMes sage.data());
386 if (m_state == CONNECTING) { 387 if (m_state == CONNECTING) {
387 setInvalidStateErrorForSendMethod(exceptionState); 388 setInvalidStateErrorForSendMethod(exceptionState);
388 return; 389 return;
389 } 390 }
390 // No exception is raised if the connection was once established but has sub sequently been closed. 391 // No exception is raised if the connection was once established but has sub sequently been closed.
391 if (m_state == CLOSING || m_state == CLOSED) { 392 if (m_state == CLOSING || m_state == CLOSED) {
392 updateBufferedAmountAfterClose(encodedMessage.length()); 393 updateBufferedAmountAfterClose(encodedMessage.length());
393 return; 394 return;
394 } 395 }
395 Platform::current()->histogramEnumeration("WebCore.WebSocket.SendType", WebS ocketSendTypeString, WebSocketSendTypeMax); 396
397 recordSendTypeHistogram(WebSocketSendTypeString);
398
396 ASSERT(m_channel); 399 ASSERT(m_channel);
397 m_bufferedAmount += encodedMessage.length(); 400 m_bufferedAmount += encodedMessage.length();
398 m_channel->send(encodedMessage); 401 m_channel->send(encodedMessage);
399 } 402 }
400 403
401 void DOMWebSocket::send(DOMArrayBuffer* binaryData, ExceptionState& exceptionSta te) 404 void DOMWebSocket::send(DOMArrayBuffer* binaryData, ExceptionState& exceptionSta te)
402 { 405 {
403 WTF_LOG(Network, "WebSocket %p send() Sending ArrayBuffer %p", this, binaryD ata); 406 WTF_LOG(Network, "WebSocket %p send() Sending ArrayBuffer %p", this, binaryD ata);
404 ASSERT(binaryData && binaryData->buffer()); 407 ASSERT(binaryData && binaryData->buffer());
405 if (m_state == CONNECTING) { 408 if (m_state == CONNECTING) {
406 setInvalidStateErrorForSendMethod(exceptionState); 409 setInvalidStateErrorForSendMethod(exceptionState);
407 return; 410 return;
408 } 411 }
409 if (m_state == CLOSING || m_state == CLOSED) { 412 if (m_state == CLOSING || m_state == CLOSED) {
410 updateBufferedAmountAfterClose(binaryData->byteLength()); 413 updateBufferedAmountAfterClose(binaryData->byteLength());
411 return; 414 return;
412 } 415 }
413 Platform::current()->histogramEnumeration("WebCore.WebSocket.SendType", WebS ocketSendTypeArrayBuffer, WebSocketSendTypeMax); 416 recordSendTypeHistogram(WebSocketSendTypeArrayBuffer);
417
414 ASSERT(m_channel); 418 ASSERT(m_channel);
415 m_bufferedAmount += binaryData->byteLength(); 419 m_bufferedAmount += binaryData->byteLength();
416 m_channel->send(*binaryData, 0, binaryData->byteLength()); 420 m_channel->send(*binaryData, 0, binaryData->byteLength());
417 } 421 }
418 422
419 void DOMWebSocket::send(DOMArrayBufferView* arrayBufferView, ExceptionState& exc eptionState) 423 void DOMWebSocket::send(DOMArrayBufferView* arrayBufferView, ExceptionState& exc eptionState)
420 { 424 {
421 WTF_LOG(Network, "WebSocket %p send() Sending ArrayBufferView %p", this, arr ayBufferView); 425 WTF_LOG(Network, "WebSocket %p send() Sending ArrayBufferView %p", this, arr ayBufferView);
422 ASSERT(arrayBufferView); 426 ASSERT(arrayBufferView);
423 if (m_state == CONNECTING) { 427 if (m_state == CONNECTING) {
424 setInvalidStateErrorForSendMethod(exceptionState); 428 setInvalidStateErrorForSendMethod(exceptionState);
425 return; 429 return;
426 } 430 }
427 if (m_state == CLOSING || m_state == CLOSED) { 431 if (m_state == CLOSING || m_state == CLOSED) {
428 updateBufferedAmountAfterClose(arrayBufferView->byteLength()); 432 updateBufferedAmountAfterClose(arrayBufferView->byteLength());
429 return; 433 return;
430 } 434 }
431 Platform::current()->histogramEnumeration("WebCore.WebSocket.SendType", WebS ocketSendTypeArrayBufferView, WebSocketSendTypeMax); 435 recordSendTypeHistogram(WebSocketSendTypeArrayBufferView);
436
432 ASSERT(m_channel); 437 ASSERT(m_channel);
433 m_bufferedAmount += arrayBufferView->byteLength(); 438 m_bufferedAmount += arrayBufferView->byteLength();
434 m_channel->send(*arrayBufferView->buffer(), arrayBufferView->byteOffset(), a rrayBufferView->byteLength()); 439 m_channel->send(*arrayBufferView->buffer(), arrayBufferView->byteOffset(), a rrayBufferView->byteLength());
435 } 440 }
436 441
437 void DOMWebSocket::send(Blob* binaryData, ExceptionState& exceptionState) 442 void DOMWebSocket::send(Blob* binaryData, ExceptionState& exceptionState)
438 { 443 {
439 WTF_LOG(Network, "WebSocket %p send() Sending Blob '%s'", this, binaryData-> uuid().utf8().data()); 444 WTF_LOG(Network, "WebSocket %p send() Sending Blob '%s'", this, binaryData-> uuid().utf8().data());
440 ASSERT(binaryData); 445 ASSERT(binaryData);
441 if (m_state == CONNECTING) { 446 if (m_state == CONNECTING) {
442 setInvalidStateErrorForSendMethod(exceptionState); 447 setInvalidStateErrorForSendMethod(exceptionState);
443 return; 448 return;
444 } 449 }
445 if (m_state == CLOSING || m_state == CLOSED) { 450 if (m_state == CLOSING || m_state == CLOSED) {
446 updateBufferedAmountAfterClose(binaryData->size()); 451 updateBufferedAmountAfterClose(binaryData->size());
447 return; 452 return;
448 } 453 }
449 Platform::current()->histogramEnumeration("WebCore.WebSocket.SendType", WebS ocketSendTypeBlob, WebSocketSendTypeMax); 454 recordSendTypeHistogram(WebSocketSendTypeBlob);
455
450 unsigned long long size = binaryData->size(); 456 unsigned long long size = binaryData->size();
451 m_bufferedAmount += size; 457 m_bufferedAmount += size;
452 ASSERT(m_channel); 458 ASSERT(m_channel);
453 459
454 // When the runtime type of |binaryData| is File, 460 // When the runtime type of |binaryData| is File,
455 // binaryData->blobDataHandle()->size() returns -1. However, in order to 461 // binaryData->blobDataHandle()->size() returns -1. However, in order to
456 // maintain the value of |m_bufferedAmount| correctly, the WebSocket code 462 // maintain the value of |m_bufferedAmount| correctly, the WebSocket code
457 // needs to fix the size of the File at this point. For this reason, 463 // needs to fix the size of the File at this point. For this reason,
458 // construct a new BlobDataHandle here with the size that this method 464 // construct a new BlobDataHandle here with the size that this method
459 // observed. 465 // observed.
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
618 m_subprotocol = subprotocol; 624 m_subprotocol = subprotocol;
619 m_extensions = extensions; 625 m_extensions = extensions;
620 m_eventQueue->dispatch(Event::create(EventTypeNames::open)); 626 m_eventQueue->dispatch(Event::create(EventTypeNames::open));
621 } 627 }
622 628
623 void DOMWebSocket::didReceiveTextMessage(const String& msg) 629 void DOMWebSocket::didReceiveTextMessage(const String& msg)
624 { 630 {
625 WTF_LOG(Network, "WebSocket %p didReceiveTextMessage() Text message '%s'", t his, msg.utf8().data()); 631 WTF_LOG(Network, "WebSocket %p didReceiveTextMessage() Text message '%s'", t his, msg.utf8().data());
626 if (m_state != OPEN) 632 if (m_state != OPEN)
627 return; 633 return;
628 Platform::current()->histogramEnumeration("WebCore.WebSocket.ReceiveType", W ebSocketReceiveTypeString, WebSocketReceiveTypeMax); 634 recordReceiveTypeHistogram(WebSocketReceiveTypeString);
635
629 m_eventQueue->dispatch(MessageEvent::create(msg, SecurityOrigin::create(m_ur l)->toString())); 636 m_eventQueue->dispatch(MessageEvent::create(msg, SecurityOrigin::create(m_ur l)->toString()));
630 } 637 }
631 638
632 void DOMWebSocket::didReceiveBinaryMessage(PassOwnPtr<Vector<char>> binaryData) 639 void DOMWebSocket::didReceiveBinaryMessage(PassOwnPtr<Vector<char>> binaryData)
633 { 640 {
634 WTF_LOG(Network, "WebSocket %p didReceiveBinaryMessage() %lu byte binary mes sage", this, static_cast<unsigned long>(binaryData->size())); 641 WTF_LOG(Network, "WebSocket %p didReceiveBinaryMessage() %lu byte binary mes sage", this, static_cast<unsigned long>(binaryData->size()));
635 switch (m_binaryType) { 642 switch (m_binaryType) {
636 case BinaryTypeBlob: { 643 case BinaryTypeBlob: {
637 size_t size = binaryData->size(); 644 size_t size = binaryData->size();
638 RefPtr<RawData> rawData = RawData::create(); 645 RefPtr<RawData> rawData = RawData::create();
639 binaryData->swap(*rawData->mutableData()); 646 binaryData->swap(*rawData->mutableData());
640 OwnPtr<BlobData> blobData = BlobData::create(); 647 OwnPtr<BlobData> blobData = BlobData::create();
641 blobData->appendData(rawData.release(), 0, BlobDataItem::toEndOfFile); 648 blobData->appendData(rawData.release(), 0, BlobDataItem::toEndOfFile);
642 Blob* blob = Blob::create(BlobDataHandle::create(blobData.release(), siz e)); 649 Blob* blob = Blob::create(BlobDataHandle::create(blobData.release(), siz e));
643 Platform::current()->histogramEnumeration("WebCore.WebSocket.ReceiveType ", WebSocketReceiveTypeBlob, WebSocketReceiveTypeMax); 650 recordReceiveTypeHistogram(WebSocketReceiveTypeBlob);
644 m_eventQueue->dispatch(MessageEvent::create(blob, SecurityOrigin::create (m_url)->toString())); 651 m_eventQueue->dispatch(MessageEvent::create(blob, SecurityOrigin::create (m_url)->toString()));
645 break; 652 break;
646 } 653 }
647 654
648 case BinaryTypeArrayBuffer: 655 case BinaryTypeArrayBuffer:
649 RefPtr<DOMArrayBuffer> arrayBuffer = DOMArrayBuffer::create(binaryData-> data(), binaryData->size()); 656 RefPtr<DOMArrayBuffer> arrayBuffer = DOMArrayBuffer::create(binaryData-> data(), binaryData->size());
650 Platform::current()->histogramEnumeration("WebCore.WebSocket.ReceiveType ", WebSocketReceiveTypeArrayBuffer, WebSocketReceiveTypeMax); 657 recordReceiveTypeHistogram(WebSocketReceiveTypeArrayBuffer);
651 m_eventQueue->dispatch(MessageEvent::create(arrayBuffer.release(), Secur ityOrigin::create(m_url)->toString())); 658 m_eventQueue->dispatch(MessageEvent::create(arrayBuffer.release(), Secur ityOrigin::create(m_url)->toString()));
652 break; 659 break;
653 } 660 }
654 } 661 }
655 662
656 void DOMWebSocket::didError() 663 void DOMWebSocket::didError()
657 { 664 {
658 WTF_LOG(Network, "WebSocket %p didError()", this); 665 WTF_LOG(Network, "WebSocket %p didError()", this);
659 m_state = CLOSED; 666 m_state = CLOSED;
660 m_eventQueue->dispatch(Event::create(EventTypeNames::error)); 667 m_eventQueue->dispatch(Event::create(EventTypeNames::error));
(...skipping 24 matching lines...) Expand all
685 if (!m_channel) 692 if (!m_channel)
686 return; 693 return;
687 bool allDataHasBeenConsumed = m_bufferedAmount == m_consumedBufferedAmount; 694 bool allDataHasBeenConsumed = m_bufferedAmount == m_consumedBufferedAmount;
688 bool wasClean = m_state == CLOSING && allDataHasBeenConsumed && closingHands hakeCompletion == ClosingHandshakeComplete && code != WebSocketChannel::CloseEve ntCodeAbnormalClosure; 695 bool wasClean = m_state == CLOSING && allDataHasBeenConsumed && closingHands hakeCompletion == ClosingHandshakeComplete && code != WebSocketChannel::CloseEve ntCodeAbnormalClosure;
689 m_state = CLOSED; 696 m_state = CLOSED;
690 697
691 m_eventQueue->dispatch(CloseEvent::create(wasClean, code, reason)); 698 m_eventQueue->dispatch(CloseEvent::create(wasClean, code, reason));
692 releaseChannel(); 699 releaseChannel();
693 } 700 }
694 701
702 void DOMWebSocket::recordSendTypeHistogram(WebSocketSendType type)
703 {
704 DEFINE_THREAD_SAFE_STATIC_LOCAL(EnumerationHistogram, sendTypeHistogram, new EnumerationHistogram("WebCore.WebSocket.SendType", WebSocketSendTypeMax));
705 sendTypeHistogram.count(type);
706 }
707
708 void DOMWebSocket::recordReceiveTypeHistogram(WebSocketReceiveType type)
709 {
710 DEFINE_THREAD_SAFE_STATIC_LOCAL(EnumerationHistogram, receiveTypeHistogram, new EnumerationHistogram("WebCore.WebSocket.ReceiveType", WebSocketReceiveTypeMa x));
711 receiveTypeHistogram.count(type);
712 }
713
695 DEFINE_TRACE(DOMWebSocket) 714 DEFINE_TRACE(DOMWebSocket)
696 { 715 {
697 visitor->trace(m_channel); 716 visitor->trace(m_channel);
698 visitor->trace(m_eventQueue); 717 visitor->trace(m_eventQueue);
699 WebSocketChannelClient::trace(visitor); 718 WebSocketChannelClient::trace(visitor);
700 RefCountedGarbageCollectedEventTargetWithInlineData<DOMWebSocket>::trace(vis itor); 719 RefCountedGarbageCollectedEventTargetWithInlineData<DOMWebSocket>::trace(vis itor);
701 ActiveDOMObject::trace(visitor); 720 ActiveDOMObject::trace(visitor);
702 } 721 }
703 722
704 } // namespace blink 723 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698