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

Side by Side Diff: trunk/Source/modules/websockets/NewWebSocketChannelImpl.cpp

Issue 338243006: Revert 176298 "[WebSocket] bufferedAmount should not decrease in..." (Closed) Base URL: svn://svn.chromium.org/blink/
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 | Annotate | Revision Log
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)
118 , m_sentSizeOfTopMessage(0) 119 , m_sentSizeOfTopMessage(0)
119 , m_sourceURLAtConstruction(sourceURL) 120 , m_sourceURLAtConstruction(sourceURL)
120 , m_lineNumberAtConstruction(lineNumber) 121 , m_lineNumberAtConstruction(lineNumber)
121 { 122 {
122 if (context->isDocument() && toDocument(context)->page()) 123 if (context->isDocument() && toDocument(context)->page())
123 m_identifier = createUniqueIdentifier(); 124 m_identifier = createUniqueIdentifier();
124 } 125 }
125 126
126 NewWebSocketChannelImpl::~NewWebSocketChannelImpl() 127 NewWebSocketChannelImpl::~NewWebSocketChannelImpl()
127 { 128 {
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
221 if (m_identifier) { 222 if (m_identifier) {
222 // FIXME: Change the inspector API to show the entire message instead 223 // FIXME: Change the inspector API to show the entire message instead
223 // of individual frames. 224 // of individual frames.
224 InspectorInstrumentation::didSendWebSocketFrame(document(), m_identifier , WebSocketFrame::OpCodeBinary, true, data->data(), data->size()); 225 InspectorInstrumentation::didSendWebSocketFrame(document(), m_identifier , WebSocketFrame::OpCodeBinary, true, data->data(), data->size());
225 } 226 }
226 m_messages.append(adoptPtr(new Message(data))); 227 m_messages.append(adoptPtr(new Message(data)));
227 sendInternal(); 228 sendInternal();
228 return SendSuccess; 229 return SendSuccess;
229 } 230 }
230 231
232 unsigned long NewWebSocketChannelImpl::bufferedAmount() const
233 {
234 WTF_LOG(Network, "NewWebSocketChannelImpl %p bufferedAmount()", this);
235 return m_bufferedAmount;
236 }
237
231 void NewWebSocketChannelImpl::close(int code, const String& reason) 238 void NewWebSocketChannelImpl::close(int code, const String& reason)
232 { 239 {
233 WTF_LOG(Network, "NewWebSocketChannelImpl %p close(%d, %s)", this, code, rea son.utf8().data()); 240 WTF_LOG(Network, "NewWebSocketChannelImpl %p close(%d, %s)", this, code, rea son.utf8().data());
234 ASSERT(m_handle); 241 ASSERT(m_handle);
235 unsigned short codeToSend = static_cast<unsigned short>(code == CloseEventCo deNotSpecified ? CloseEventCodeNoStatusRcvd : code); 242 unsigned short codeToSend = static_cast<unsigned short>(code == CloseEventCo deNotSpecified ? CloseEventCodeNoStatusRcvd : code);
236 m_handle->close(codeToSend, reason); 243 m_handle->close(codeToSend, reason);
237 } 244 }
238 245
239 void NewWebSocketChannelImpl::fail(const String& reason, MessageLevel level, con st String& sourceURL, unsigned lineNumber) 246 void NewWebSocketChannelImpl::fail(const String& reason, MessageLevel level, con st String& sourceURL, unsigned lineNumber)
240 { 247 {
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
291 : type(MessageTypeArrayBuffer) 298 : type(MessageTypeArrayBuffer)
292 , arrayBuffer(arrayBuffer) { } 299 , arrayBuffer(arrayBuffer) { }
293 300
294 NewWebSocketChannelImpl::Message::Message(PassOwnPtr<Vector<char> > vectorData) 301 NewWebSocketChannelImpl::Message::Message(PassOwnPtr<Vector<char> > vectorData)
295 : type(MessageTypeVector) 302 : type(MessageTypeVector)
296 , vectorData(vectorData) { } 303 , vectorData(vectorData) { }
297 304
298 void NewWebSocketChannelImpl::sendInternal() 305 void NewWebSocketChannelImpl::sendInternal()
299 { 306 {
300 ASSERT(m_handle); 307 ASSERT(m_handle);
301 unsigned long consumedBufferedAmount = 0; 308 unsigned long bufferedAmount = m_bufferedAmount;
302 while (!m_messages.isEmpty() && m_sendingQuota > 0 && !m_blobLoader) { 309 while (!m_messages.isEmpty() && m_sendingQuota > 0 && !m_blobLoader) {
303 bool final = false; 310 bool final = false;
304 Message* message = m_messages.first().get(); 311 Message* message = m_messages.first().get();
305 switch (message->type) { 312 switch (message->type) {
306 case MessageTypeText: { 313 case MessageTypeText: {
307 WebSocketHandle::MessageType type = 314 WebSocketHandle::MessageType type =
308 m_sentSizeOfTopMessage ? WebSocketHandle::MessageTypeContinuatio n : WebSocketHandle::MessageTypeText; 315 m_sentSizeOfTopMessage ? WebSocketHandle::MessageTypeContinuatio n : WebSocketHandle::MessageTypeText;
309 size_t size = std::min(static_cast<size_t>(m_sendingQuota), message- >text.length() - m_sentSizeOfTopMessage); 316 size_t size = std::min(static_cast<size_t>(m_sendingQuota), message- >text.length() - m_sentSizeOfTopMessage);
310 final = (m_sentSizeOfTopMessage + size == message->text.length()); 317 final = (m_sentSizeOfTopMessage + size == message->text.length());
311 m_handle->send(final, type, message->text.data() + m_sentSizeOfTopMe ssage, size); 318 m_handle->send(final, type, message->text.data() + m_sentSizeOfTopMe ssage, size);
312 m_sentSizeOfTopMessage += size; 319 m_sentSizeOfTopMessage += size;
313 m_sendingQuota -= size; 320 m_sendingQuota -= size;
314 consumedBufferedAmount += size;
315 break; 321 break;
316 } 322 }
317 case MessageTypeBlob: 323 case MessageTypeBlob:
318 ASSERT(!m_blobLoader); 324 ASSERT(!m_blobLoader);
319 m_blobLoader = adoptPtrWillBeNoop(new BlobLoader(message->blobDataHa ndle, this)); 325 m_blobLoader = adoptPtrWillBeNoop(new BlobLoader(message->blobDataHa ndle, this));
320 break; 326 break;
321 case MessageTypeArrayBuffer: { 327 case MessageTypeArrayBuffer: {
322 WebSocketHandle::MessageType type = 328 WebSocketHandle::MessageType type =
323 m_sentSizeOfTopMessage ? WebSocketHandle::MessageTypeContinuatio n : WebSocketHandle::MessageTypeBinary; 329 m_sentSizeOfTopMessage ? WebSocketHandle::MessageTypeContinuatio n : WebSocketHandle::MessageTypeBinary;
324 size_t size = std::min(static_cast<size_t>(m_sendingQuota), message- >arrayBuffer->byteLength() - m_sentSizeOfTopMessage); 330 size_t size = std::min(static_cast<size_t>(m_sendingQuota), message- >arrayBuffer->byteLength() - m_sentSizeOfTopMessage);
325 final = (m_sentSizeOfTopMessage + size == message->arrayBuffer->byte Length()); 331 final = (m_sentSizeOfTopMessage + size == message->arrayBuffer->byte Length());
326 m_handle->send(final, type, static_cast<const char*>(message->arrayB uffer->data()) + m_sentSizeOfTopMessage, size); 332 m_handle->send(final, type, static_cast<const char*>(message->arrayB uffer->data()) + m_sentSizeOfTopMessage, size);
327 m_sentSizeOfTopMessage += size; 333 m_sentSizeOfTopMessage += size;
328 m_sendingQuota -= size; 334 m_sendingQuota -= size;
329 consumedBufferedAmount += size;
330 break; 335 break;
331 } 336 }
332 case MessageTypeVector: { 337 case MessageTypeVector: {
333 WebSocketHandle::MessageType type = 338 WebSocketHandle::MessageType type =
334 m_sentSizeOfTopMessage ? WebSocketHandle::MessageTypeContinuatio n : WebSocketHandle::MessageTypeBinary; 339 m_sentSizeOfTopMessage ? WebSocketHandle::MessageTypeContinuatio n : WebSocketHandle::MessageTypeBinary;
335 size_t size = std::min(static_cast<size_t>(m_sendingQuota), message- >vectorData->size() - m_sentSizeOfTopMessage); 340 size_t size = std::min(static_cast<size_t>(m_sendingQuota), message- >vectorData->size() - m_sentSizeOfTopMessage);
336 final = (m_sentSizeOfTopMessage + size == message->vectorData->size( )); 341 final = (m_sentSizeOfTopMessage + size == message->vectorData->size( ));
337 m_handle->send(final, type, message->vectorData->data() + m_sentSize OfTopMessage, size); 342 m_handle->send(final, type, message->vectorData->data() + m_sentSize OfTopMessage, size);
338 m_sentSizeOfTopMessage += size; 343 m_sentSizeOfTopMessage += size;
339 m_sendingQuota -= size; 344 m_sendingQuota -= size;
340 consumedBufferedAmount += size;
341 break; 345 break;
342 } 346 }
343 } 347 }
344 if (final) { 348 if (final) {
345 m_messages.removeFirst(); 349 m_messages.removeFirst();
346 m_sentSizeOfTopMessage = 0; 350 m_sentSizeOfTopMessage = 0;
347 } 351 }
348 } 352 }
349 if (m_client && consumedBufferedAmount > 0) 353 if (m_client && m_bufferedAmount != bufferedAmount) {
350 m_client->didConsumeBufferedAmount(consumedBufferedAmount); 354 m_client->didUpdateBufferedAmount(m_bufferedAmount);
355 }
351 } 356 }
352 357
353 void NewWebSocketChannelImpl::flowControlIfNecessary() 358 void NewWebSocketChannelImpl::flowControlIfNecessary()
354 { 359 {
355 if (!m_handle || m_receivedDataSizeForFlowControl < receivedDataSizeForFlowC ontrolHighWaterMark) { 360 if (!m_handle || m_receivedDataSizeForFlowControl < receivedDataSizeForFlowC ontrolHighWaterMark) {
356 return; 361 return;
357 } 362 }
358 m_handle->flowControl(m_receivedDataSizeForFlowControl); 363 m_handle->flowControl(m_receivedDataSizeForFlowControl);
359 m_receivedDataSizeForFlowControl = 0; 364 m_receivedDataSizeForFlowControl = 0;
360 } 365 }
(...skipping 10 matching lines...) Expand all
371 { 376 {
372 m_handle.clear(); 377 m_handle.clear();
373 abortAsyncOperations(); 378 abortAsyncOperations();
374 if (!m_client) { 379 if (!m_client) {
375 return; 380 return;
376 } 381 }
377 WebSocketChannelClient* client = m_client; 382 WebSocketChannelClient* client = m_client;
378 m_client = 0; 383 m_client = 0;
379 WebSocketChannelClient::ClosingHandshakeCompletionStatus status = 384 WebSocketChannelClient::ClosingHandshakeCompletionStatus status =
380 wasClean ? WebSocketChannelClient::ClosingHandshakeComplete : WebSocketC hannelClient::ClosingHandshakeIncomplete; 385 wasClean ? WebSocketChannelClient::ClosingHandshakeComplete : WebSocketC hannelClient::ClosingHandshakeIncomplete;
381 client->didClose(status, code, reason); 386 client->didClose(m_bufferedAmount, status, code, reason);
382 // client->didClose may delete this object. 387 // client->didClose may delete this object.
383 } 388 }
384 389
385 Document* NewWebSocketChannelImpl::document() 390 Document* NewWebSocketChannelImpl::document()
386 { 391 {
387 ASSERT(m_identifier); 392 ASSERT(m_identifier);
388 ExecutionContext* context = executionContext(); 393 ExecutionContext* context = executionContext();
389 ASSERT(context->isDocument()); 394 ASSERT(context->isDocument());
390 return toDocument(context); 395 return toDocument(context);
391 } 396 }
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
543 // |this| can be deleted here. 548 // |this| can be deleted here.
544 } 549 }
545 550
546 void NewWebSocketChannelImpl::trace(Visitor* visitor) 551 void NewWebSocketChannelImpl::trace(Visitor* visitor)
547 { 552 {
548 visitor->trace(m_blobLoader); 553 visitor->trace(m_blobLoader);
549 WebSocketChannel::trace(visitor); 554 WebSocketChannel::trace(visitor);
550 } 555 }
551 556
552 } // namespace WebCore 557 } // namespace WebCore
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698