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 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 void P2PSocketClientImpl::SendWithDscp( |
73 const net::IPEndPoint& address, | 73 const net::IPEndPoint& address, |
74 const std::vector<char>& data, | 74 const std::vector<char>& data, |
75 const talk_base::PacketOptions& options) { | 75 const rtc::PacketOptions& options) { |
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( |
79 &P2PSocketClientImpl::SendWithDscp, this, address, data, options)); | 79 &P2PSocketClientImpl::SendWithDscp, this, address, data, options)); |
80 return; | 80 return; |
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 uint64 unique_id = GetUniqueId(random_socket_id_, ++next_packet_id_); |
87 TRACE_EVENT_ASYNC_BEGIN0("p2p", "Send", unique_id); | 87 TRACE_EVENT_ASYNC_BEGIN0("p2p", "Send", unique_id); |
88 dispatcher_->SendP2PMessage(new P2PHostMsg_Send(socket_id_, address, data, | 88 dispatcher_->SendP2PMessage(new P2PHostMsg_Send(socket_id_, address, data, |
89 options, unique_id)); | 89 options, unique_id)); |
90 } | 90 } |
91 } | 91 } |
92 | 92 |
93 void P2PSocketClientImpl::Send(const net::IPEndPoint& address, | 93 void P2PSocketClientImpl::Send(const net::IPEndPoint& address, |
94 const std::vector<char>& data) { | 94 const std::vector<char>& data) { |
95 talk_base::PacketOptions options(talk_base::DSCP_DEFAULT); | 95 rtc::PacketOptions options(rtc::DSCP_DEFAULT); |
96 SendWithDscp(address, data, options); | 96 SendWithDscp(address, data, options); |
97 } | 97 } |
98 | 98 |
99 void P2PSocketClientImpl::SetOption(P2PSocketOption option, | 99 void P2PSocketClientImpl::SetOption(P2PSocketOption option, |
100 int value) { | 100 int value) { |
101 if (!ipc_message_loop_->BelongsToCurrentThread()) { | 101 if (!ipc_message_loop_->BelongsToCurrentThread()) { |
102 ipc_message_loop_->PostTask( | 102 ipc_message_loop_->PostTask( |
103 FROM_HERE, base::Bind( | 103 FROM_HERE, base::Bind( |
104 &P2PSocketClientImpl::SetOption, this, option, value)); | 104 &P2PSocketClientImpl::SetOption, this, option, value)); |
105 return; | 105 return; |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
245 delegate_->OnDataReceived(address, data, timestamp); | 245 delegate_->OnDataReceived(address, data, timestamp); |
246 } | 246 } |
247 | 247 |
248 void P2PSocketClientImpl::Detach() { | 248 void P2PSocketClientImpl::Detach() { |
249 DCHECK(ipc_message_loop_->BelongsToCurrentThread()); | 249 DCHECK(ipc_message_loop_->BelongsToCurrentThread()); |
250 dispatcher_ = NULL; | 250 dispatcher_ = NULL; |
251 OnError(); | 251 OnError(); |
252 } | 252 } |
253 | 253 |
254 } // namespace content | 254 } // namespace content |
OLD | NEW |