| 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_proxy.h" | 8 #include "base/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 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 127 const net::IPEndPoint& address, scoped_refptr<P2PSocketClient> new_client) { | 127 const net::IPEndPoint& address, scoped_refptr<P2PSocketClient> new_client) { |
| 128 DCHECK(delegate_message_loop_->BelongsToCurrentThread()); | 128 DCHECK(delegate_message_loop_->BelongsToCurrentThread()); |
| 129 if (delegate_) { | 129 if (delegate_) { |
| 130 delegate_->OnIncomingTcpConnection(address, new_client); | 130 delegate_->OnIncomingTcpConnection(address, new_client); |
| 131 } else { | 131 } else { |
| 132 // Just close the socket if there is no delegate to accept it. | 132 // Just close the socket if there is no delegate to accept it. |
| 133 new_client->Close(); | 133 new_client->Close(); |
| 134 } | 134 } |
| 135 } | 135 } |
| 136 | 136 |
| 137 void P2PSocketClient::OnSendComplete() { |
| 138 DCHECK(ipc_message_loop_->BelongsToCurrentThread()); |
| 139 |
| 140 delegate_message_loop_->PostTask( |
| 141 FROM_HERE, base::Bind(&P2PSocketClient::DeliverOnSendComplete, this)); |
| 142 } |
| 143 |
| 144 void P2PSocketClient::DeliverOnSendComplete() { |
| 145 DCHECK(delegate_message_loop_->BelongsToCurrentThread()); |
| 146 if (delegate_) |
| 147 delegate_->OnSendComplete(); |
| 148 } |
| 149 |
| 137 void P2PSocketClient::OnError() { | 150 void P2PSocketClient::OnError() { |
| 138 DCHECK(ipc_message_loop_->BelongsToCurrentThread()); | 151 DCHECK(ipc_message_loop_->BelongsToCurrentThread()); |
| 139 state_ = STATE_ERROR; | 152 state_ = STATE_ERROR; |
| 140 | 153 |
| 141 delegate_message_loop_->PostTask( | 154 delegate_message_loop_->PostTask( |
| 142 FROM_HERE, base::Bind(&P2PSocketClient::DeliverOnError, this)); | 155 FROM_HERE, base::Bind(&P2PSocketClient::DeliverOnError, this)); |
| 143 } | 156 } |
| 144 | 157 |
| 145 void P2PSocketClient::DeliverOnError() { | 158 void P2PSocketClient::DeliverOnError() { |
| 146 DCHECK(delegate_message_loop_->BelongsToCurrentThread()); | 159 DCHECK(delegate_message_loop_->BelongsToCurrentThread()); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 164 delegate_->OnDataReceived(address, data); | 177 delegate_->OnDataReceived(address, data); |
| 165 } | 178 } |
| 166 | 179 |
| 167 void P2PSocketClient::Detach() { | 180 void P2PSocketClient::Detach() { |
| 168 DCHECK(ipc_message_loop_->BelongsToCurrentThread()); | 181 DCHECK(ipc_message_loop_->BelongsToCurrentThread()); |
| 169 dispatcher_ = NULL; | 182 dispatcher_ = NULL; |
| 170 OnError(); | 183 OnError(); |
| 171 } | 184 } |
| 172 | 185 |
| 173 } // namespace content | 186 } // namespace content |
| OLD | NEW |