Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(98)

Side by Side Diff: remoting/jingle_glue/iq_sender.h

Issue 9447087: Revert 123635 - Implement timeouts for IQ requests. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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_IQ_SENDER_H_ 5 #ifndef REMOTING_JINGLE_GLUE_IQ_SENDER_H_
6 #define REMOTING_JINGLE_GLUE_IQ_SENDER_H_ 6 #define REMOTING_JINGLE_GLUE_IQ_SENDER_H_
7 7
8 #include <map> 8 #include <map>
9 #include <string> 9 #include <string>
10 10
11 #include "base/callback.h" 11 #include "base/callback.h"
12 #include "base/compiler_specific.h" 12 #include "base/compiler_specific.h"
13 #include "base/gtest_prod_util.h" 13 #include "base/gtest_prod_util.h"
14 #include "base/memory/scoped_ptr.h" 14 #include "base/memory/scoped_ptr.h"
15 #include "base/memory/weak_ptr.h"
16 #include "remoting/jingle_glue/signal_strategy.h" 15 #include "remoting/jingle_glue/signal_strategy.h"
17 16
18 namespace buzz { 17 namespace buzz {
19 class XmlElement; 18 class XmlElement;
20 } // namespace buzz 19 } // namespace buzz
21 20
22 namespace remoting { 21 namespace remoting {
23 22
24 class IqRequest; 23 class IqRequest;
25 class SignalStrategy; 24 class SignalStrategy;
26 25
27 // IqSender handles sending iq requests and routing of responses to 26 // IqSender handles sending iq requests and routing of responses to
28 // those requests. 27 // those requests.
29 class IqSender : public SignalStrategy::Listener { 28 class IqSender : public SignalStrategy::Listener {
30 public: 29 public:
31 // Callback that is called when an Iq response is received. Called 30 typedef base::Callback<void(const buzz::XmlElement*)> ReplyCallback;
32 // with the |response| set to NULL in case of a timeout.
33 typedef base::Callback<void(IqRequest* request,
34 const buzz::XmlElement* response)> ReplyCallback;
35 31
36 explicit IqSender(SignalStrategy* signal_strategy); 32 explicit IqSender(SignalStrategy* signal_strategy);
37 virtual ~IqSender(); 33 virtual ~IqSender();
38 34
39 // Send an iq stanza. Returns an IqRequest object that represends 35 // Send an iq stanza. Returns an IqRequest object that represends
40 // the request. |callback| is called when response to |stanza| is 36 // the request. |callback| is called when response to |stanza| is
41 // received. Destroy the returned IqRequest to cancel the callback. 37 // received. Destroy the returned IqRequest to cancel the callback.
42 // Caller must take ownership of the result. Result must be 38 // Caller must take ownership of the result. Result must be
43 // destroyed before sender is destroyed. 39 // destroyed before sender is destroyed.
44 scoped_ptr<IqRequest> SendIq(scoped_ptr<buzz::XmlElement> stanza, 40 scoped_ptr<IqRequest> SendIq(scoped_ptr<buzz::XmlElement> stanza,
(...skipping 24 matching lines...) Expand all
69 // Removes |request| from the list of pending requests. Called by IqRequest. 65 // Removes |request| from the list of pending requests. Called by IqRequest.
70 void RemoveRequest(IqRequest* request); 66 void RemoveRequest(IqRequest* request);
71 67
72 SignalStrategy* signal_strategy_; 68 SignalStrategy* signal_strategy_;
73 IqRequestMap requests_; 69 IqRequestMap requests_;
74 70
75 DISALLOW_COPY_AND_ASSIGN(IqSender); 71 DISALLOW_COPY_AND_ASSIGN(IqSender);
76 }; 72 };
77 73
78 // This call must only be used on the thread it was created on. 74 // This call must only be used on the thread it was created on.
79 class IqRequest : public base::SupportsWeakPtr<IqRequest> { 75 class IqRequest {
80 public: 76 public:
81 IqRequest(IqSender* sender, const IqSender::ReplyCallback& callback, 77 IqRequest(IqSender* sender, const IqSender::ReplyCallback& callback);
82 const std::string& addressee);
83 ~IqRequest(); 78 ~IqRequest();
84 79
85 // Sets timeout for the request. When the timeout expires the
86 // callback is called with the |response| set to NULL.
87 void SetTimeout(base::TimeDelta timeout);
88
89 private: 80 private:
90 friend class IqSender; 81 friend class IqSender;
91 82
92 void CallCallback(const buzz::XmlElement* stanza);
93 void OnTimeout();
94
95 // Called by IqSender when a response is received. 83 // Called by IqSender when a response is received.
96 void OnResponse(const buzz::XmlElement* stanza); 84 void OnResponse(const buzz::XmlElement* stanza);
97 85
98 IqSender* sender_; 86 IqSender* sender_;
99 IqSender::ReplyCallback callback_; 87 IqSender::ReplyCallback callback_;
100 std::string addressee_;
101 88
102 DISALLOW_COPY_AND_ASSIGN(IqRequest); 89 DISALLOW_COPY_AND_ASSIGN(IqRequest);
103 }; 90 };
104 91
105 } // namespace remoting 92 } // namespace remoting
106 93
107 #endif // REMOTING_JINGLE_GLUE_IQ_SENDER_H_ 94 #endif // REMOTING_JINGLE_GLUE_IQ_SENDER_H_
OLDNEW
« no previous file with comments | « remoting/host/register_support_host_request_unittest.cc ('k') | remoting/jingle_glue/iq_sender.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698