| 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 #ifndef CONTENT_RENDERER_P2P_HOST_ADDRESS_REQUEST_H_ | 5 #ifndef CONTENT_RENDERER_P2P_HOST_ADDRESS_REQUEST_H_ |
| 6 #define CONTENT_RENDERER_P2P_HOST_ADDRESS_REQUEST_H_ | 6 #define CONTENT_RENDERER_P2P_HOST_ADDRESS_REQUEST_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/callback.h" | 10 #include "base/callback.h" |
| 11 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
| 12 #include "content/common/content_export.h" | 12 #include "content/common/content_export.h" |
| 13 #include "net/base/net_util.h" | 13 #include "net/base/net_util.h" |
| 14 #include "third_party/libjingle/source/talk/base/asyncresolverinterface.h" | 14 #include "third_party/webrtc/base/asyncresolverinterface.h" |
| 15 | 15 |
| 16 namespace base { | 16 namespace base { |
| 17 class MessageLoop; | 17 class MessageLoop; |
| 18 class MessageLoopProxy; | 18 class MessageLoopProxy; |
| 19 } // namespace base | 19 } // namespace base |
| 20 | 20 |
| 21 namespace content { | 21 namespace content { |
| 22 | 22 |
| 23 class P2PSocketDispatcher; | 23 class P2PSocketDispatcher; |
| 24 | 24 |
| 25 // P2PAsyncAddressResolver performs DNS hostname resolution. It's used | 25 // P2PAsyncAddressResolver performs DNS hostname resolution. It's used |
| 26 // to resolve addresses of STUN and relay servers. | 26 // to resolve addresses of STUN and relay servers. |
| 27 class P2PAsyncAddressResolver | 27 class P2PAsyncAddressResolver |
| 28 : public base::RefCountedThreadSafe<P2PAsyncAddressResolver> { | 28 : public base::RefCountedThreadSafe<P2PAsyncAddressResolver> { |
| 29 public: | 29 public: |
| 30 typedef base::Callback<void(const net::IPAddressList&)> DoneCallback; | 30 typedef base::Callback<void(const net::IPAddressList&)> DoneCallback; |
| 31 | 31 |
| 32 P2PAsyncAddressResolver(P2PSocketDispatcher* dispatcher); | 32 P2PAsyncAddressResolver(P2PSocketDispatcher* dispatcher); |
| 33 // Start address resolve process. | 33 // Start address resolve process. |
| 34 void Start(const talk_base::SocketAddress& addr, | 34 void Start(const rtc::SocketAddress& addr, |
| 35 const DoneCallback& done_callback); | 35 const DoneCallback& done_callback); |
| 36 // Clients must unregister before exiting for cleanup. | 36 // Clients must unregister before exiting for cleanup. |
| 37 void Cancel(); | 37 void Cancel(); |
| 38 | 38 |
| 39 private: | 39 private: |
| 40 enum State { | 40 enum State { |
| 41 STATE_CREATED, | 41 STATE_CREATED, |
| 42 STATE_SENT, | 42 STATE_SENT, |
| 43 STATE_FINISHED, | 43 STATE_FINISHED, |
| 44 }; | 44 }; |
| 45 | 45 |
| 46 friend class P2PSocketDispatcher; | 46 friend class P2PSocketDispatcher; |
| 47 | 47 |
| 48 friend class base::RefCountedThreadSafe<P2PAsyncAddressResolver>; | 48 friend class base::RefCountedThreadSafe<P2PAsyncAddressResolver>; |
| 49 | 49 |
| 50 virtual ~P2PAsyncAddressResolver(); | 50 virtual ~P2PAsyncAddressResolver(); |
| 51 | 51 |
| 52 void DoSendRequest(const talk_base::SocketAddress& host_name, | 52 void DoSendRequest(const rtc::SocketAddress& host_name, |
| 53 const DoneCallback& done_callback); | 53 const DoneCallback& done_callback); |
| 54 void DoUnregister(); | 54 void DoUnregister(); |
| 55 void OnResponse(const net::IPAddressList& address); | 55 void OnResponse(const net::IPAddressList& address); |
| 56 void DeliverResponse(const net::IPAddressList& address); | 56 void DeliverResponse(const net::IPAddressList& address); |
| 57 | 57 |
| 58 P2PSocketDispatcher* dispatcher_; | 58 P2PSocketDispatcher* dispatcher_; |
| 59 scoped_refptr<base::MessageLoopProxy> ipc_message_loop_; | 59 scoped_refptr<base::MessageLoopProxy> ipc_message_loop_; |
| 60 scoped_refptr<base::MessageLoopProxy> delegate_message_loop_; | 60 scoped_refptr<base::MessageLoopProxy> delegate_message_loop_; |
| 61 | 61 |
| 62 // State must be accessed from delegate thread only. | 62 // State must be accessed from delegate thread only. |
| 63 State state_; | 63 State state_; |
| 64 | 64 |
| 65 // Accessed on the IPC thread only. | 65 // Accessed on the IPC thread only. |
| 66 int32 request_id_; | 66 int32 request_id_; |
| 67 bool registered_; | 67 bool registered_; |
| 68 std::vector<talk_base::IPAddress> addresses_; | 68 std::vector<rtc::IPAddress> addresses_; |
| 69 DoneCallback done_callback_; | 69 DoneCallback done_callback_; |
| 70 | 70 |
| 71 DISALLOW_COPY_AND_ASSIGN(P2PAsyncAddressResolver); | 71 DISALLOW_COPY_AND_ASSIGN(P2PAsyncAddressResolver); |
| 72 }; | 72 }; |
| 73 | 73 |
| 74 } // namespace content | 74 } // namespace content |
| 75 | 75 |
| 76 #endif // CONTENT_RENDERER_P2P_HOST_ADDRESS_REQUEST_H_ | 76 #endif // CONTENT_RENDERER_P2P_HOST_ADDRESS_REQUEST_H_ |
| OLD | NEW |