| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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.h" | 5 #include "content/renderer/p2p/socket_client.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_dispatcher.h" | 10 #include "content/renderer/p2p/socket_dispatcher.h" |
| (...skipping 30 matching lines...) Expand all Loading... |
| 41 const net::IPEndPoint& local_address, | 41 const net::IPEndPoint& local_address, |
| 42 const net::IPEndPoint& remote_address) { | 42 const net::IPEndPoint& remote_address) { |
| 43 DCHECK_EQ(state_, STATE_UNINITIALIZED); | 43 DCHECK_EQ(state_, STATE_UNINITIALIZED); |
| 44 DCHECK(delegate_); | 44 DCHECK(delegate_); |
| 45 state_ = STATE_OPENING; | 45 state_ = STATE_OPENING; |
| 46 socket_id_ = dispatcher_->RegisterClient(this); | 46 socket_id_ = dispatcher_->RegisterClient(this); |
| 47 dispatcher_->SendP2PMessage(new P2PHostMsg_CreateSocket( | 47 dispatcher_->SendP2PMessage(new P2PHostMsg_CreateSocket( |
| 48 type, socket_id_, local_address, remote_address)); | 48 type, socket_id_, local_address, remote_address)); |
| 49 } | 49 } |
| 50 | 50 |
| 51 void P2PSocketClient::Send(const net::IPEndPoint& address, | 51 void P2PSocketClient::SendWithDscp( |
| 52 const std::vector<char>& data) { | 52 const net::IPEndPoint& address, |
| 53 const std::vector<char>& data, |
| 54 net::DiffServCodePoint dscp) { |
| 53 if (!ipc_message_loop_->BelongsToCurrentThread()) { | 55 if (!ipc_message_loop_->BelongsToCurrentThread()) { |
| 54 ipc_message_loop_->PostTask( | 56 ipc_message_loop_->PostTask( |
| 55 FROM_HERE, base::Bind(&P2PSocketClient::Send, this, address, data)); | 57 FROM_HERE, base::Bind(&P2PSocketClient::Send, this, address, data)); |
| 56 return; | 58 return; |
| 57 } | 59 } |
| 58 | 60 |
| 59 // Can send data only when the socket is open. | 61 // Can send data only when the socket is open. |
| 60 DCHECK(state_ == STATE_OPEN || state_ == STATE_ERROR); | 62 DCHECK(state_ == STATE_OPEN || state_ == STATE_ERROR); |
| 61 if (state_ == STATE_OPEN) { | 63 if (state_ == STATE_OPEN) { |
| 62 dispatcher_->SendP2PMessage(new P2PHostMsg_Send(socket_id_, address, data)); | 64 dispatcher_->SendP2PMessage( |
| 65 new P2PHostMsg_Send(socket_id_, address, data, dscp)); |
| 63 } | 66 } |
| 64 } | 67 } |
| 65 | 68 |
| 69 void P2PSocketClient::Send(const net::IPEndPoint& address, |
| 70 const std::vector<char>& data) { |
| 71 SendWithDscp(address, data, net::DSCP_NO_CHANGE); |
| 72 } |
| 73 |
| 66 void P2PSocketClient::Close() { | 74 void P2PSocketClient::Close() { |
| 67 DCHECK(delegate_message_loop_->BelongsToCurrentThread()); | 75 DCHECK(delegate_message_loop_->BelongsToCurrentThread()); |
| 68 | 76 |
| 69 delegate_ = NULL; | 77 delegate_ = NULL; |
| 70 | 78 |
| 71 ipc_message_loop_->PostTask( | 79 ipc_message_loop_->PostTask( |
| 72 FROM_HERE, base::Bind(&P2PSocketClient::DoClose, this)); | 80 FROM_HERE, base::Bind(&P2PSocketClient::DoClose, this)); |
| 73 } | 81 } |
| 74 | 82 |
| 75 void P2PSocketClient::DoClose() { | 83 void P2PSocketClient::DoClose() { |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 177 delegate_->OnDataReceived(address, data); | 185 delegate_->OnDataReceived(address, data); |
| 178 } | 186 } |
| 179 | 187 |
| 180 void P2PSocketClient::Detach() { | 188 void P2PSocketClient::Detach() { |
| 181 DCHECK(ipc_message_loop_->BelongsToCurrentThread()); | 189 DCHECK(ipc_message_loop_->BelongsToCurrentThread()); |
| 182 dispatcher_ = NULL; | 190 dispatcher_ = NULL; |
| 183 OnError(); | 191 OnError(); |
| 184 } | 192 } |
| 185 | 193 |
| 186 } // namespace content | 194 } // namespace content |
| OLD | NEW |