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

Unified Diff: content/renderer/p2p/ipc_socket_factory.cc

Issue 13584008: Send notification about outgoing p2p packets from browser to renderer. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 9 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « content/common/p2p_messages.h ('k') | content/renderer/p2p/socket_client.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/renderer/p2p/ipc_socket_factory.cc
diff --git a/content/renderer/p2p/ipc_socket_factory.cc b/content/renderer/p2p/ipc_socket_factory.cc
index ea53678fd76c935865a77e35ce887c16ea03dc33..cf38da15c180b39a8b84ed7194e20353c809230b 100644
--- a/content/renderer/p2p/ipc_socket_factory.cc
+++ b/content/renderer/p2p/ipc_socket_factory.cc
@@ -16,6 +16,10 @@ namespace content {
namespace {
+// TODO(sergeyu): Try adjusting these parameters to achieve optimal performance.
+const int kMaxPendingPackets = 8;
+const int kWritableSignalThreshold = 0;
+
// IpcPacketSocket implements talk_base::AsyncPacketSocket interface
// using P2PSocketClient that works over IPC-channel. It must be used
// on the thread it was created.
@@ -47,6 +51,7 @@ class IpcPacketSocket : public talk_base::AsyncPacketSocket,
virtual void OnOpen(const net::IPEndPoint& address) OVERRIDE;
virtual void OnIncomingTcpConnection(const net::IPEndPoint& address,
P2PSocketClient* client) OVERRIDE;
+ virtual void OnSendComplete() OVERRIDE;
virtual void OnError() OVERRIDE;
virtual void OnDataReceived(const net::IPEndPoint& address,
const std::vector<char>& data) OVERRIDE;
@@ -83,6 +88,14 @@ class IpcPacketSocket : public talk_base::AsyncPacketSocket,
// Current state of the object.
InternalState state_;
+ // Number which have been sent to the browser, but for which we haven't
+ // received response.
+ int send_packets_pending_;
+
+ // Set to true once EWOULDBLOCK was returned from Send(). Indicates that the
+ // caller expects SignalWritable notification.
+ bool writable_signal_expected_;
+
// Current error code. Valid when state_ == IS_ERROR.
int error_;
@@ -93,6 +106,8 @@ IpcPacketSocket::IpcPacketSocket()
: type_(P2P_SOCKET_UDP),
message_loop_(MessageLoop::current()),
state_(IS_UNINITIALIZED),
+ send_packets_pending_(0),
+ writable_signal_expected_(false),
error_(0) {
}
@@ -180,6 +195,11 @@ int IpcPacketSocket::SendTo(const void *data, size_t data_size,
break;
}
+ if (send_packets_pending_ > kMaxPendingPackets) {
+ writable_signal_expected_ = true;
+ return EWOULDBLOCK;
Ronghua Wu (Left Chromium) 2013/04/04 23:53:02 Justin, you mentioned in my cl that you want somet
Ronghua Wu (Left Chromium) 2013/04/05 17:56:04 Should we set error_ to EWOULDBLOCK? IOW, should t
Sergey Ulanov 2013/04/05 21:04:03 That's a good point. I think we should return -1 h
+ }
+
const char* data_char = reinterpret_cast<const char*>(data);
std::vector<char> data_vector(data_char, data_char + data_size);
@@ -189,6 +209,7 @@ int IpcPacketSocket::SendTo(const void *data, size_t data_size,
return 0;
}
+ ++send_packets_pending_;
client_->Send(address_chrome, data_vector);
// Fake successful send. The caller ignores result anyway.
@@ -238,9 +259,6 @@ int IpcPacketSocket::GetOption(talk_base::Socket::Option opt, int* value) {
int IpcPacketSocket::SetOption(talk_base::Socket::Option opt, int value) {
// We don't support socket options for IPC sockets.
- //
- // TODO(sergeyu): Make sure we set proper socket options on the
- // browser side.
return -1;
}
@@ -287,6 +305,22 @@ void IpcPacketSocket::OnIncomingTcpConnection(
SignalNewConnection(this, socket.release());
}
+void IpcPacketSocket::OnSendComplete() {
+ DCHECK_EQ(MessageLoop::current(), message_loop_);
+
+ --send_packets_pending_;
+ DCHECK_GE(send_packets_pending_, 0);
+
+ if (writable_signal_expected_ &&
+ send_packets_pending_ <= kWritableSignalThreshold) {
+ // TODO(sergeyu): Uncomment this line once SignalWritable is added in
+ // talk_base::AsyncPacketSocket.
+ //
+ // SignalWritable(this);
+ writable_signal_expected_ = false;
+ }
+}
+
void IpcPacketSocket::OnError() {
DCHECK_EQ(MessageLoop::current(), message_loop_);
state_ = IS_ERROR;
« no previous file with comments | « content/common/p2p_messages.h ('k') | content/renderer/p2p/socket_client.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698