Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "content/renderer/p2p/socket_client_impl.h" | 5 #include "content/renderer/p2p/socket_client_impl.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/message_loop/message_loop_proxy.h" | 8 #include "base/message_loop/message_loop_proxy.h" |
| 9 #include "base/time/time.h" | 9 #include "base/time/time.h" |
| 10 #include "content/common/p2p_messages.h" | 10 #include "content/common/p2p_messages.h" |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 62 void P2PSocketClientImpl::DoInit(P2PSocketType type, | 62 void P2PSocketClientImpl::DoInit(P2PSocketType type, |
| 63 const net::IPEndPoint& local_address, | 63 const net::IPEndPoint& local_address, |
| 64 const P2PHostAndIPEndPoint& remote_address) { | 64 const P2PHostAndIPEndPoint& remote_address) { |
| 65 DCHECK_EQ(state_, STATE_UNINITIALIZED); | 65 DCHECK_EQ(state_, STATE_UNINITIALIZED); |
| 66 state_ = STATE_OPENING; | 66 state_ = STATE_OPENING; |
| 67 socket_id_ = dispatcher_->RegisterClient(this); | 67 socket_id_ = dispatcher_->RegisterClient(this); |
| 68 dispatcher_->SendP2PMessage(new P2PHostMsg_CreateSocket( | 68 dispatcher_->SendP2PMessage(new P2PHostMsg_CreateSocket( |
| 69 type, socket_id_, local_address, remote_address)); | 69 type, socket_id_, local_address, remote_address)); |
| 70 } | 70 } |
| 71 | 71 |
| 72 void P2PSocketClientImpl::SendWithDscp( | 72 uint64 P2PSocketClientImpl::SendWithDscp(const net::IPEndPoint& address, |
| 73 const net::IPEndPoint& address, | 73 const std::vector<char>& data, |
| 74 const std::vector<char>& data, | 74 const rtc::PacketOptions& options) { |
| 75 const rtc::PacketOptions& options) { | 75 uint64 unique_id = GetUniqueId(random_socket_id_, ++next_packet_id_); |
| 76 if (!ipc_message_loop_->BelongsToCurrentThread()) { | 76 if (!ipc_message_loop_->BelongsToCurrentThread()) { |
| 77 ipc_message_loop_->PostTask( | 77 ipc_message_loop_->PostTask( |
| 78 FROM_HERE, base::Bind( | 78 FROM_HERE, base::Bind(&P2PSocketClientImpl::SendWithDscpAndPacketId, |
| 79 &P2PSocketClientImpl::SendWithDscp, this, address, data, options)); | 79 this, address, data, options, unique_id)); |
| 80 return; | 80 return unique_id; |
| 81 } | 81 } |
| 82 | 82 |
| 83 // Can send data only when the socket is open. | 83 // Can send data only when the socket is open. |
| 84 DCHECK(state_ == STATE_OPEN || state_ == STATE_ERROR); | 84 DCHECK(state_ == STATE_OPEN || state_ == STATE_ERROR); |
| 85 if (state_ == STATE_OPEN) { | 85 if (state_ == STATE_OPEN) { |
| 86 uint64 unique_id = GetUniqueId(random_socket_id_, ++next_packet_id_); | 86 SendWithDscpAndPacketId(address, data, options, unique_id); |
| 87 TRACE_EVENT_ASYNC_BEGIN0("p2p", "Send", unique_id); | |
| 88 dispatcher_->SendP2PMessage(new P2PHostMsg_Send(socket_id_, address, data, | |
| 89 options, unique_id)); | |
| 90 } | 87 } |
| 88 | |
| 89 return unique_id; | |
| 90 } | |
| 91 | |
| 92 void P2PSocketClientImpl::SendWithDscpAndPacketId( | |
| 93 const net::IPEndPoint& address, | |
| 94 const std::vector<char>& data, | |
| 95 const rtc::PacketOptions& options, | |
| 96 uint64 packet_id) { | |
| 97 DCHECK_EQ(state_, STATE_OPEN); | |
|
Sergey Ulanov
2014/12/17 20:05:30
I don't think this DCHECK is valid. SendWithDscp()
guoweis_left_chromium
2014/12/22 21:41:47
Done.
| |
| 98 TRACE_EVENT_ASYNC_BEGIN0("p2p", "Send", packet_id); | |
| 99 dispatcher_->SendP2PMessage( | |
| 100 new P2PHostMsg_Send(socket_id_, address, data, options, packet_id)); | |
| 91 } | 101 } |
| 92 | 102 |
| 93 void P2PSocketClientImpl::Send(const net::IPEndPoint& address, | 103 void P2PSocketClientImpl::Send(const net::IPEndPoint& address, |
| 94 const std::vector<char>& data) { | 104 const std::vector<char>& data) { |
| 95 rtc::PacketOptions options(rtc::DSCP_DEFAULT); | 105 rtc::PacketOptions options(rtc::DSCP_DEFAULT); |
| 96 SendWithDscp(address, data, options); | 106 SendWithDscp(address, data, options); |
| 97 } | 107 } |
| 98 | 108 |
| 99 void P2PSocketClientImpl::SetOption(P2PSocketOption option, | 109 void P2PSocketClientImpl::SetOption(P2PSocketOption option, |
| 100 int value) { | 110 int value) { |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 189 scoped_refptr<P2PSocketClient> new_client) { | 199 scoped_refptr<P2PSocketClient> new_client) { |
| 190 DCHECK(delegate_message_loop_->BelongsToCurrentThread()); | 200 DCHECK(delegate_message_loop_->BelongsToCurrentThread()); |
| 191 if (delegate_) { | 201 if (delegate_) { |
| 192 delegate_->OnIncomingTcpConnection(address, new_client.get()); | 202 delegate_->OnIncomingTcpConnection(address, new_client.get()); |
| 193 } else { | 203 } else { |
| 194 // Just close the socket if there is no delegate to accept it. | 204 // Just close the socket if there is no delegate to accept it. |
| 195 new_client->Close(); | 205 new_client->Close(); |
| 196 } | 206 } |
| 197 } | 207 } |
| 198 | 208 |
| 199 void P2PSocketClientImpl::OnSendComplete() { | 209 void P2PSocketClientImpl::OnSendComplete( |
| 210 const P2PSendPacketMetrics& send_metrics) { | |
| 200 DCHECK(ipc_message_loop_->BelongsToCurrentThread()); | 211 DCHECK(ipc_message_loop_->BelongsToCurrentThread()); |
| 201 | 212 |
| 202 delegate_message_loop_->PostTask( | 213 delegate_message_loop_->PostTask( |
| 203 FROM_HERE, base::Bind(&P2PSocketClientImpl::DeliverOnSendComplete, this)); | 214 FROM_HERE, base::Bind(&P2PSocketClientImpl::DeliverOnSendComplete, this, |
| 215 send_metrics)); | |
| 204 } | 216 } |
| 205 | 217 |
| 206 void P2PSocketClientImpl::DeliverOnSendComplete() { | 218 void P2PSocketClientImpl::DeliverOnSendComplete( |
| 219 const P2PSendPacketMetrics& send_metrics) { | |
| 207 DCHECK(delegate_message_loop_->BelongsToCurrentThread()); | 220 DCHECK(delegate_message_loop_->BelongsToCurrentThread()); |
| 208 if (delegate_) | 221 if (delegate_) |
| 209 delegate_->OnSendComplete(); | 222 delegate_->OnSendComplete(send_metrics); |
| 210 } | 223 } |
| 211 | 224 |
| 212 void P2PSocketClientImpl::OnError() { | 225 void P2PSocketClientImpl::OnError() { |
| 213 DCHECK(ipc_message_loop_->BelongsToCurrentThread()); | 226 DCHECK(ipc_message_loop_->BelongsToCurrentThread()); |
| 214 state_ = STATE_ERROR; | 227 state_ = STATE_ERROR; |
| 215 | 228 |
| 216 delegate_message_loop_->PostTask( | 229 delegate_message_loop_->PostTask( |
| 217 FROM_HERE, base::Bind(&P2PSocketClientImpl::DeliverOnError, this)); | 230 FROM_HERE, base::Bind(&P2PSocketClientImpl::DeliverOnError, this)); |
| 218 } | 231 } |
| 219 | 232 |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 245 delegate_->OnDataReceived(address, data, timestamp); | 258 delegate_->OnDataReceived(address, data, timestamp); |
| 246 } | 259 } |
| 247 | 260 |
| 248 void P2PSocketClientImpl::Detach() { | 261 void P2PSocketClientImpl::Detach() { |
| 249 DCHECK(ipc_message_loop_->BelongsToCurrentThread()); | 262 DCHECK(ipc_message_loop_->BelongsToCurrentThread()); |
| 250 dispatcher_ = NULL; | 263 dispatcher_ = NULL; |
| 251 OnError(); | 264 OnError(); |
| 252 } | 265 } |
| 253 | 266 |
| 254 } // namespace content | 267 } // namespace content |
| OLD | NEW |