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
3 // found in the LICENSE file.
5 #ifndef CONTENT_RENDERER_P2P_HOST_ADDRESS_REQUEST_H_
6 #define CONTENT_RENDERER_P2P_HOST_ADDRESS_REQUEST_H_
10 #include "base/callback.h"
11 #include "base/memory/ref_counted.h"
12 #include "content/common/content_export.h"
13 #include "net/base/net_util.h"
16 class MessageLoopProxy;
21 class P2PSocketDispatcher;
23 // P2PHostAddressRequest performs DNS hostname resolution. It's used
24 // to resolve addresses of STUN and relay servers.
26 // TODO(sergeyu): Name of this class may be confusing. Rename it to
27 // something else, e.g. P2PHostnameResolver.
28 class CONTENT_EXPORT P2PHostAddressRequest
29 : public base::RefCountedThreadSafe<P2PHostAddressRequest> {
31 typedef base::Callback<void(const net::IPAddressNumber&)> DoneCallback;
33 P2PHostAddressRequest(P2PSocketDispatcher* dispatcher);
35 // Sends host address request.
36 void Request(const std::string& host_name,
37 const DoneCallback& done_callback);
39 // Cancels the request. The callback passed to Request() will not be
40 // called after Cancel() is called.
50 friend class P2PSocketDispatcher;
52 friend class base::RefCountedThreadSafe<P2PHostAddressRequest>;
53 virtual ~P2PHostAddressRequest();
55 void DoSendRequest(const std::string& host_name,
56 const DoneCallback& done_callback);
58 void OnResponse(const net::IPAddressNumber& address);
59 void DeliverResponse(const net::IPAddressNumber& address);
61 P2PSocketDispatcher* dispatcher_;
62 scoped_refptr<base::MessageLoopProxy> ipc_message_loop_;
63 scoped_refptr<base::MessageLoopProxy> delegate_message_loop_;
64 DoneCallback done_callback_;
66 // State must be accessed from delegate thread only.
69 // Accessed on the IPC thread only.
73 DISALLOW_COPY_AND_ASSIGN(P2PHostAddressRequest);
76 } // namespace content
78 #endif // CONTENT_RENDERER_P2P_HOST_ADDRESS_REQUEST_H_