Bug 73290 - [WebSocket] Add didUpdateBufferedAmount() callback to SocketStreamHandleClient
Summary: [WebSocket] Add didUpdateBufferedAmount() callback to SocketStreamHandleClient
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: WebCore Misc. (show other bugs)
Version: 528+ (Nightly build)
Hardware: All All
: P2 Normal
Assignee: Takashi Toyoshima
URL:
Keywords:
Depends on:
Blocks: 73306 73308 73336 73404
  Show dependency treegraph
 
Reported: 2011-11-29 00:44 PST by Takashi Toyoshima
Modified: 2011-11-30 06:47 PST (History)
6 users (show)

See Also:


Attachments
Patch (18.22 KB, patch)
2011-11-29 00:54 PST, Takashi Toyoshima
no flags Details | Formatted Diff | Diff
Patch (13.28 KB, patch)
2011-11-29 03:54 PST, Takashi Toyoshima
no flags Details | Formatted Diff | Diff
Patch (9.29 KB, patch)
2011-11-29 04:35 PST, Takashi Toyoshima
no flags Details | Formatted Diff | Diff
Patch (15.77 KB, patch)
2011-11-29 06:05 PST, Takashi Toyoshima
no flags Details | Formatted Diff | Diff
Patch (15.77 KB, patch)
2011-11-29 11:01 PST, Takashi Toyoshima
no flags Details | Formatted Diff | Diff
Patch (15.77 KB, patch)
2011-11-29 20:22 PST, Takashi Toyoshima
no flags Details | Formatted Diff | Diff
Patch (15.78 KB, patch)
2011-11-29 21:57 PST, Takashi Toyoshima
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Takashi Toyoshima 2011-11-29 00:44:26 PST
Now, WebSocketChannel is exported as WebKit::WebSocket in Chromium port.
For now, bufferedAmount property needs some latency to get from plugins.
This callback allow client side cache its value and reduce IPC turnaround time latency.
Comment 1 Takashi Toyoshima 2011-11-29 00:54:14 PST
Created attachment 116915 [details]
Patch
Comment 2 Yuta Kitamura 2011-11-29 01:41:38 PST
Comment on attachment 116915 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=116915&action=review

> Source/WebCore/platform/network/SocketStreamHandleBase.cpp:42
> +    : m_handle(handle)

You don't have to save m_handle. As SocketStreamHandle is derived from SocketStreamHandleBase, it is safe to cast |this| to SocketStreamHandle* (i.e. static_cast<SocketStreamHandle*>(this) is always equal to |handle|). Compilers take care of offset adjustment.

> Source/WebCore/platform/network/SocketStreamHandleClient.h:49
> +        virtual void didUpdateBufferedAmount(SocketStreamHandle*, int bufferedAmount) { }

Is |int| large enough?

> Source/WebCore/platform/network/cf/SocketStreamHandleCFNet.cpp:2
> + * Copyright (C) 2011 Apple Inc.  All rights reserved.

Don't update copyright year of others.

> Source/WebCore/platform/network/curl/SocketStreamHandleCurl.cpp:2
> + * Copyright (C) 2011 Brent Fulgham.  All rights reserved.

Ditto.

> Source/WebCore/platform/network/qt/SocketStreamHandleQt.cpp:2
> + * Copyright (C) 2011 Nokia Inc. All rights reserved.

Ditto.

> Source/WebCore/platform/network/win/SocketStreamHandleWin.cpp:2
> + * Copyright (C) 2011 Brent Fulgham.  All rights reserved.

Ditto.
Comment 3 Kent Tamura 2011-11-29 01:48:44 PST
Comment on attachment 116915 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=116915&action=review

> Source/WebCore/websockets/WebSocket.h:109
> +    virtual void didUpdateBufferedAmount(int bufferedAmount);

You had better append OVERRIDE.

> Source/WebCore/websockets/WebSocketChannel.h:84
> +    virtual void didUpdateBufferedAmount(SocketStreamHandle*, int bufferedAmount);

ditto.
Comment 4 Takashi Toyoshima 2011-11-29 03:54:16 PST
Created attachment 116941 [details]
Patch
Comment 5 Takashi Toyoshima 2011-11-29 03:54:58 PST
Comment on attachment 116915 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=116915&action=review

