| 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 "content/common/p2p_messages.h" | 9 #include "content/common/p2p_messages.h" |
| 10 #include "content/renderer/p2p/socket_client_delegate.h" | 10 #include "content/renderer/p2p/socket_client_delegate.h" |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 75 DCHECK(delegate_); | 75 DCHECK(delegate_); |
| 76 state_ = STATE_OPENING; | 76 state_ = STATE_OPENING; |
| 77 socket_id_ = dispatcher_->RegisterClient(this); | 77 socket_id_ = dispatcher_->RegisterClient(this); |
| 78 dispatcher_->SendP2PMessage(new P2PHostMsg_CreateSocket( | 78 dispatcher_->SendP2PMessage(new P2PHostMsg_CreateSocket( |
| 79 type, socket_id_, local_address, remote_address)); | 79 type, socket_id_, local_address, remote_address)); |
| 80 } | 80 } |
| 81 | 81 |
| 82 void P2PSocketClientImpl::SendWithDscp( | 82 void P2PSocketClientImpl::SendWithDscp( |
| 83 const net::IPEndPoint& address, | 83 const net::IPEndPoint& address, |
| 84 const std::vector<char>& data, | 84 const std::vector<char>& data, |
| 85 net::DiffServCodePoint dscp) { | 85 const talk_base::PacketOptions& options) { |
| 86 if (!ipc_message_loop_->BelongsToCurrentThread()) { | 86 if (!ipc_message_loop_->BelongsToCurrentThread()) { |
| 87 ipc_message_loop_->PostTask( | 87 ipc_message_loop_->PostTask( |
| 88 FROM_HERE, base::Bind( | 88 FROM_HERE, base::Bind( |
| 89 &P2PSocketClientImpl::SendWithDscp, this, address, data, dscp)); | 89 &P2PSocketClientImpl::SendWithDscp, this, address, data, options)); |
| 90 return; | 90 return; |
| 91 } | 91 } |
| 92 | 92 |
| 93 // Can send data only when the socket is open. | 93 // Can send data only when the socket is open. |
| 94 DCHECK(state_ == STATE_OPEN || state_ == STATE_ERROR); | 94 DCHECK(state_ == STATE_OPEN || state_ == STATE_ERROR); |
| 95 if (state_ == STATE_OPEN) { | 95 if (state_ == STATE_OPEN) { |
| 96 uint64 unique_id = GetUniqueId(random_socket_id_, ++next_packet_id_); | 96 uint64 unique_id = GetUniqueId(random_socket_id_, ++next_packet_id_); |
| 97 TRACE_EVENT_ASYNC_BEGIN0("p2p", "Send", unique_id); | 97 TRACE_EVENT_ASYNC_BEGIN0("p2p", "Send", unique_id); |
| 98 dispatcher_->SendP2PMessage(new P2PHostMsg_Send(socket_id_, address, data, | 98 dispatcher_->SendP2PMessage(new P2PHostMsg_Send(socket_id_, address, data, |
| 99 dscp, unique_id)); | 99 options, unique_id)); |
| 100 } | 100 } |
| 101 } | 101 } |
| 102 | 102 |
| 103 void P2PSocketClientImpl::Send(const net::IPEndPoint& address, | 103 void P2PSocketClientImpl::Send(const net::IPEndPoint& address, |
| 104 const std::vector<char>& data) { | 104 const std::vector<char>& data) { |
| 105 SendWithDscp(address, data, net::DSCP_DEFAULT); | 105 talk_base::PacketOptions options(talk_base::DSCP_DEFAULT); |
| 106 SendWithDscp(address, data, options); |
| 106 } | 107 } |
| 107 | 108 |
| 108 void P2PSocketClientImpl::SetOption(P2PSocketOption option, | 109 void P2PSocketClientImpl::SetOption(P2PSocketOption option, |
| 109 int value) { | 110 int value) { |
| 110 if (!ipc_message_loop_->BelongsToCurrentThread()) { | 111 if (!ipc_message_loop_->BelongsToCurrentThread()) { |
| 111 ipc_message_loop_->PostTask( | 112 ipc_message_loop_->PostTask( |
| 112 FROM_HERE, base::Bind( | 113 FROM_HERE, base::Bind( |
| 113 &P2PSocketClientImpl::SetOption, this, option, value)); | 114 &P2PSocketClientImpl::SetOption, this, option, value)); |
| 114 return; | 115 return; |
| 115 } | 116 } |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 250 delegate_->OnDataReceived(address, data, timestamp); | 251 delegate_->OnDataReceived(address, data, timestamp); |
| 251 } | 252 } |
| 252 | 253 |
| 253 void P2PSocketClientImpl::Detach() { | 254 void P2PSocketClientImpl::Detach() { |
| 254 DCHECK(ipc_message_loop_->BelongsToCurrentThread()); | 255 DCHECK(ipc_message_loop_->BelongsToCurrentThread()); |
| 255 dispatcher_ = NULL; | 256 dispatcher_ = NULL; |
| 256 OnError(); | 257 OnError(); |
| 257 } | 258 } |
| 258 | 259 |
| 259 } // namespace content | 260 } // namespace content |
| OLD | NEW |