|
|
Created:
8 years, 8 months ago by Sergey Ulanov Modified:
8 years, 8 months ago Reviewers:
Wez CC:
chromium-reviews, jamiewalch+watch_chromium.org, dcaiafa+watch_chromium.org, simonmorris+watch_chromium.org, hclam+watch_chromium.org, wez+watch_chromium.org, amit, sanjeevr, garykac+watch_chromium.org, lambroslambrou+watch_chromium.org, alexeypa+watch_chromium.org, sergeyu+watch_chromium.org Base URL:
svn://svn.chromium.org/chrome/trunk/src Visibility:
Public. |
DescriptionImplement PepperPacketSocketFactory.
Then new PepperPacketSocketFactory implements talk_base::PacketSocketFactory
based on Pepper's UDP sockets interface.
BUG=109630
Committed: http://src.chromium.org/viewvc/chrome?view=rev&revision=133859
Patch Set 1 #
Total comments: 30
Patch Set 2 : #Patch Set 3 : #Patch Set 4 : #
Total comments: 17
Patch Set 5 : #
Total comments: 6
Patch Set 6 : #
Messages
Total messages: 11 (0 generated)
http://codereview.chromium.org/10121002/diff/1/remoting/client/plugin/pepper_... File remoting/client/plugin/pepper_packet_socket_factory.cc (right): http://codereview.chromium.org/10121002/diff/1/remoting/client/plugin/pepper_... remoting/client/plugin/pepper_packet_socket_factory.cc:23: const int kMaxSendBufferSize = 256 * 1024; This is a limit on the amount of user data; the limit on the amount of memory consumed by packet buffers is much higher if the caller sends lots of small packets, and similarly the amount of data actually sent on the wire. :( http://codereview.chromium.org/10121002/diff/1/remoting/client/plugin/pepper_... remoting/client/plugin/pepper_packet_socket_factory.cc:68: pp::UDPSocketPrivate socket; socket -> socket_ http://codereview.chromium.org/10121002/diff/1/remoting/client/plugin/pepper_... remoting/client/plugin/pepper_packet_socket_factory.cc:73: talk_base::SocketAddress local_address_; Add a comment indicating that this is contains the address to bind to, or "any", until we're bound after which point it contains the bound address & port. http://codereview.chromium.org/10121002/diff/1/remoting/client/plugin/pepper_... remoting/client/plugin/pepper_packet_socket_factory.cc:75: // Used when the caller specified min_port_ and max_port_. Doesn't the caller always specify those? The key thing to get across is that these are only used during the Bind() process, when we're scanning for ports in the caller-specified range. http://codereview.chromium.org/10121002/diff/1/remoting/client/plugin/pepper_... remoting/client/plugin/pepper_packet_socket_factory.cc:76: uint16_t current_port_; nit: |current_port_| sounds like it's the port to which we're bound. You could instead just call in |min_port_|, unless you're worried that the fact it gets incremented as we scan would be confusing. Or |next_port_| (and increment earlier)? http://codereview.chromium.org/10121002/diff/1/remoting/client/plugin/pepper_... remoting/client/plugin/pepper_packet_socket_factory.cc:223: base::Unretained(this)))); Hmmm, I think we'll leak a base::Callback from PpCompletionCallback in the case where |socket| gets torn down before Bind() has completed, and similarly for the other uses of PpCompletionCallback here? http://codereview.chromium.org/10121002/diff/1/remoting/client/plugin/pepper_... remoting/client/plugin/pepper_packet_socket_factory.cc:242: // UDP sockets are not connected - this method should never be called. They _can_ be connected, in which case this and GetRemoveAddress() are both valid. http://codereview.chromium.org/10121002/diff/1/remoting/client/plugin/pepper_... remoting/client/plugin/pepper_packet_socket_factory.cc:280: return -1; nit: Add a // comment explaining this return code. http://codereview.chromium.org/10121002/diff/1/remoting/client/plugin/pepper_... remoting/client/plugin/pepper_packet_socket_factory.cc:303: base::Unretained(this)))); Is the SendTo() interface actually defined to not be callable while a previous SendTo() is still pending? Would it make sense to call SendTo() and handle the in-progress return code rather than keeping the |send_pending_| flag? http://codereview.chromium.org/10121002/diff/1/remoting/client/plugin/pepper_... remoting/client/plugin/pepper_packet_socket_factory.cc:349: SignalReadPacket(this, &receive_buffer_[0], result, address); SignalReadPacket() could trigger the caller to tear us down, so do we need to dispatch it asynchronously? http://codereview.chromium.org/10121002/diff/1/remoting/client/plugin/pepper_... remoting/client/plugin/pepper_packet_socket_factory.cc:378: // Don't use TCP sockets for remoting connections. NOTREACHED()?
http://codereview.chromium.org/10121002/diff/1/remoting/client/plugin/pepper_... File remoting/client/plugin/pepper_packet_socket_factory.cc (right): http://codereview.chromium.org/10121002/diff/1/remoting/client/plugin/pepper_... remoting/client/plugin/pepper_packet_socket_factory.cc:23: const int kMaxSendBufferSize = 256 * 1024; On 2012/04/20 21:37:07, Wez wrote: > This is a limit on the amount of user data; the limit on the amount of memory > consumed by packet buffers is much higher if the caller sends lots of small > packets, and similarly the amount of data actually sent on the wire. :( Right. I don't think it matters though. Normally that limit will never be reached, it's just here to prevent from OOM in case there is a bug in the lower layer and it stops sending data for some reason. http://codereview.chromium.org/10121002/diff/1/remoting/client/plugin/pepper_... remoting/client/plugin/pepper_packet_socket_factory.cc:68: pp::UDPSocketPrivate socket; On 2012/04/20 21:37:07, Wez wrote: > socket -> socket_ Done. http://codereview.chromium.org/10121002/diff/1/remoting/client/plugin/pepper_... remoting/client/plugin/pepper_packet_socket_factory.cc:73: talk_base::SocketAddress local_address_; On 2012/04/20 21:37:07, Wez wrote: > Add a comment indicating that this is contains the address to bind to, or "any", > until we're bound after which point it contains the bound address & port. Done. http://codereview.chromium.org/10121002/diff/1/remoting/client/plugin/pepper_... remoting/client/plugin/pepper_packet_socket_factory.cc:75: // Used when the caller specified min_port_ and max_port_. On 2012/04/20 21:37:07, Wez wrote: > Doesn't the caller always specify those? The key thing to get across is that > these are only used during the Bind() process, when we're scanning for ports in > the caller-specified range. Done. http://codereview.chromium.org/10121002/diff/1/remoting/client/plugin/pepper_... remoting/client/plugin/pepper_packet_socket_factory.cc:76: uint16_t current_port_; On 2012/04/20 21:37:07, Wez wrote: > nit: |current_port_| sounds like it's the port to which we're bound. You could > instead just call in |min_port_|, unless you're worried that the fact it gets > incremented as we scan would be confusing. Or |next_port_| (and increment > earlier)? Done. http://codereview.chromium.org/10121002/diff/1/remoting/client/plugin/pepper_... remoting/client/plugin/pepper_packet_socket_factory.cc:223: base::Unretained(this)))); On 2012/04/20 21:37:07, Wez wrote: > Hmmm, I think we'll leak a base::Callback from PpCompletionCallback in the case > where |socket| gets torn down before Bind() has completed, and similarly for the > other uses of PpCompletionCallback here? The callbacks must be invoked with PP_ERROR_ABORTED when we destroy the socket. I added Close() call in the destructor to make sure this happens while the object is still alive. http://codereview.chromium.org/10121002/diff/1/remoting/client/plugin/pepper_... remoting/client/plugin/pepper_packet_socket_factory.cc:242: // UDP sockets are not connected - this method should never be called. On 2012/04/20 21:37:07, Wez wrote: > They _can_ be connected, in which case this and GetRemoveAddress() are both > valid. UDP instances of AsyncPacketSocket are never connected, so Send() method should never be called for them. http://codereview.chromium.org/10121002/diff/1/remoting/client/plugin/pepper_... remoting/client/plugin/pepper_packet_socket_factory.cc:280: return -1; On 2012/04/20 21:37:07, Wez wrote: > nit: Add a // comment explaining this return code. Done. http://codereview.chromium.org/10121002/diff/1/remoting/client/plugin/pepper_... remoting/client/plugin/pepper_packet_socket_factory.cc:303: base::Unretained(this)))); On 2012/04/20 21:37:07, Wez wrote: > Is the SendTo() interface actually defined to not be callable while a previous > SendTo() is still pending? Would it make sense to call SendTo() and handle the > in-progress return code rather than keeping the |send_pending_| flag? Yes, SendTo() would return an error when another send is pending. Problem is that with the current implementation it would require additional IPC roundtrip to the browser and we cannot distinguish that error from other errors. Also this callback is not optional, so we get PP_OK_COMPLETIONPENDING in either case, so OnSendCompleted() would need to know what packet it's being called for. http://codereview.chromium.org/10121002/diff/1/remoting/client/plugin/pepper_... remoting/client/plugin/pepper_packet_socket_factory.cc:349: SignalReadPacket(this, &receive_buffer_[0], result, address); On 2012/04/20 21:37:07, Wez wrote: > SignalReadPacket() could trigger the caller to tear us down, so do we need to > dispatch it asynchronously? It should be safe to delete the socket from a callback. http://codereview.chromium.org/10121002/diff/1/remoting/client/plugin/pepper_... remoting/client/plugin/pepper_packet_socket_factory.cc:378: // Don't use TCP sockets for remoting connections. On 2012/04/20 21:37:07, Wez wrote: > NOTREACHED()? Done.
http://codereview.chromium.org/10121002/diff/1/remoting/client/plugin/pepper_... File remoting/client/plugin/pepper_packet_socket_factory.cc (right): http://codereview.chromium.org/10121002/diff/1/remoting/client/plugin/pepper_... remoting/client/plugin/pepper_packet_socket_factory.cc:23: const int kMaxSendBufferSize = 256 * 1024; On 2012/04/23 22:16:51, sergeyu wrote: > On 2012/04/20 21:37:07, Wez wrote: > > This is a limit on the amount of user data; the limit on the amount of memory > > consumed by packet buffers is much higher if the caller sends lots of small > > packets, and similarly the amount of data actually sent on the wire. :( > > Right. I don't think it matters though. Normally that limit will never be > reached, it's just here to prevent from OOM in case there is a bug in the lower > layer and it stops sending data for some reason. Right, so best to make it clear in the comment what the maximum is used for. http://codereview.chromium.org/10121002/diff/1/remoting/client/plugin/pepper_... remoting/client/plugin/pepper_packet_socket_factory.cc:223: base::Unretained(this)))); On 2012/04/23 22:16:51, sergeyu wrote: > On 2012/04/20 21:37:07, Wez wrote: > > Hmmm, I think we'll leak a base::Callback from PpCompletionCallback in the > case > > where |socket| gets torn down before Bind() has completed, and similarly for > the > > other uses of PpCompletionCallback here? > > The callbacks must be invoked with PP_ERROR_ABORTED when we destroy the socket. > I added Close() call in the destructor to make sure this happens while the > object is still alive. If the caller deletes this object while the socket.Bind() is pending then won't the PP_ERROR_ABORTED from the Close() call in the dtor cause a new socket.Bind() to be dispatched, to the next port number, though? http://codereview.chromium.org/10121002/diff/1/remoting/client/plugin/pepper_... remoting/client/plugin/pepper_packet_socket_factory.cc:303: base::Unretained(this)))); On 2012/04/23 22:16:51, sergeyu wrote: > On 2012/04/20 21:37:07, Wez wrote: > > Is the SendTo() interface actually defined to not be callable while a previous > > SendTo() is still pending? Would it make sense to call SendTo() and handle the > > in-progress return code rather than keeping the |send_pending_| flag? > > Yes, SendTo() would return an error when another send is pending. Problem is > that with the current implementation it would require additional IPC roundtrip > to the browser and we cannot distinguish that error from other errors. Also this > callback is not optional, so we get PP_OK_COMPLETIONPENDING in either case, so > OnSendCompleted() would need to know what packet it's being called for. Shouldn't you get PP_ERROR_IN_PROGRESS to the completion callback in the case where the previous SendTo() hasn't completed? So you'd need to base::Bind() the packet to the completion callback and push it on to send_queue_ if you saw PP_ERROR_IN_PROGRESS returned. Agreed that the extra IPC round-trip seems undesirable. http://codereview.chromium.org/10121002/diff/1/remoting/client/plugin/pepper_... remoting/client/plugin/pepper_packet_socket_factory.cc:349: SignalReadPacket(this, &receive_buffer_[0], result, address); On 2012/04/23 22:16:51, sergeyu wrote: > On 2012/04/20 21:37:07, Wez wrote: > > SignalReadPacket() could trigger the caller to tear us down, so do we need to > > dispatch it asynchronously? > > It should be safe to delete the socket from a callback. Right. So if calling code deletes us from within SignalReadPacket() in HandleReadResult(), which in turn came from OnReadCompleted(), then we'll go on to try to DoRead(), and crash?
http://codereview.chromium.org/10121002/diff/1/remoting/client/plugin/pepper_... File remoting/client/plugin/pepper_packet_socket_factory.cc (right): http://codereview.chromium.org/10121002/diff/1/remoting/client/plugin/pepper_... remoting/client/plugin/pepper_packet_socket_factory.cc:23: const int kMaxSendBufferSize = 256 * 1024; On 2012/04/25 00:01:59, Wez wrote: > On 2012/04/23 22:16:51, sergeyu wrote: > > On 2012/04/20 21:37:07, Wez wrote: > > > This is a limit on the amount of user data; the limit on the amount of > memory > > > consumed by packet buffers is much higher if the caller sends lots of small > > > packets, and similarly the amount of data actually sent on the wire. :( > > > > Right. I don't think it matters though. Normally that limit will never be > > reached, it's just here to prevent from OOM in case there is a bug in the > lower > > layer and it stops sending data for some reason. > > Right, so best to make it clear in the comment what the maximum is used for. Done. http://codereview.chromium.org/10121002/diff/1/remoting/client/plugin/pepper_... remoting/client/plugin/pepper_packet_socket_factory.cc:223: base::Unretained(this)))); On 2012/04/25 00:01:59, Wez wrote: > On 2012/04/23 22:16:51, sergeyu wrote: > > On 2012/04/20 21:37:07, Wez wrote: > > > Hmmm, I think we'll leak a base::Callback from PpCompletionCallback in the > > case > > > where |socket| gets torn down before Bind() has completed, and similarly for > > the > > > other uses of PpCompletionCallback here? > > > > The callbacks must be invoked with PP_ERROR_ABORTED when we destroy the > socket. > > I added Close() call in the destructor to make sure this happens while the > > object is still alive. > > If the caller deletes this object while the socket.Bind() is pending then won't > the PP_ERROR_ABORTED from the Close() call in the dtor cause a new socket.Bind() > to be dispatched, to the next port number, though? More recent version of OnBindCompleted() handles this case properly. http://codereview.chromium.org/10121002/diff/1/remoting/client/plugin/pepper_... remoting/client/plugin/pepper_packet_socket_factory.cc:303: base::Unretained(this)))); On 2012/04/25 00:01:59, Wez wrote: > On 2012/04/23 22:16:51, sergeyu wrote: > > On 2012/04/20 21:37:07, Wez wrote: > > > Is the SendTo() interface actually defined to not be callable while a > previous > > > SendTo() is still pending? Would it make sense to call SendTo() and handle > the > > > in-progress return code rather than keeping the |send_pending_| flag? > > > > Yes, SendTo() would return an error when another send is pending. Problem is > > that with the current implementation it would require additional IPC roundtrip > > to the browser and we cannot distinguish that error from other errors. Also > this > > callback is not optional, so we get PP_OK_COMPLETIONPENDING in either case, so > > OnSendCompleted() would need to know what packet it's being called for. > > Shouldn't you get PP_ERROR_IN_PROGRESS to the completion callback in the case > where the previous SendTo() hasn't completed? So you'd need to base::Bind() the > packet to the completion callback and push it on to send_queue_ if you saw > PP_ERROR_IN_PROGRESS returned. Agreed that the extra IPC round-trip seems > undesirable. I take this back - looks like the current UDP sockets implementation should correctly return PP_ERROR_INPROGRESS. In any case I still don't think that using it would make this code any cleaner. Currently socket.SendTo() is called in only one place. With the approach you describe it would have to be called in two places. And we need to copy the data being sent anyway because the send buffer must be alive while the SendTo() call is pending. http://codereview.chromium.org/10121002/diff/1/remoting/client/plugin/pepper_... remoting/client/plugin/pepper_packet_socket_factory.cc:349: SignalReadPacket(this, &receive_buffer_[0], result, address); On 2012/04/25 00:01:59, Wez wrote: > On 2012/04/23 22:16:51, sergeyu wrote: > > On 2012/04/20 21:37:07, Wez wrote: > > > SignalReadPacket() could trigger the caller to tear us down, so do we need > to > > > dispatch it asynchronously? > > > > It should be safe to delete the socket from a callback. > > Right. So if calling code deletes us from within SignalReadPacket() in > HandleReadResult(), which in turn came from OnReadCompleted(), then we'll go on > to try to DoRead(), and crash? ah, I see what you are talking about now. Actually signal<> handlers are not allowed to delete the object that contain the fired signal<>. That's the reason we always have to delete libjingle objects asynchronously. So we are safe here :)
http://codereview.chromium.org/10121002/diff/13001/remoting/client/plugin/pep... File remoting/client/plugin/pepper_packet_socket_factory.cc (right): http://codereview.chromium.org/10121002/diff/13001/remoting/client/plugin/pep... remoting/client/plugin/pepper_packet_socket_factory.cc:23: // prevent form out-of-memory crashes when the UDP API stops sending nit: Suggest "This prevents OOM crashes if the caller sends data faster than Pepper's UDP API can handle it." http://codereview.chromium.org/10121002/diff/13001/remoting/client/plugin/pep... remoting/client/plugin/pepper_packet_socket_factory.cc:32: // Always takes ownership of client even if initialization fails. Not sure what this means? http://codereview.chromium.org/10121002/diff/13001/remoting/client/plugin/pep... remoting/client/plugin/pepper_packet_socket_factory.cc:77: // Used to scan ports when part range is specified. Set to 0 when typo: part -> port http://codereview.chromium.org/10121002/diff/13001/remoting/client/plugin/pep... remoting/client/plugin/pepper_packet_socket_factory.cc:117: bool result; Initialize result. Surprised clang didn't catch this. http://codereview.chromium.org/10121002/diff/13001/remoting/client/plugin/pep... remoting/client/plugin/pepper_packet_socket_factory.cc:241: return local_address_; nit: Check state_? http://codereview.chromium.org/10121002/diff/13001/remoting/client/plugin/pep... remoting/client/plugin/pepper_packet_socket_factory.cc:259: if (error_ != 0) { Check the state_ here? http://codereview.chromium.org/10121002/diff/13001/remoting/client/plugin/pep... remoting/client/plugin/pepper_packet_socket_factory.cc:394: // Don't use TCP sockets for remoting connections. nit: "We don't use..." http://codereview.chromium.org/10121002/diff/13001/remoting/client/plugin/pep... remoting/client/plugin/pepper_packet_socket_factory.cc:405: // Don't use TCP sockets for remoting connections. nit: Here too. http://codereview.chromium.org/10121002/diff/13001/remoting/client/plugin/pep... File remoting/client/plugin/pepper_packet_socket_factory.h (right): http://codereview.chromium.org/10121002/diff/13001/remoting/client/plugin/pep... remoting/client/plugin/pepper_packet_socket_factory.h:13: class PepperPacketSocketFactory : public talk_base::PacketSocketFactory { There should be a short comment explaining what this class does and any limitations, e.g. not currently supporting TCP.
http://codereview.chromium.org/10121002/diff/13001/remoting/client/plugin/pep... File remoting/client/plugin/pepper_packet_socket_factory.cc (right): http://codereview.chromium.org/10121002/diff/13001/remoting/client/plugin/pep... remoting/client/plugin/pepper_packet_socket_factory.cc:23: // prevent form out-of-memory crashes when the UDP API stops sending On 2012/04/25 01:05:33, Wez wrote: > nit: Suggest "This prevents OOM crashes if the caller sends data faster than > Pepper's UDP API can handle it." Done. http://codereview.chromium.org/10121002/diff/13001/remoting/client/plugin/pep... remoting/client/plugin/pepper_packet_socket_factory.cc:32: // Always takes ownership of client even if initialization fails. On 2012/04/25 01:05:33, Wez wrote: > Not sure what this means? Removed comment - it was copy-pasted from IpcPacketSocket. http://codereview.chromium.org/10121002/diff/13001/remoting/client/plugin/pep... remoting/client/plugin/pepper_packet_socket_factory.cc:77: // Used to scan ports when part range is specified. Set to 0 when On 2012/04/25 01:05:33, Wez wrote: > typo: part -> port Done. http://codereview.chromium.org/10121002/diff/13001/remoting/client/plugin/pep... remoting/client/plugin/pepper_packet_socket_factory.cc:117: bool result; On 2012/04/25 01:05:33, Wez wrote: > Initialize result. Surprised clang didn't catch this. Done. http://codereview.chromium.org/10121002/diff/13001/remoting/client/plugin/pep... remoting/client/plugin/pepper_packet_socket_factory.cc:241: return local_address_; On 2012/04/25 01:05:33, Wez wrote: > nit: Check state_? Done. http://codereview.chromium.org/10121002/diff/13001/remoting/client/plugin/pep... remoting/client/plugin/pepper_packet_socket_factory.cc:259: if (error_ != 0) { On 2012/04/25 01:05:33, Wez wrote: > Check the state_ here? Done. http://codereview.chromium.org/10121002/diff/13001/remoting/client/plugin/pep... remoting/client/plugin/pepper_packet_socket_factory.cc:394: // Don't use TCP sockets for remoting connections. On 2012/04/25 01:05:33, Wez wrote: > nit: "We don't use..." Done. http://codereview.chromium.org/10121002/diff/13001/remoting/client/plugin/pep... remoting/client/plugin/pepper_packet_socket_factory.cc:405: // Don't use TCP sockets for remoting connections. On 2012/04/25 01:05:33, Wez wrote: > nit: Here too. Done.
LGTM w/ a couple of remaining typo nits. http://codereview.chromium.org/10121002/diff/18001/remoting/client/plugin/pep... File remoting/client/plugin/pepper_packet_socket_factory.cc (right): http://codereview.chromium.org/10121002/diff/18001/remoting/client/plugin/pep... remoting/client/plugin/pepper_packet_socket_factory.cc:23: // prevent form out-of-memory crashes if the caller sends data faster typo: Get rid of "form" http://codereview.chromium.org/10121002/diff/18001/remoting/client/plugin/pep... remoting/client/plugin/pepper_packet_socket_factory.cc:24: // than Pepper's UDP API can handle it. Normally this maximum . typo: Get rid of "Normally this maximum" http://codereview.chromium.org/10121002/diff/18001/remoting/client/plugin/pep... remoting/client/plugin/pepper_packet_socket_factory.cc:76: // Used to scan ports when port range is specified. Set to 0 when Init() requires a port range, so this comment doesn't seem valid; Init() should have a comment explaining that 0, 0 indicates no limit on the port range, if that's what we want.
http://codereview.chromium.org/10121002/diff/18001/remoting/client/plugin/pep... File remoting/client/plugin/pepper_packet_socket_factory.cc (right): http://codereview.chromium.org/10121002/diff/18001/remoting/client/plugin/pep... remoting/client/plugin/pepper_packet_socket_factory.cc:23: // prevent form out-of-memory crashes if the caller sends data faster On 2012/04/25 01:26:17, Wez wrote: > typo: Get rid of "form" Done. http://codereview.chromium.org/10121002/diff/18001/remoting/client/plugin/pep... remoting/client/plugin/pepper_packet_socket_factory.cc:24: // than Pepper's UDP API can handle it. Normally this maximum . On 2012/04/25 01:26:17, Wez wrote: > typo: Get rid of "Normally this maximum" Changed it to "This maximum should never be reached under normal conditions." http://codereview.chromium.org/10121002/diff/18001/remoting/client/plugin/pep... remoting/client/plugin/pepper_packet_socket_factory.cc:76: // Used to scan ports when port range is specified. Set to 0 when On 2012/04/25 01:26:17, Wez wrote: > Init() requires a port range, so this comment doesn't seem valid; Init() should > have a comment explaining that 0, 0 indicates no limit on the port range, if > that's what we want. by "not specified" I meant "set to 0" :) Done.
CQ is trying da patch. Follow status at https://chromium-status.appspot.com/cq/sergeyu@chromium.org/10121002/11002
Change committed as 133859 |