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

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

Issue 244923002: UMA: Count the number of WebSocket.send() call for each argument type. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Rebase Created 6 years, 8 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
« no previous file with comments | « Source/modules/websockets/WebSocket.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
44 #include "core/frame/DOMWindow.h" 44 #include "core/frame/DOMWindow.h"
45 #include "core/frame/LocalFrame.h" 45 #include "core/frame/LocalFrame.h"
46 #include "core/frame/csp/ContentSecurityPolicy.h" 46 #include "core/frame/csp/ContentSecurityPolicy.h"
47 #include "core/inspector/ScriptCallStack.h" 47 #include "core/inspector/ScriptCallStack.h"
48 #include "modules/websockets/CloseEvent.h" 48 #include "modules/websockets/CloseEvent.h"
49 #include "platform/Logging.h" 49 #include "platform/Logging.h"
50 #include "platform/blob/BlobData.h" 50 #include "platform/blob/BlobData.h"
51 #include "platform/heap/Handle.h" 51 #include "platform/heap/Handle.h"
52 #include "platform/weborigin/KnownPorts.h" 52 #include "platform/weborigin/KnownPorts.h"
53 #include "platform/weborigin/SecurityOrigin.h" 53 #include "platform/weborigin/SecurityOrigin.h"
54 #include "public/platform/Platform.h"
54 #include "wtf/ArrayBuffer.h" 55 #include "wtf/ArrayBuffer.h"
55 #include "wtf/ArrayBufferView.h" 56 #include "wtf/ArrayBufferView.h"
56 #include "wtf/HashSet.h" 57 #include "wtf/HashSet.h"
57 #include "wtf/PassOwnPtr.h" 58 #include "wtf/PassOwnPtr.h"
58 #include "wtf/StdLibExtras.h" 59 #include "wtf/StdLibExtras.h"
59 #include "wtf/text/CString.h" 60 #include "wtf/text/CString.h"
60 #include "wtf/text/StringBuilder.h" 61 #include "wtf/text/StringBuilder.h"
61 #include "wtf/text/WTFString.h" 62 #include "wtf/text/WTFString.h"
62 63
63 using namespace std; 64 using namespace std;
(...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after
349 } 350 }
350 } 351 }
351 352
352 String protocolString; 353 String protocolString;
353 if (!protocols.isEmpty()) 354 if (!protocols.isEmpty())
354 protocolString = joinStrings(protocols, subProtocolSeperator()); 355 protocolString = joinStrings(protocols, subProtocolSeperator());
355 356
356 m_channel->connect(m_url, protocolString); 357 m_channel->connect(m_url, protocolString);
357 } 358 }
358 359
359 void WebSocket::handleSendResult(WebSocketChannel::SendResult result, ExceptionS tate& exceptionState) 360 void WebSocket::handleSendResult(WebSocketChannel::SendResult result, ExceptionS tate& exceptionState, WebSocketSendType dataType)
360 { 361 {
361 switch (result) { 362 switch (result) {
362 case WebSocketChannel::InvalidMessage: 363 case WebSocketChannel::InvalidMessage:
363 exceptionState.throwDOMException(SyntaxError, "The message contains inva lid characters."); 364 exceptionState.throwDOMException(SyntaxError, "The message contains inva lid characters.");
364 return; 365 return;
365 case WebSocketChannel::SendFail: 366 case WebSocketChannel::SendFail:
366 logError("WebSocket send() failed."); 367 logError("WebSocket send() failed.");
367 return; 368 return;
368 case WebSocketChannel::SendSuccess: 369 case WebSocketChannel::SendSuccess:
370 blink::Platform::current()->histogramEnumeration("WebCore.WebSocket.Send Type", dataType, WebSocketSendTypeMax);
369 return; 371 return;
370 } 372 }
371 ASSERT_NOT_REACHED(); 373 ASSERT_NOT_REACHED();
372 } 374 }
373 375
374 void WebSocket::updateBufferedAmountAfterClose(unsigned long payloadSize) 376 void WebSocket::updateBufferedAmountAfterClose(unsigned long payloadSize)
375 { 377 {
376 m_bufferedAmountAfterClose = saturateAdd(m_bufferedAmountAfterClose, payload Size); 378 m_bufferedAmountAfterClose = saturateAdd(m_bufferedAmountAfterClose, payload Size);
377 m_bufferedAmountAfterClose = saturateAdd(m_bufferedAmountAfterClose, getFram ingOverhead(payloadSize)); 379 m_bufferedAmountAfterClose = saturateAdd(m_bufferedAmountAfterClose, getFram ingOverhead(payloadSize));
378 380
(...skipping 13 matching lines...) Expand all
392 if (m_state == CONNECTING) { 394 if (m_state == CONNECTING) {
393 setInvalidStateErrorForSendMethod(exceptionState); 395 setInvalidStateErrorForSendMethod(exceptionState);
394 return; 396 return;
395 } 397 }
396 // No exception is raised if the connection was once established but has sub sequently been closed. 398 // No exception is raised if the connection was once established but has sub sequently been closed.
397 if (m_state == CLOSING || m_state == CLOSED) { 399 if (m_state == CLOSING || m_state == CLOSED) {
398 updateBufferedAmountAfterClose(message.utf8().length()); 400 updateBufferedAmountAfterClose(message.utf8().length());
399 return; 401 return;
400 } 402 }
401 ASSERT(m_channel); 403 ASSERT(m_channel);
402 handleSendResult(m_channel->send(message), exceptionState); 404 handleSendResult(m_channel->send(message), exceptionState, WebSocketSendType String);
403 } 405 }
404 406
405 void WebSocket::send(ArrayBuffer* binaryData, ExceptionState& exceptionState) 407 void WebSocket::send(ArrayBuffer* binaryData, ExceptionState& exceptionState)
406 { 408 {
407 WTF_LOG(Network, "WebSocket %p send() Sending ArrayBuffer %p", this, binaryD ata); 409 WTF_LOG(Network, "WebSocket %p send() Sending ArrayBuffer %p", this, binaryD ata);
408 ASSERT(binaryData); 410 ASSERT(binaryData);
409 if (m_state == CONNECTING) { 411 if (m_state == CONNECTING) {
410 setInvalidStateErrorForSendMethod(exceptionState); 412 setInvalidStateErrorForSendMethod(exceptionState);
411 return; 413 return;
412 } 414 }
413 if (m_state == CLOSING || m_state == CLOSED) { 415 if (m_state == CLOSING || m_state == CLOSED) {
414 updateBufferedAmountAfterClose(binaryData->byteLength()); 416 updateBufferedAmountAfterClose(binaryData->byteLength());
415 return; 417 return;
416 } 418 }
417 ASSERT(m_channel); 419 ASSERT(m_channel);
418 handleSendResult(m_channel->send(*binaryData, 0, binaryData->byteLength()), exceptionState); 420 handleSendResult(m_channel->send(*binaryData, 0, binaryData->byteLength()), exceptionState, WebSocketSendTypeArrayBuffer);
419 } 421 }
420 422
421 void WebSocket::send(ArrayBufferView* arrayBufferView, ExceptionState& exception State) 423 void WebSocket::send(ArrayBufferView* arrayBufferView, ExceptionState& exception State)
422 { 424 {
423 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);
424 ASSERT(arrayBufferView); 426 ASSERT(arrayBufferView);
425 if (m_state == CONNECTING) { 427 if (m_state == CONNECTING) {
426 setInvalidStateErrorForSendMethod(exceptionState); 428 setInvalidStateErrorForSendMethod(exceptionState);
427 return; 429 return;
428 } 430 }
429 if (m_state == CLOSING || m_state == CLOSED) { 431 if (m_state == CLOSING || m_state == CLOSED) {
430 updateBufferedAmountAfterClose(arrayBufferView->byteLength()); 432 updateBufferedAmountAfterClose(arrayBufferView->byteLength());
431 return; 433 return;
432 } 434 }
433 ASSERT(m_channel); 435 ASSERT(m_channel);
434 RefPtr<ArrayBuffer> arrayBuffer(arrayBufferView->buffer()); 436 RefPtr<ArrayBuffer> arrayBuffer(arrayBufferView->buffer());
435 handleSendResult(m_channel->send(*arrayBuffer, arrayBufferView->byteOffset() , arrayBufferView->byteLength()), exceptionState); 437 handleSendResult(m_channel->send(*arrayBuffer, arrayBufferView->byteOffset() , arrayBufferView->byteLength()), exceptionState, WebSocketSendTypeArrayBufferVi ew);
436 } 438 }
437 439
438 void WebSocket::send(Blob* binaryData, ExceptionState& exceptionState) 440 void WebSocket::send(Blob* binaryData, ExceptionState& exceptionState)
439 { 441 {
440 WTF_LOG(Network, "WebSocket %p send() Sending Blob '%s'", this, binaryData-> uuid().utf8().data()); 442 WTF_LOG(Network, "WebSocket %p send() Sending Blob '%s'", this, binaryData-> uuid().utf8().data());
441 ASSERT(binaryData); 443 ASSERT(binaryData);
442 if (m_state == CONNECTING) { 444 if (m_state == CONNECTING) {
443 setInvalidStateErrorForSendMethod(exceptionState); 445 setInvalidStateErrorForSendMethod(exceptionState);
444 return; 446 return;
445 } 447 }
446 if (m_state == CLOSING || m_state == CLOSED) { 448 if (m_state == CLOSING || m_state == CLOSED) {
447 updateBufferedAmountAfterClose(static_cast<unsigned long>(binaryData->si ze())); 449 updateBufferedAmountAfterClose(static_cast<unsigned long>(binaryData->si ze()));
448 return; 450 return;
449 } 451 }
450 ASSERT(m_channel); 452 ASSERT(m_channel);
451 handleSendResult(m_channel->send(binaryData->blobDataHandle()), exceptionSta te); 453 handleSendResult(m_channel->send(binaryData->blobDataHandle()), exceptionSta te, WebSocketSendTypeBlob);
452 } 454 }
453 455
454 void WebSocket::close(unsigned short code, const String& reason, ExceptionState& exceptionState) 456 void WebSocket::close(unsigned short code, const String& reason, ExceptionState& exceptionState)
455 { 457 {
456 closeInternal(code, reason, exceptionState); 458 closeInternal(code, reason, exceptionState);
457 } 459 }
458 460
459 void WebSocket::close(ExceptionState& exceptionState) 461 void WebSocket::close(ExceptionState& exceptionState)
460 { 462 {
461 closeInternal(WebSocketChannel::CloseEventCodeNotSpecified, String(), except ionState); 463 closeInternal(WebSocketChannel::CloseEventCodeNotSpecified, String(), except ionState);
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after
674 static const size_t minimumPayloadSizeWithEightByteExtendedPayloadLength = 0 x10000; 676 static const size_t minimumPayloadSizeWithEightByteExtendedPayloadLength = 0 x10000;
675 size_t overhead = hybiBaseFramingOverhead + hybiMaskingKeyLength; 677 size_t overhead = hybiBaseFramingOverhead + hybiMaskingKeyLength;
676 if (payloadSize >= minimumPayloadSizeWithEightByteExtendedPayloadLength) 678 if (payloadSize >= minimumPayloadSizeWithEightByteExtendedPayloadLength)
677 overhead += 8; 679 overhead += 8;
678 else if (payloadSize >= minimumPayloadSizeWithTwoByteExtendedPayloadLength) 680 else if (payloadSize >= minimumPayloadSizeWithTwoByteExtendedPayloadLength)
679 overhead += 2; 681 overhead += 2;
680 return overhead; 682 return overhead;
681 } 683 }
682 684
683 } // namespace WebCore 685 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/modules/websockets/WebSocket.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698