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

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 int64_t quota = m_sendingQuota;
tyoshino (SeeGerritForStatus) 2014/06/16 02:29:29 quota and bufferedAmount are different concept. as
yhirano 2014/06/16 04:44:27 Done.
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);
(...skipping 24 matching lines...) Expand all
355 m_sentSizeOfTopMessage += size; 348 m_sentSizeOfTopMessage += size;
356 m_sendingQuota -= size; 349 m_sendingQuota -= size;
357 break; 350 break;
358 } 351 }
359 } 352 }
360 if (final) { 353 if (final) {
361 m_messages.removeFirst(); 354 m_messages.removeFirst();
362 m_sentSizeOfTopMessage = 0; 355 m_sentSizeOfTopMessage = 0;
363 } 356 }
364 } 357 }
365 if (m_client && m_bufferedAmount != bufferedAmount) { 358 if (m_client && quota != m_sendingQuota) {
366 m_client->didUpdateBufferedAmount(m_bufferedAmount); 359 unsigned long diff = quota - m_sendingQuota;
360 m_client->didConsumeBufferedAmount(diff);
367 } 361 }
368 } 362 }
369 363
370 void NewWebSocketChannelImpl::flowControlIfNecessary() 364 void NewWebSocketChannelImpl::flowControlIfNecessary()
371 { 365 {
372 if (!m_handle || m_receivedDataSizeForFlowControl < receivedDataSizeForFlowC ontrolHighWaterMark) { 366 if (!m_handle || m_receivedDataSizeForFlowControl < receivedDataSizeForFlowC ontrolHighWaterMark) {
373 return; 367 return;
374 } 368 }
375 m_handle->flowControl(m_receivedDataSizeForFlowControl); 369 m_handle->flowControl(m_receivedDataSizeForFlowControl);
376 m_receivedDataSizeForFlowControl = 0; 370 m_receivedDataSizeForFlowControl = 0;
(...skipping 11 matching lines...) Expand all
388 { 382 {
389 m_handle.clear(); 383 m_handle.clear();
390 abortAsyncOperations(); 384 abortAsyncOperations();
391 if (!m_client) { 385 if (!m_client) {
392 return; 386 return;
393 } 387 }
394 WebSocketChannelClient* client = m_client; 388 WebSocketChannelClient* client = m_client;
395 m_client = 0; 389 m_client = 0;
396 WebSocketChannelClient::ClosingHandshakeCompletionStatus status = 390 WebSocketChannelClient::ClosingHandshakeCompletionStatus status =
397 wasClean ? WebSocketChannelClient::ClosingHandshakeComplete : WebSocketC hannelClient::ClosingHandshakeIncomplete; 391 wasClean ? WebSocketChannelClient::ClosingHandshakeComplete : WebSocketC hannelClient::ClosingHandshakeIncomplete;
398 client->didClose(m_bufferedAmount, status, code, reason); 392 client->didClose(status, code, reason);
399 // client->didClose may delete this object. 393 // client->didClose may delete this object.
400 } 394 }
401 395
402 Document* NewWebSocketChannelImpl::document() 396 Document* NewWebSocketChannelImpl::document()
403 { 397 {
404 ASSERT(m_identifier); 398 ASSERT(m_identifier);
405 ExecutionContext* context = executionContext(); 399 ExecutionContext* context = executionContext();
406 ASSERT(context->isDocument()); 400 ASSERT(context->isDocument());
407 return toDocument(context); 401 return toDocument(context);
408 } 402 }
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
562 // |this| can be deleted here. 556 // |this| can be deleted here.
563 } 557 }
564 558
565 void NewWebSocketChannelImpl::trace(Visitor* visitor) 559 void NewWebSocketChannelImpl::trace(Visitor* visitor)
566 { 560 {
567 visitor->trace(m_blobLoader); 561 visitor->trace(m_blobLoader);
568 WebSocketChannel::trace(visitor); 562 WebSocketChannel::trace(visitor);
569 } 563 }
570 564
571 } // namespace WebCore 565 } // namespace WebCore
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698