>> Source/WebCore/platform/network/SocketStreamHandleBase.cpp:42
>> +    : m_handle(handle)
> 
> You don't have to save m_handle. As SocketStreamHandle is derived from SocketStreamHandleBase, it is safe to cast |this| to SocketStreamHandle* (i.e. static_cast<SocketStreamHandle*>(this) is always equal to |handle|). Compilers take care of offset adjustment.

Thanks Yuta!
Now, my change is quite simpler.

>> Source/WebCore/platform/network/SocketStreamHandleClient.h:49
>> +        virtual void didUpdateBufferedAmount(SocketStreamHandle*, int bufferedAmount) { }
> 
> Is |int| large enough?

Originally, SocketStreamHandleBase::bufferedAmount() returns an int value.
But, size_t seems better than int because returned value comes from Vector::size() and it returns size_t.
On the other hand, I guess I must use unsigned long in WebSocketChannelClient because WebSocketChannel::bufferedAmount returns unsigned long value.

>> Source/WebCore/platform/network/cf/SocketStreamHandleCFNet.cpp:2
>> + * Copyright (C) 2011 Apple Inc.  All rights reserved.
> 
> Don't update copyright year of others.

Thanks.
But, these update will be removed in next change because I don't have to pass this pointer from them now.

>> Source/WebCore/websockets/WebSocket.h:109
>> +    virtual void didUpdateBufferedAmount(int bufferedAmount);
> 
> You had better append OVERRIDE.

Thanks.
I added OVERRIDE to all inherit methods in WebSocket and WebSocketChannel.
Comment 6 Kent Tamura 2011-11-29 04:12:28 PST
Comment on attachment 116941 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=116941&action=review

> Source/WebCore/websockets/WebSocket.h:93
> -    virtual const AtomicString& interfaceName() const;
> -    virtual ScriptExecutionContext* scriptExecutionContext() const;
> +    virtual const AtomicString& interfaceName() const OVERRIDE;
> +    virtual ScriptExecutionContext* scriptExecutionContext() const OVERRIDE;

We had better NOT add OVERRIDE to functions other than didUpdateBufferAmount() in this patch.

> Source/WebCore/websockets/WebSocketChannelClient.h:49
> +        virtual void didUpdateBufferedAmount(unsigned long bufferedAmount) { }

Why is the argument type is unsigned long instead of size_t?
Comment 7 Takashi Toyoshima 2011-11-29 04:24:29 PST
Comment on attachment 116941 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=116941&action=review

>> Source/WebCore/websockets/WebSocket.h:93
>> +    virtual ScriptExecutionContext* scriptExecutionContext() const OVERRIDE;
> 
> We had better NOT add OVERRIDE to functions other than didUpdateBufferAmount() in this patch.

You mean adding OVERRIDE to other methods must be splited into another change?
If so, I'll make another change to add OVERRIDEs.

>> Source/WebCore/websockets/WebSocketChannelClient.h:49
>> +        virtual void didUpdateBufferedAmount(unsigned long bufferedAmount) { }
> 
> Why is the argument type is unsigned long instead of size_t?

WebSocketChannel::bufferedAmount() return unsigned long value.
That mean all interfaces exposed to WebCore::WebSocket follows the WebSocket API specification defining types.
So I decide to use unsigned long for WebSocketChannelClient to keep consistency with them.
Comment 8 Kent Tamura 2011-11-29 04:26:40 PST
Comment on attachment 116941 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=116941&action=review

>>> Source/WebCore/websockets/WebSocket.h:93
>>> +    virtual ScriptExecutionContext* scriptExecutionContext() const OVERRIDE;
>> 
>> We had better NOT add OVERRIDE to functions other than didUpdateBufferAmount() in this patch.
> 
> You mean adding OVERRIDE to other methods must be splited into another change?
> If so, I'll make another change to add OVERRIDEs.

Yes.

>>> Source/WebCore/websockets/WebSocketChannelClient.h:49
>>> +        virtual void didUpdateBufferedAmount(unsigned long bufferedAmount) { }
>> 
>> Why is the argument type is unsigned long instead of size_t?
> 
> WebSocketChannel::bufferedAmount() return unsigned long value.
> That mean all interfaces exposed to WebCore::WebSocket follows the WebSocket API specification defining types.
> So I decide to use unsigned long for WebSocketChannelClient to keep consistency with them.

