OLD | NEW |
(Empty) | |
| 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. |
| 4 |
| 5 #ifndef CONTENT_RENDERER_P2P_HOST_ADDRESS_REQUEST_H_ |
| 6 #define CONTENT_RENDERER_P2P_HOST_ADDRESS_REQUEST_H_ |
| 7 |
| 8 #include <string> |
| 9 |
| 10 #include "base/callback.h" |
| 11 #include "base/memory/ref_counted.h" |
| 12 #include "net/base/net_util.h" |
| 13 |
| 14 namespace base { |
| 15 class MessageLoopProxy; |
| 16 } // namespace base |
| 17 |
| 18 class P2PSocketDispatcher; |
| 19 |
| 20 class P2PHostAddressRequest : |
| 21 public base::RefCountedThreadSafe<P2PHostAddressRequest> { |
| 22 public: |
| 23 typedef base::Callback<void(const net::IPAddressNumber&)> DoneCallback; |
| 24 |
| 25 P2PHostAddressRequest(P2PSocketDispatcher* dispatcher); |
| 26 |
| 27 // Sends host address request. |
| 28 void Request(const std::string& host_name, |
| 29 const DoneCallback& done_callback); |
| 30 |
| 31 // Cancels the request. The callback passed to Request() will not be |
| 32 // called after Cancel() is called. |
| 33 void Cancel(); |
| 34 |
| 35 private: |
| 36 enum State { |
| 37 STATE_CREATED, |
| 38 STATE_SENT, |
| 39 STATE_FINISHED, |
| 40 }; |
| 41 |
| 42 friend class P2PSocketDispatcher; |
| 43 |
| 44 friend class base::RefCountedThreadSafe<P2PHostAddressRequest>; |
| 45 virtual ~P2PHostAddressRequest(); |
| 46 |
| 47 void DoSendRequest(const std::string& host_name, |
| 48 const DoneCallback& done_callback); |
| 49 void DoUnregister(); |
| 50 void OnResponse(const net::IPAddressNumber& address); |
| 51 void DeliverResponse(const net::IPAddressNumber& address); |
| 52 |
| 53 P2PSocketDispatcher* dispatcher_; |
| 54 scoped_refptr<base::MessageLoopProxy> ipc_message_loop_; |
| 55 scoped_refptr<base::MessageLoopProxy> delegate_message_loop_; |
| 56 DoneCallback done_callback_; |
| 57 |
| 58 // State must be accessed from delegate thread only. |
| 59 State state_; |
| 60 |
| 61 // Accessed on the IPC thread only. |
| 62 int32 request_id_; |
| 63 bool registered_; |
| 64 |
| 65 DISALLOW_COPY_AND_ASSIGN(P2PHostAddressRequest); |
| 66 }; |
| 67 |
| 68 #endif // CONTENT_RENDERER_P2P_HOST_ADDRESS_REQUEST_H_ |
OLD | NEW |