OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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_SIGNALING_IQ_SENDER_H_ | 5 #ifndef REMOTING_SIGNALING_IQ_SENDER_H_ |
6 #define REMOTING_SIGNALING_IQ_SENDER_H_ | 6 #define REMOTING_SIGNALING_IQ_SENDER_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
| 9 #include <memory> |
9 #include <string> | 10 #include <string> |
10 | 11 |
11 #include "base/callback.h" | 12 #include "base/callback.h" |
12 #include "base/compiler_specific.h" | 13 #include "base/compiler_specific.h" |
13 #include "base/macros.h" | 14 #include "base/macros.h" |
14 #include "base/memory/scoped_ptr.h" | |
15 #include "base/memory/weak_ptr.h" | 15 #include "base/memory/weak_ptr.h" |
16 #include "remoting/signaling/signal_strategy.h" | 16 #include "remoting/signaling/signal_strategy.h" |
17 | 17 |
18 namespace base { | 18 namespace base { |
19 class TimeDelta; | 19 class TimeDelta; |
20 } // namespace base | 20 } // namespace base |
21 | 21 |
22 namespace buzz { | 22 namespace buzz { |
23 class XmlElement; | 23 class XmlElement; |
24 } // namespace buzz | 24 } // namespace buzz |
(...skipping 13 matching lines...) Expand all Loading... |
38 const buzz::XmlElement* response)> ReplyCallback; | 38 const buzz::XmlElement* response)> ReplyCallback; |
39 | 39 |
40 explicit IqSender(SignalStrategy* signal_strategy); | 40 explicit IqSender(SignalStrategy* signal_strategy); |
41 ~IqSender() override; | 41 ~IqSender() override; |
42 | 42 |
43 // Send an iq stanza. Returns an IqRequest object that represends | 43 // Send an iq stanza. Returns an IqRequest object that represends |
44 // the request. |callback| is called when response to |stanza| is | 44 // the request. |callback| is called when response to |stanza| is |
45 // received. Destroy the returned IqRequest to cancel the callback. | 45 // received. Destroy the returned IqRequest to cancel the callback. |
46 // Caller must take ownership of the result. Result must be | 46 // Caller must take ownership of the result. Result must be |
47 // destroyed before sender is destroyed. | 47 // destroyed before sender is destroyed. |
48 scoped_ptr<IqRequest> SendIq(scoped_ptr<buzz::XmlElement> stanza, | 48 std::unique_ptr<IqRequest> SendIq(std::unique_ptr<buzz::XmlElement> stanza, |
49 const ReplyCallback& callback); | 49 const ReplyCallback& callback); |
50 | 50 |
51 // Same as above, but also formats the message. | 51 // Same as above, but also formats the message. |
52 scoped_ptr<IqRequest> SendIq(const std::string& type, | 52 std::unique_ptr<IqRequest> SendIq(const std::string& type, |
53 const std::string& addressee, | 53 const std::string& addressee, |
54 scoped_ptr<buzz::XmlElement> iq_body, | 54 std::unique_ptr<buzz::XmlElement> iq_body, |
55 const ReplyCallback& callback); | 55 const ReplyCallback& callback); |
56 | 56 |
57 // SignalStrategy::Listener implementation. | 57 // SignalStrategy::Listener implementation. |
58 void OnSignalStrategyStateChange(SignalStrategy::State state) override; | 58 void OnSignalStrategyStateChange(SignalStrategy::State state) override; |
59 bool OnSignalStrategyIncomingStanza(const buzz::XmlElement* stanza) override; | 59 bool OnSignalStrategyIncomingStanza(const buzz::XmlElement* stanza) override; |
60 | 60 |
61 private: | 61 private: |
62 typedef std::map<std::string, IqRequest*> IqRequestMap; | 62 typedef std::map<std::string, IqRequest*> IqRequestMap; |
63 friend class IqRequest; | 63 friend class IqRequest; |
64 | 64 |
65 // Helper function used to create iq stanzas. | 65 // Helper function used to create iq stanzas. |
66 static scoped_ptr<buzz::XmlElement> MakeIqStanza( | 66 static std::unique_ptr<buzz::XmlElement> MakeIqStanza( |
67 const std::string& type, | 67 const std::string& type, |
68 const std::string& addressee, | 68 const std::string& addressee, |
69 scoped_ptr<buzz::XmlElement> iq_body); | 69 std::unique_ptr<buzz::XmlElement> iq_body); |
70 | 70 |
71 // Removes |request| from the list of pending requests. Called by IqRequest. | 71 // Removes |request| from the list of pending requests. Called by IqRequest. |
72 void RemoveRequest(IqRequest* request); | 72 void RemoveRequest(IqRequest* request); |
73 | 73 |
74 SignalStrategy* signal_strategy_; | 74 SignalStrategy* signal_strategy_; |
75 IqRequestMap requests_; | 75 IqRequestMap requests_; |
76 | 76 |
77 DISALLOW_COPY_AND_ASSIGN(IqSender); | 77 DISALLOW_COPY_AND_ASSIGN(IqSender); |
78 }; | 78 }; |
79 | 79 |
(...skipping 10 matching lines...) Expand all Loading... |
90 | 90 |
91 private: | 91 private: |
92 friend class IqSender; | 92 friend class IqSender; |
93 | 93 |
94 void CallCallback(const buzz::XmlElement* stanza); | 94 void CallCallback(const buzz::XmlElement* stanza); |
95 void OnTimeout(); | 95 void OnTimeout(); |
96 | 96 |
97 // Called by IqSender when a response is received. | 97 // Called by IqSender when a response is received. |
98 void OnResponse(const buzz::XmlElement* stanza); | 98 void OnResponse(const buzz::XmlElement* stanza); |
99 | 99 |
100 void DeliverResponse(scoped_ptr<buzz::XmlElement> stanza); | 100 void DeliverResponse(std::unique_ptr<buzz::XmlElement> stanza); |
101 | 101 |
102 IqSender* sender_; | 102 IqSender* sender_; |
103 IqSender::ReplyCallback callback_; | 103 IqSender::ReplyCallback callback_; |
104 std::string addressee_; | 104 std::string addressee_; |
105 | 105 |
106 DISALLOW_COPY_AND_ASSIGN(IqRequest); | 106 DISALLOW_COPY_AND_ASSIGN(IqRequest); |
107 }; | 107 }; |
108 | 108 |
109 } // namespace remoting | 109 } // namespace remoting |
110 | 110 |
111 #endif // REMOTING_SIGNALING_IQ_SENDER_H_ | 111 #endif // REMOTING_SIGNALING_IQ_SENDER_H_ |
OLD | NEW |