Ok, I understand.
Comment 9 Takashi Toyoshima 2011-11-29 04:35:39 PST
Created attachment 116946 [details]
Patch
Comment 10 Takashi Toyoshima 2011-11-29 04:38:00 PST
Thank you Kent,
I uploaded revised one which remove all OVERRIDEs.
Comment 11 Takashi Toyoshima 2011-11-29 05:17:50 PST
Adding OVERRIDEs in another change, I notice that we must care for the worker version of WebSocket.
Please wait for the next patch which support the worker implementation.
Comment 12 Takashi Toyoshima 2011-11-29 06:05:38 PST
Created attachment 116956 [details]
Patch
Comment 13 David Levin 2011-11-29 09:02:19 PST
Comment on attachment 116956 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=116956&action=review

A few drive by comments.

> Source/WebCore/platform/network/SocketStreamHandleBase.cpp:2
> + * Copyright (C) 2011 Google Inc.  All rights reserved.

In WebKit typically just add the year (2009, 2011) as opposed to deleting the old year like what is done in Chromium.

> Source/WebCore/websockets/ThreadableWebSocketChannelClientWrapper.cpp:148
> +    m_pendingTasks.append(createCallbackTask(&ThreadableWebSocketChannelClientWrapper::didUpdateBufferedAmountCallback, AllowCrossThreadAccess(this), bufferedAmount));

You shouldn't use "AllowCrossThreadAccess" here and in fact should get rid of it throughout this file.

Here's why:
1. It was added to highlight the places where we were not doing anything to help with lifetime of the object being passed.
2. At the time it was added, ThreadSafeRefCounted* objects passed through createCallbackTask did not have the ref count increased, so AllowCrossThreadAccess needed to be added here.
3. ThreadableWebSocketChannelClientWrapper is designed to be ref counted across threads -- largely to make sure that its lifetime is preserved by this call.

So in short, putting AllowCrossThreadAccess means that ThreadableWebSocketChannelClientWrapper may get deleted before the callback is done leading to unpredictable crashes.

Feel free to create a bug that blocks: https://bugs.webkit.org/show_bug.cgi?id=67942 to get rid of AllowCrossThreadAccess in this file. (I've been wanting to do this but I also wanted to look at the files and make sure it was the right thing to do.  In this case, the patch motivated me to do so.)
Comment 14 David Levin 2011-11-29 09:03:10 PST
Comment on attachment 116956 [details]
Patch

cq- due to my comments (specifically the ref count related one).
Comment 15 Takashi Toyoshima 2011-11-29 10:56:43 PST
Comment on attachment 116956 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=116956&action=review

>> Source/WebCore/platform/network/SocketStreamHandleBase.cpp:2
>> + * Copyright (C) 2011 Google Inc.  All rights reserved.
> 
> In WebKit typically just add the year (2009, 2011) as opposed to deleting the old year like what is done in Chromium.

Thanks, I fix it in the next change.

>> Source/WebCore/websockets/ThreadableWebSocketChannelClientWrapper.cpp:148
>> +    m_pendingTasks.append(createCallbackTask(&ThreadableWebSocketChannelClientWrapper::didUpdateBufferedAmountCallback, AllowCrossThreadAccess(this), bufferedAmount));
> 
> You shouldn't use "AllowCrossThreadAccess" here and in fact should get rid of it throughout this file.
> 
> Here's why:
> 1. It was added to highlight the places where we were not doing anything to help with lifetime of the object being passed.
> 2. At the time it was added, ThreadSafeRefCounted* objects passed through createCallbackTask did not have the ref count increased, so AllowCrossThreadAccess needed to be added here.
> 3. ThreadableWebSocketChannelClientWrapper is designed to be ref counted across threads -- largely to make sure that its lifetime is preserved by this call.
> 
> So in short, putting AllowCrossThreadAccess means that ThreadableWebSocketChannelClientWrapper may get deleted before the callback is done leading to unpredictable crashes.
> 
> Feel free to create a bug that blocks: https://bugs.webkit.org/show_bug.cgi?id=67942 to get rid of AllowCrossThreadAccess in this file. (I've been wanting to do this but I also wanted to look at the files and make sure it was the right thing to do.  In this case, the patch motivated me to do so.)

OK, I see.
I created a bug https://bugs.webkit.org/show_bug.cgi?id=73336 and set to block 67942.
Comment 16 Takashi Toyoshima 2011-11-29 11:01:16 PST
Created attachment 116999 [details]
Patch
Comment 17 David Levin 2011-11-29 11:11:46 PST
(In reply to comment #15)
> (From update of attachment 116956 [details])
> OK, I see.
> I created a bug https://bugs.webkit.org/show_bug.cgi?id=73336 and set to block 67942.

PS Feel free to do it too :). (It should be trivial and hopefully fix some crashes for you.)
Comment 18 Kent Tamura 2011-11-29 18:13:28 PST
Comment on attachment 116999 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=116999&action=review

