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/location.h" | 8 #include "base/location.h" |
9 #include "base/single_thread_task_runner.h" | 9 #include "base/single_thread_task_runner.h" |
10 #include "base/threading/thread_task_runner_handle.h" | 10 #include "base/threading/thread_task_runner_handle.h" |
(...skipping 26 matching lines...) Expand all Loading... |
37 state_(STATE_UNINITIALIZED), | 37 state_(STATE_UNINITIALIZED), |
38 random_socket_id_(0), | 38 random_socket_id_(0), |
39 next_packet_id_(0) { | 39 next_packet_id_(0) { |
40 crypto::RandBytes(&random_socket_id_, sizeof(random_socket_id_)); | 40 crypto::RandBytes(&random_socket_id_, sizeof(random_socket_id_)); |
41 } | 41 } |
42 | 42 |
43 P2PSocketClientImpl::~P2PSocketClientImpl() { | 43 P2PSocketClientImpl::~P2PSocketClientImpl() { |
44 CHECK(state_ == STATE_CLOSED || state_ == STATE_UNINITIALIZED); | 44 CHECK(state_ == STATE_CLOSED || state_ == STATE_UNINITIALIZED); |
45 } | 45 } |
46 | 46 |
47 void P2PSocketClientImpl::Init( | 47 void P2PSocketClientImpl::Init(P2PSocketType type, |
48 P2PSocketType type, | 48 const net::IPEndPoint& local_address, |
49 const net::IPEndPoint& local_address, | 49 uint16_t min_port, |
50 const P2PHostAndIPEndPoint& remote_address, | 50 uint16_t max_port, |
51 P2PSocketClientDelegate* delegate) { | 51 const P2PHostAndIPEndPoint& remote_address, |
| 52 P2PSocketClientDelegate* delegate) { |
52 DCHECK(delegate_task_runner_->BelongsToCurrentThread()); | 53 DCHECK(delegate_task_runner_->BelongsToCurrentThread()); |
53 DCHECK(delegate); | 54 DCHECK(delegate); |
54 // |delegate_| is only accessesed on |delegate_message_loop_|. | 55 // |delegate_| is only accessesed on |delegate_message_loop_|. |
55 delegate_ = delegate; | 56 delegate_ = delegate; |
56 | 57 |
57 ipc_task_runner_->PostTask( | 58 ipc_task_runner_->PostTask( |
58 FROM_HERE, base::Bind(&P2PSocketClientImpl::DoInit, this, type, | 59 FROM_HERE, base::Bind(&P2PSocketClientImpl::DoInit, this, type, |
59 local_address, remote_address)); | 60 local_address, min_port, max_port, remote_address)); |
60 } | 61 } |
61 | 62 |
62 void P2PSocketClientImpl::DoInit(P2PSocketType type, | 63 void P2PSocketClientImpl::DoInit(P2PSocketType type, |
63 const net::IPEndPoint& local_address, | 64 const net::IPEndPoint& local_address, |
| 65 uint16_t min_port, |
| 66 uint16_t max_port, |
64 const P2PHostAndIPEndPoint& remote_address) { | 67 const P2PHostAndIPEndPoint& remote_address) { |
65 DCHECK_EQ(state_, STATE_UNINITIALIZED); | 68 DCHECK_EQ(state_, STATE_UNINITIALIZED); |
66 state_ = STATE_OPENING; | 69 state_ = STATE_OPENING; |
67 socket_id_ = dispatcher_->RegisterClient(this); | 70 socket_id_ = dispatcher_->RegisterClient(this); |
68 dispatcher_->SendP2PMessage(new P2PHostMsg_CreateSocket( | 71 dispatcher_->SendP2PMessage(new P2PHostMsg_CreateSocket( |
69 type, socket_id_, local_address, remote_address)); | 72 type, socket_id_, local_address, P2PPortRange(min_port, max_port), |
| 73 remote_address)); |
70 } | 74 } |
71 | 75 |
72 uint64_t P2PSocketClientImpl::Send(const net::IPEndPoint& address, | 76 uint64_t P2PSocketClientImpl::Send(const net::IPEndPoint& address, |
73 const std::vector<char>& data, | 77 const std::vector<char>& data, |
74 const rtc::PacketOptions& options) { | 78 const rtc::PacketOptions& options) { |
75 uint64_t unique_id = GetUniqueId(random_socket_id_, ++next_packet_id_); | 79 uint64_t unique_id = GetUniqueId(random_socket_id_, ++next_packet_id_); |
76 if (!ipc_task_runner_->BelongsToCurrentThread()) { | 80 if (!ipc_task_runner_->BelongsToCurrentThread()) { |
77 ipc_task_runner_->PostTask( | 81 ipc_task_runner_->PostTask( |
78 FROM_HERE, base::Bind(&P2PSocketClientImpl::SendWithPacketId, this, | 82 FROM_HERE, base::Bind(&P2PSocketClientImpl::SendWithPacketId, this, |
79 address, data, options, unique_id)); | 83 address, data, options, unique_id)); |
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
245 delegate_->OnDataReceived(address, data, timestamp); | 249 delegate_->OnDataReceived(address, data, timestamp); |
246 } | 250 } |
247 | 251 |
248 void P2PSocketClientImpl::Detach() { | 252 void P2PSocketClientImpl::Detach() { |
249 DCHECK(ipc_task_runner_->BelongsToCurrentThread()); | 253 DCHECK(ipc_task_runner_->BelongsToCurrentThread()); |
250 dispatcher_ = NULL; | 254 dispatcher_ = NULL; |
251 OnError(); | 255 OnError(); |
252 } | 256 } |
253 | 257 |
254 } // namespace content | 258 } // namespace content |
OLD | NEW |