| 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 REMOTING_JINGLE_GLUE_JINGLE_INFO_REQUEST_H_ | 5 #ifndef REMOTING_JINGLE_GLUE_JINGLE_INFO_REQUEST_H_ |
| 6 #define REMOTING_JINGLE_GLUE_JINGLE_INFO_REQUEST_H_ | 6 #define REMOTING_JINGLE_GLUE_JINGLE_INFO_REQUEST_H_ |
| 7 | 7 |
| 8 #include <map> |
| 9 #include <set> |
| 8 #include <string> | 10 #include <string> |
| 9 #include <vector> | 11 #include <vector> |
| 10 | 12 |
| 11 #include "base/basictypes.h" | 13 #include "base/basictypes.h" |
| 12 #include "base/callback.h" | 14 #include "base/callback.h" |
| 13 #include "base/memory/scoped_ptr.h" | 15 #include "base/memory/scoped_ptr.h" |
| 16 #include "third_party/libjingle/source/talk/base/sigslot.h" |
| 14 | 17 |
| 15 class Task; | 18 class Task; |
| 16 | 19 |
| 17 namespace buzz { | 20 namespace buzz { |
| 18 class XmlElement; | 21 class XmlElement; |
| 19 } // namespace buzz | 22 } // namespace buzz |
| 20 | 23 |
| 21 namespace talk_base { | 24 namespace talk_base { |
| 22 class SocketAddress; | 25 class SocketAddress; |
| 23 } // namespace talk_base | 26 } // namespace talk_base |
| 24 | 27 |
| 25 namespace remoting { | 28 namespace remoting { |
| 26 | 29 |
| 27 class IqRequest; | 30 class IqRequest; |
| 31 class HostAddressRequest; |
| 32 class HostAddressResolver; |
| 28 | 33 |
| 29 // JingleInfoRequest handles requesting STUN/Relay infromation from | 34 // JingleInfoRequest handles requesting STUN/Relay infromation from |
| 30 // the Google Talk network. The query is made when Send() is | 35 // the Google Talk network. The query is made when Send() is |
| 31 // called. The callback given to Send() is called when response to the | 36 // called. The callback given to Send() is called when response to the |
| 32 // request is received. | 37 // request is received. |
| 33 // | 38 // |
| 34 // This class is not threadsafe and should be used on the same thread it is | 39 // This class is not threadsafe and should be used on the same thread it is |
| 35 // created on. | 40 // created on. |
| 36 // | 41 // |
| 37 // TODO(ajwong): Add support for a timeout. | 42 // TODO(ajwong): Add support for a timeout. |
| 38 class JingleInfoRequest { | 43 class JingleInfoRequest : public sigslot::has_slots<> { |
| 39 public: | 44 public: |
| 40 // Callback to receive the Jingle configuration settings. The argumetns are | 45 // Callback to receive the Jingle configuration settings. The argumetns are |
| 41 // passed by pointer so the receive may call swap on them. The receiver does | 46 // passed by pointer so the receive may call swap on them. The receiver does |
| 42 // NOT own the arguments, which are guaranteed only to be alive for the | 47 // NOT own the arguments, which are guaranteed only to be alive for the |
| 43 // duration of the callback. | 48 // duration of the callback. |
| 44 typedef base::Callback<void ( | 49 typedef base::Callback<void ( |
| 45 const std::string&, const std::vector<std::string>&, | 50 const std::string&, const std::vector<std::string>&, |
| 46 const std::vector<talk_base::SocketAddress>&)> OnJingleInfoCallback; | 51 const std::vector<talk_base::SocketAddress>&)> OnJingleInfoCallback; |
| 47 | 52 |
| 48 explicit JingleInfoRequest(IqRequest* request); | 53 explicit JingleInfoRequest(IqRequest* request, |
| 54 HostAddressResolver* host_resolver); |
| 49 ~JingleInfoRequest(); | 55 ~JingleInfoRequest(); |
| 50 | 56 |
| 51 void Send(const OnJingleInfoCallback& callback); | 57 void Send(const OnJingleInfoCallback& callback); |
| 52 | 58 |
| 53 private: | 59 private: |
| 60 struct PendingDnsRequest; |
| 61 typedef std::map<HostAddressRequest*, PendingDnsRequest*> RequestsMap; |
| 62 |
| 54 void OnResponse(const buzz::XmlElement* stanza); | 63 void OnResponse(const buzz::XmlElement* stanza); |
| 55 | 64 |
| 65 void OnStunAddressResponse(HostAddressRequest* request, |
| 66 const talk_base::SocketAddress& address); |
| 67 void OnRelayAddressResponse(HostAddressRequest* request, |
| 68 const talk_base::SocketAddress& address); |
| 69 |
| 70 void VerifyAllAddressesResolved(); |
| 71 |
| 72 HostAddressResolver* host_resolver_; |
| 56 scoped_ptr<IqRequest> request_; | 73 scoped_ptr<IqRequest> request_; |
| 57 OnJingleInfoCallback on_jingle_info_cb_; | 74 OnJingleInfoCallback on_jingle_info_cb_; |
| 58 | 75 |
| 76 std::vector<std::string> relay_hosts_; |
| 77 std::vector<talk_base::SocketAddress> stun_hosts_; |
| 78 std::string relay_token_; |
| 79 |
| 80 RequestsMap stun_dns_requests_; |
| 81 std::set<HostAddressRequest*> relay_dns_requests_; |
| 82 |
| 59 DISALLOW_COPY_AND_ASSIGN(JingleInfoRequest); | 83 DISALLOW_COPY_AND_ASSIGN(JingleInfoRequest); |
| 60 }; | 84 }; |
| 61 | 85 |
| 62 } // namespace remoting | 86 } // namespace remoting |
| 63 | 87 |
| 64 #endif // REMOTING_JINGLE_GLUE_JINGLE_INFO_REQUEST_H_ | 88 #endif // REMOTING_JINGLE_GLUE_JINGLE_INFO_REQUEST_H_ |
| OLD | NEW |