> Source/WebCore/websockets/WebSocket.cpp:510
> +    LOG(Network, "WebSocket %p didUpdateBufferedAmount %lld", this, bufferedAmount);

Why %lld for unsigned long value?
Comment 19 David Levin 2011-11-29 18:21:53 PST
Comment on attachment 116999 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=116999&action=review

> Source/WebCore/websockets/ThreadableWebSocketChannelClientWrapper.cpp:148
> +    m_pendingTasks.append(createCallbackTask(&ThreadableWebSocketChannelClientWrapper::didUpdateBufferedAmountCallback, AllowCrossThreadAccess(this), bufferedAmount));

Please remove AllowCrossThreadAccess :).
Comment 20 Takashi Toyoshima 2011-11-29 20:22:34 PST
Created attachment 117104 [details]
Patch
Comment 21 Takashi Toyoshima 2011-11-29 20:23:21 PST
Comment on attachment 116999 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=116999&action=review

>> Source/WebCore/websockets/ThreadableWebSocketChannelClientWrapper.cpp:148
>> +    m_pendingTasks.append(createCallbackTask(&ThreadableWebSocketChannelClientWrapper::didUpdateBufferedAmountCallback, AllowCrossThreadAccess(this), bufferedAmount));
> 
> Please remove AllowCrossThreadAccess :).

The change you reviewed in 73336 follows this change and will overwrite this.
I decide to split removing AllowCrossThreadAccess change to 73336.

>> Source/WebCore/websockets/WebSocket.cpp:510
>> +    LOG(Network, "WebSocket %p didUpdateBufferedAmount %lld", this, bufferedAmount);
> 
> Why %lld for unsigned long value?

Oops, sorry for careless mistake.
Comment 22 David Levin 2011-11-29 20:24:46 PST
(In reply to comment #21)
> (From update of attachment 116999 [details])
> View in context: https://bugs.webkit.org/attachment.cgi?id=116999&action=review
> 
> >> Source/WebCore/websockets/ThreadableWebSocketChannelClientWrapper.cpp:148
> >> +    m_pendingTasks.append(createCallbackTask(&ThreadableWebSocketChannelClientWrapper::didUpdateBufferedAmountCallback, AllowCrossThreadAccess(this), bufferedAmount));
> > 
> > Please remove AllowCrossThreadAccess :).
> 
> The change you reviewed in 73336 follows this change and will overwrite this.
> I decide to split removing AllowCrossThreadAccess change to 73336.

Oh, thanks. I thought it was just for existing items.... ok, I'm done here. I was just looking at some threaded related items.
Comment 23 Kent Tamura 2011-11-29 21:36:54 PST
Comment on attachment 117104 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=117104&action=review

> Source/WebCore/websockets/WebSocket.cpp:510
> +    LOG(Network, "WebSocket %p didUpdateBufferedAmount %d", this, bufferedAmount);

Why %d?  I think it should be %lu.
Comment 24 Takashi Toyoshima 2011-11-29 21:57:22 PST
Comment on attachment 117104 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=117104&action=review

> Source/WebCore/platform/network/SocketStreamHandleClient.h:3
> + * Copyright (C) 2011 Google Inc.  All rights reserved.

Fixed.

>> Source/WebCore/websockets/WebSocket.cpp:510
>> +    LOG(Network, "WebSocket %p didUpdateBufferedAmount %d", this, bufferedAmount);
> 
> Why %d?  I think it should be %lu.

Sorry for vague understanding on conversion specifiers.
I fixed it.
Comment 25 Takashi Toyoshima 2011-11-29 21:57:43 PST
Created attachment 117121 [details]
Patch
Comment 26 Kent Tamura 2011-11-29 22:02:54 PST
Comment on attachment 117121 [details]
Patch

Looks ok
Comment 27 WebKit Review Bot 2011-11-30 06:47:22 PST
Comment on attachment 117121 [details]
Patch

Clearing flags on attachment: 117121

Committed r101507: <http://trac.webkit.org/changeset/101507>
Comment 28 WebKit Review Bot 2011-11-30 06:47:29 PST
All reviewed patches have been landed.  Closing bug.