Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(355)

Side by Side Diff: content/browser/renderer_host/p2p/socket_host_udp.cc

Issue 10917167: Refactor the P2PSocketDispatcher to be created on the RenderThread instead of the RenderView. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Removed unnecessary destruction callback. Removed remaining routing_id. Created 8 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/browser/renderer_host/p2p/socket_host_udp.h" 5 #include "content/browser/renderer_host/p2p/socket_host_udp.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "content/common/p2p_messages.h" 8 #include "content/common/p2p_messages.h"
9 #include "net/base/io_buffer.h" 9 #include "net/base/io_buffer.h"
10 #include "net/base/net_errors.h" 10 #include "net/base/net_errors.h"
(...skipping 12 matching lines...) Expand all
23 const net::IPEndPoint& to, const std::vector<char>& content) 23 const net::IPEndPoint& to, const std::vector<char>& content)
24 : to(to), 24 : to(to),
25 data(new net::IOBuffer(content.size())), 25 data(new net::IOBuffer(content.size())),
26 size(content.size()) { 26 size(content.size()) {
27 memcpy(data->data(), &content[0], size); 27 memcpy(data->data(), &content[0], size);
28 } 28 }
29 29
30 P2PSocketHostUdp::PendingPacket::~PendingPacket() { 30 P2PSocketHostUdp::PendingPacket::~PendingPacket() {
31 } 31 }
32 32
33 P2PSocketHostUdp::P2PSocketHostUdp(IPC::Sender* message_sender, 33 P2PSocketHostUdp::P2PSocketHostUdp(IPC::Sender* message_sender, int id)
34 int routing_id, int id) 34 : P2PSocketHost(message_sender, id),
35 : P2PSocketHost(message_sender, routing_id, id),
36 socket_(new net::UDPServerSocket(NULL, net::NetLog::Source())), 35 socket_(new net::UDPServerSocket(NULL, net::NetLog::Source())),
37 send_queue_bytes_(0), 36 send_queue_bytes_(0),
38 send_pending_(false) { 37 send_pending_(false) {
39 } 38 }
40 39
41 P2PSocketHostUdp::~P2PSocketHostUdp() { 40 P2PSocketHostUdp::~P2PSocketHostUdp() {
42 if (state_ == STATE_OPEN) { 41 if (state_ == STATE_OPEN) {
43 DCHECK(socket_.get()); 42 DCHECK(socket_.get());
44 socket_.reset(); 43 socket_.reset();
45 } 44 }
(...skipping 15 matching lines...) Expand all
61 if (result < 0) { 60 if (result < 0) {
62 LOG(ERROR) << "P2PSocketHostUdp::Init(): unable to get local address: " 61 LOG(ERROR) << "P2PSocketHostUdp::Init(): unable to get local address: "
63 << result; 62 << result;
64 OnError(); 63 OnError();
65 return false; 64 return false;
66 } 65 }
67 VLOG(1) << "Local address: " << address.ToString(); 66 VLOG(1) << "Local address: " << address.ToString();
68 67
69 state_ = STATE_OPEN; 68 state_ = STATE_OPEN;
70 69
71 message_sender_->Send(new P2PMsg_OnSocketCreated(routing_id_, id_, address)); 70 message_sender_->Send(new P2PMsg_OnSocketCreated(id_, address));
72 71
73 recv_buffer_ = new net::IOBuffer(kReadBufferSize); 72 recv_buffer_ = new net::IOBuffer(kReadBufferSize);
74 DoRead(); 73 DoRead();
75 74
76 return true; 75 return true;
77 } 76 }
78 77
79 void P2PSocketHostUdp::OnError() { 78 void P2PSocketHostUdp::OnError() {
80 socket_.reset(); 79 socket_.reset();
81 send_queue_.clear(); 80 send_queue_.clear();
82 81
83 if (state_ == STATE_UNINITIALIZED || state_ == STATE_OPEN) 82 if (state_ == STATE_UNINITIALIZED || state_ == STATE_OPEN)
84 message_sender_->Send(new P2PMsg_OnError(routing_id_, id_)); 83 message_sender_->Send(new P2PMsg_OnError(id_));
85 84
86 state_ = STATE_ERROR; 85 state_ = STATE_ERROR;
87 } 86 }
88 87
89 void P2PSocketHostUdp::DoRead() { 88 void P2PSocketHostUdp::DoRead() {
90 int result; 89 int result;
91 do { 90 do {
92 result = socket_->RecvFrom(recv_buffer_, kReadBufferSize, &recv_address_, 91 result = socket_->RecvFrom(recv_buffer_, kReadBufferSize, &recv_address_,
93 base::Bind(&P2PSocketHostUdp::OnRecv, 92 base::Bind(&P2PSocketHostUdp::OnRecv,
94 base::Unretained(this))); 93 base::Unretained(this)));
(...skipping 20 matching lines...) Expand all
115 if (stun && IsRequestOrResponse(type)) { 114 if (stun && IsRequestOrResponse(type)) {
116 connected_peers_.insert(recv_address_); 115 connected_peers_.insert(recv_address_);
117 } else if (!stun || type == STUN_DATA_INDICATION) { 116 } else if (!stun || type == STUN_DATA_INDICATION) {
118 LOG(ERROR) << "Received unexpected data packet from " 117 LOG(ERROR) << "Received unexpected data packet from "
119 << recv_address_.ToString() 118 << recv_address_.ToString()
120 << " before STUN binding is finished."; 119 << " before STUN binding is finished.";
121 return; 120 return;
122 } 121 }
123 } 122 }
124 123
125 message_sender_->Send(new P2PMsg_OnDataReceived(routing_id_, id_, 124 message_sender_->Send(new P2PMsg_OnDataReceived(id_, recv_address_, data));
126 recv_address_, data));
127 } else if (result < 0 && result != net::ERR_IO_PENDING) { 125 } else if (result < 0 && result != net::ERR_IO_PENDING) {
128 LOG(ERROR) << "Error when reading from UDP socket: " << result; 126 LOG(ERROR) << "Error when reading from UDP socket: " << result;
129 OnError(); 127 OnError();
130 } 128 }
131 } 129 }
132 130
133 void P2PSocketHostUdp::Send(const net::IPEndPoint& to, 131 void P2PSocketHostUdp::Send(const net::IPEndPoint& to,
134 const std::vector<char>& data) { 132 const std::vector<char>& data) {
135 if (!socket_.get()) { 133 if (!socket_.get()) {
136 // The Send message may be sent after the an OnError message was 134 // The Send message may be sent after the an OnError message was
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
199 } 197 }
200 198
201 P2PSocketHost* P2PSocketHostUdp::AcceptIncomingTcpConnection( 199 P2PSocketHost* P2PSocketHostUdp::AcceptIncomingTcpConnection(
202 const net::IPEndPoint& remote_address, int id) { 200 const net::IPEndPoint& remote_address, int id) {
203 NOTREACHED(); 201 NOTREACHED();
204 OnError(); 202 OnError();
205 return NULL; 203 return NULL;
206 } 204 }
207 205
208 } // namespace content 206 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698