OLD | NEW |
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/renderer/p2p/host_address_request.h" | 5 #include "content/renderer/p2p/host_address_request.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/callback_helpers.h" | 8 #include "base/callback_helpers.h" |
9 #include "base/message_loop/message_loop_proxy.h" | 9 #include "base/message_loop/message_loop_proxy.h" |
10 #include "content/common/p2p_messages.h" | 10 #include "content/common/p2p_messages.h" |
(...skipping 11 matching lines...) Expand all Loading... |
22 request_id_(0), | 22 request_id_(0), |
23 registered_(false) { | 23 registered_(false) { |
24 AddRef(); // Balanced in Destroy(). | 24 AddRef(); // Balanced in Destroy(). |
25 } | 25 } |
26 | 26 |
27 P2PAsyncAddressResolver::~P2PAsyncAddressResolver() { | 27 P2PAsyncAddressResolver::~P2PAsyncAddressResolver() { |
28 DCHECK(state_ == STATE_CREATED || state_ == STATE_FINISHED); | 28 DCHECK(state_ == STATE_CREATED || state_ == STATE_FINISHED); |
29 DCHECK(!registered_); | 29 DCHECK(!registered_); |
30 } | 30 } |
31 | 31 |
32 void P2PAsyncAddressResolver::Start(const talk_base::SocketAddress& host_name, | 32 void P2PAsyncAddressResolver::Start(const rtc::SocketAddress& host_name, |
33 const DoneCallback& done_callback) { | 33 const DoneCallback& done_callback) { |
34 DCHECK(delegate_message_loop_->BelongsToCurrentThread()); | 34 DCHECK(delegate_message_loop_->BelongsToCurrentThread()); |
35 DCHECK_EQ(STATE_CREATED, state_); | 35 DCHECK_EQ(STATE_CREATED, state_); |
36 | 36 |
37 state_ = STATE_SENT; | 37 state_ = STATE_SENT; |
38 ipc_message_loop_->PostTask(FROM_HERE, base::Bind( | 38 ipc_message_loop_->PostTask(FROM_HERE, base::Bind( |
39 &P2PAsyncAddressResolver::DoSendRequest, this, host_name, done_callback)); | 39 &P2PAsyncAddressResolver::DoSendRequest, this, host_name, done_callback)); |
40 } | 40 } |
41 | 41 |
42 void P2PAsyncAddressResolver::Cancel() { | 42 void P2PAsyncAddressResolver::Cancel() { |
43 DCHECK(delegate_message_loop_->BelongsToCurrentThread()); | 43 DCHECK(delegate_message_loop_->BelongsToCurrentThread()); |
44 | 44 |
45 if (state_ != STATE_FINISHED) { | 45 if (state_ != STATE_FINISHED) { |
46 state_ = STATE_FINISHED; | 46 state_ = STATE_FINISHED; |
47 ipc_message_loop_->PostTask(FROM_HERE, base::Bind( | 47 ipc_message_loop_->PostTask(FROM_HERE, base::Bind( |
48 &P2PAsyncAddressResolver::DoUnregister, this)); | 48 &P2PAsyncAddressResolver::DoUnregister, this)); |
49 } | 49 } |
50 done_callback_.Reset(); | 50 done_callback_.Reset(); |
51 } | 51 } |
52 | 52 |
53 void P2PAsyncAddressResolver::DoSendRequest( | 53 void P2PAsyncAddressResolver::DoSendRequest( |
54 const talk_base::SocketAddress& host_name, | 54 const rtc::SocketAddress& host_name, |
55 const DoneCallback& done_callback) { | 55 const DoneCallback& done_callback) { |
56 DCHECK(ipc_message_loop_->BelongsToCurrentThread()); | 56 DCHECK(ipc_message_loop_->BelongsToCurrentThread()); |
57 | 57 |
58 done_callback_ = done_callback; | 58 done_callback_ = done_callback; |
59 request_id_ = dispatcher_->RegisterHostAddressRequest(this); | 59 request_id_ = dispatcher_->RegisterHostAddressRequest(this); |
60 registered_ = true; | 60 registered_ = true; |
61 dispatcher_->SendP2PMessage( | 61 dispatcher_->SendP2PMessage( |
62 new P2PHostMsg_GetHostAddress(host_name.hostname(), request_id_)); | 62 new P2PHostMsg_GetHostAddress(host_name.hostname(), request_id_)); |
63 } | 63 } |
64 | 64 |
(...skipping 19 matching lines...) Expand all Loading... |
84 void P2PAsyncAddressResolver::DeliverResponse( | 84 void P2PAsyncAddressResolver::DeliverResponse( |
85 const net::IPAddressList& addresses) { | 85 const net::IPAddressList& addresses) { |
86 DCHECK(delegate_message_loop_->BelongsToCurrentThread()); | 86 DCHECK(delegate_message_loop_->BelongsToCurrentThread()); |
87 if (state_ == STATE_SENT) { | 87 if (state_ == STATE_SENT) { |
88 state_ = STATE_FINISHED; | 88 state_ = STATE_FINISHED; |
89 base::ResetAndReturn(&done_callback_).Run(addresses); | 89 base::ResetAndReturn(&done_callback_).Run(addresses); |
90 } | 90 } |
91 } | 91 } |
92 | 92 |
93 } // namespace content | 93 } // namespace content |
OLD | NEW |