| Index: content/renderer/p2p/socket_client.cc
|
| diff --git a/content/renderer/p2p/socket_client.cc b/content/renderer/p2p/socket_client.cc
|
| index 74ad2b3c8cacfa1ca7ec3d32cd4aa904673b4e67..5de281e1edf555a6bf29fe20b5906bc7da79a5ec 100644
|
| --- a/content/renderer/p2p/socket_client.cc
|
| +++ b/content/renderer/p2p/socket_client.cc
|
| @@ -23,7 +23,7 @@ uint64 GetUniqueId(uint32 random_socket_id, uint32 packet_id) {
|
|
|
| namespace content {
|
|
|
| -P2PSocketClient::P2PSocketClient(P2PSocketDispatcher* dispatcher)
|
| +P2PSocketClientImpl::P2PSocketClientImpl(P2PSocketDispatcher* dispatcher)
|
| : dispatcher_(dispatcher),
|
| ipc_message_loop_(dispatcher->message_loop()),
|
| delegate_message_loop_(base::MessageLoopProxy::current()),
|
| @@ -34,11 +34,11 @@ P2PSocketClient::P2PSocketClient(P2PSocketDispatcher* dispatcher)
|
| crypto::RandBytes(&random_socket_id_, sizeof(random_socket_id_));
|
| }
|
|
|
| -P2PSocketClient::~P2PSocketClient() {
|
| +P2PSocketClientImpl::~P2PSocketClientImpl() {
|
| CHECK(state_ == STATE_CLOSED || state_ == STATE_UNINITIALIZED);
|
| }
|
|
|
| -void P2PSocketClient::Init(
|
| +void P2PSocketClientImpl::Init(
|
| P2PSocketType type,
|
| const net::IPEndPoint& local_address,
|
| const net::IPEndPoint& remote_address,
|
| @@ -48,13 +48,16 @@ void P2PSocketClient::Init(
|
| delegate_ = delegate;
|
|
|
| ipc_message_loop_->PostTask(
|
| - FROM_HERE, base::Bind(&P2PSocketClient::DoInit, this, type, local_address,
|
| + FROM_HERE, base::Bind(&P2PSocketClientImpl::DoInit,
|
| + this,
|
| + type,
|
| + local_address,
|
| remote_address));
|
| }
|
|
|
| -void P2PSocketClient::DoInit(P2PSocketType type,
|
| - const net::IPEndPoint& local_address,
|
| - const net::IPEndPoint& remote_address) {
|
| +void P2PSocketClientImpl::DoInit(P2PSocketType type,
|
| + const net::IPEndPoint& local_address,
|
| + const net::IPEndPoint& remote_address) {
|
| DCHECK_EQ(state_, STATE_UNINITIALIZED);
|
| DCHECK(delegate_);
|
| state_ = STATE_OPENING;
|
| @@ -63,14 +66,14 @@ void P2PSocketClient::DoInit(P2PSocketType type,
|
| type, socket_id_, local_address, remote_address));
|
| }
|
|
|
| -void P2PSocketClient::SendWithDscp(
|
| +void P2PSocketClientImpl::SendWithDscp(
|
| const net::IPEndPoint& address,
|
| const std::vector<char>& data,
|
| net::DiffServCodePoint dscp) {
|
| if (!ipc_message_loop_->BelongsToCurrentThread()) {
|
| ipc_message_loop_->PostTask(
|
| FROM_HERE, base::Bind(
|
| - &P2PSocketClient::SendWithDscp, this, address, data, dscp));
|
| + &P2PSocketClientImpl::SendWithDscp, this, address, data, dscp));
|
| return;
|
| }
|
|
|
| @@ -84,21 +87,21 @@ void P2PSocketClient::SendWithDscp(
|
| }
|
| }
|
|
|
| -void P2PSocketClient::Send(const net::IPEndPoint& address,
|
| +void P2PSocketClientImpl::Send(const net::IPEndPoint& address,
|
| const std::vector<char>& data) {
|
| SendWithDscp(address, data, net::DSCP_DEFAULT);
|
| }
|
|
|
| -void P2PSocketClient::Close() {
|
| +void P2PSocketClientImpl::Close() {
|
| DCHECK(delegate_message_loop_->BelongsToCurrentThread());
|
|
|
| delegate_ = NULL;
|
|
|
| ipc_message_loop_->PostTask(
|
| - FROM_HERE, base::Bind(&P2PSocketClient::DoClose, this));
|
| + FROM_HERE, base::Bind(&P2PSocketClientImpl::DoClose, this));
|
| }
|
|
|
| -void P2PSocketClient::DoClose() {
|
| +void P2PSocketClientImpl::DoClose() {
|
| DCHECK(ipc_message_loop_->BelongsToCurrentThread());
|
| if (dispatcher_) {
|
| if (state_ == STATE_OPEN || state_ == STATE_OPENING ||
|
| @@ -111,32 +114,39 @@ void P2PSocketClient::DoClose() {
|
| state_ = STATE_CLOSED;
|
| }
|
|
|
| -void P2PSocketClient::set_delegate(Delegate* delegate) {
|
| +int P2PSocketClientImpl::socket_id() const {
|
| + return socket_id_;
|
| +}
|
| +
|
| +void P2PSocketClientImpl::set_delegate(Delegate* delegate) {
|
| DCHECK(delegate_message_loop_->BelongsToCurrentThread());
|
| delegate_ = delegate;
|
| }
|
|
|
| -void P2PSocketClient::OnSocketCreated(const net::IPEndPoint& address) {
|
| +void P2PSocketClientImpl::OnSocketCreated(const net::IPEndPoint& address) {
|
| DCHECK(ipc_message_loop_->BelongsToCurrentThread());
|
| DCHECK_EQ(state_, STATE_OPENING);
|
| state_ = STATE_OPEN;
|
|
|
| delegate_message_loop_->PostTask(
|
| FROM_HERE,
|
| - base::Bind(&P2PSocketClient::DeliverOnSocketCreated, this, address));
|
| + base::Bind(&P2PSocketClientImpl::DeliverOnSocketCreated, this, address));
|
| }
|
|
|
| -void P2PSocketClient::DeliverOnSocketCreated(const net::IPEndPoint& address) {
|
| +void P2PSocketClientImpl::DeliverOnSocketCreated(
|
| + const net::IPEndPoint& address) {
|
| DCHECK(delegate_message_loop_->BelongsToCurrentThread());
|
| if (delegate_)
|
| delegate_->OnOpen(address);
|
| }
|
|
|
| -void P2PSocketClient::OnIncomingTcpConnection(const net::IPEndPoint& address) {
|
| +void P2PSocketClientImpl::OnIncomingTcpConnection(
|
| + const net::IPEndPoint& address) {
|
| DCHECK(ipc_message_loop_->BelongsToCurrentThread());
|
| DCHECK_EQ(state_, STATE_OPEN);
|
|
|
| - scoped_refptr<P2PSocketClient> new_client = new P2PSocketClient(dispatcher_);
|
| + scoped_refptr<P2PSocketClientImpl> new_client =
|
| + new P2PSocketClientImpl(dispatcher_);
|
| new_client->socket_id_ = dispatcher_->RegisterClient(new_client.get());
|
| new_client->state_ = STATE_OPEN;
|
| new_client->delegate_message_loop_ = delegate_message_loop_;
|
| @@ -145,12 +155,14 @@ void P2PSocketClient::OnIncomingTcpConnection(const net::IPEndPoint& address) {
|
| socket_id_, address, new_client->socket_id_));
|
|
|
| delegate_message_loop_->PostTask(
|
| - FROM_HERE, base::Bind(&P2PSocketClient::DeliverOnIncomingTcpConnection,
|
| - this, address, new_client));
|
| + FROM_HERE, base::Bind(
|
| + &P2PSocketClientImpl::DeliverOnIncomingTcpConnection,
|
| + this, address, new_client));
|
| }
|
|
|
| -void P2PSocketClient::DeliverOnIncomingTcpConnection(
|
| - const net::IPEndPoint& address, scoped_refptr<P2PSocketClient> new_client) {
|
| +void P2PSocketClientImpl::DeliverOnIncomingTcpConnection(
|
| + const net::IPEndPoint& address,
|
| + scoped_refptr<P2PSocketClient> new_client) {
|
| DCHECK(delegate_message_loop_->BelongsToCurrentThread());
|
| if (delegate_) {
|
| delegate_->OnIncomingTcpConnection(address, new_client.get());
|
| @@ -160,50 +172,53 @@ void P2PSocketClient::DeliverOnIncomingTcpConnection(
|
| }
|
| }
|
|
|
| -void P2PSocketClient::OnSendComplete() {
|
| +void P2PSocketClientImpl::OnSendComplete() {
|
| DCHECK(ipc_message_loop_->BelongsToCurrentThread());
|
|
|
| delegate_message_loop_->PostTask(
|
| - FROM_HERE, base::Bind(&P2PSocketClient::DeliverOnSendComplete, this));
|
| + FROM_HERE, base::Bind(&P2PSocketClientImpl::DeliverOnSendComplete, this));
|
| }
|
|
|
| -void P2PSocketClient::DeliverOnSendComplete() {
|
| +void P2PSocketClientImpl::DeliverOnSendComplete() {
|
| DCHECK(delegate_message_loop_->BelongsToCurrentThread());
|
| if (delegate_)
|
| delegate_->OnSendComplete();
|
| }
|
|
|
| -void P2PSocketClient::OnError() {
|
| +void P2PSocketClientImpl::OnError() {
|
| DCHECK(ipc_message_loop_->BelongsToCurrentThread());
|
| state_ = STATE_ERROR;
|
|
|
| delegate_message_loop_->PostTask(
|
| - FROM_HERE, base::Bind(&P2PSocketClient::DeliverOnError, this));
|
| + FROM_HERE, base::Bind(&P2PSocketClientImpl::DeliverOnError, this));
|
| }
|
|
|
| -void P2PSocketClient::DeliverOnError() {
|
| +void P2PSocketClientImpl::DeliverOnError() {
|
| DCHECK(delegate_message_loop_->BelongsToCurrentThread());
|
| if (delegate_)
|
| delegate_->OnError();
|
| }
|
|
|
| -void P2PSocketClient::OnDataReceived(const net::IPEndPoint& address,
|
| - const std::vector<char>& data) {
|
| +void P2PSocketClientImpl::OnDataReceived(const net::IPEndPoint& address,
|
| + const std::vector<char>& data) {
|
| DCHECK(ipc_message_loop_->BelongsToCurrentThread());
|
| DCHECK_EQ(STATE_OPEN, state_);
|
| delegate_message_loop_->PostTask(
|
| FROM_HERE,
|
| - base::Bind(&P2PSocketClient::DeliverOnDataReceived, this, address, data));
|
| + base::Bind(&P2PSocketClientImpl::DeliverOnDataReceived,
|
| + this,
|
| + address,
|
| + data));
|
| }
|
|
|
| -void P2PSocketClient::DeliverOnDataReceived(const net::IPEndPoint& address,
|
| - const std::vector<char>& data) {
|
| +void P2PSocketClientImpl::DeliverOnDataReceived(const net::IPEndPoint& address,
|
| + const std::vector<char>& data) {
|
| DCHECK(delegate_message_loop_->BelongsToCurrentThread());
|
| if (delegate_)
|
| delegate_->OnDataReceived(address, data);
|
| }
|
|
|
| -void P2PSocketClient::Detach() {
|
| +void P2PSocketClientImpl::Detach() {
|
| DCHECK(ipc_message_loop_->BelongsToCurrentThread());
|
| dispatcher_ = NULL;
|
| OnError();
|
|
|