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

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

Issue 9452038: Implement timeouts for IQ requests. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix release build 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"
15 #include "remoting/jingle_glue/signal_strategy.h" 16 #include "remoting/jingle_glue/signal_strategy.h"
16 17
18 namespace base {
19 class TimeDelta;
20 } // namespace base
21
17 namespace buzz { 22 namespace buzz {
18 class XmlElement; 23 class XmlElement;
19 } // namespace buzz 24 } // namespace buzz
20 25
21 namespace remoting { 26 namespace remoting {
22 27
23 class IqRequest; 28 class IqRequest;
24 class SignalStrategy; 29 class SignalStrategy;
25 30
26 // IqSender handles sending iq requests and routing of responses to 31 // IqSender handles sending iq requests and routing of responses to
27 // those requests. 32 // those requests.
28 class IqSender : public SignalStrategy::Listener { 33 class IqSender : public SignalStrategy::Listener {
29 public: 34 public:
30 typedef base::Callback<void(const buzz::XmlElement*)> ReplyCallback; 35 // Callback that is called when an Iq response is received. Called
36 // with the |response| set to NULL in case of a timeout.
37 typedef base::Callback<void(IqRequest* request,
38 const buzz::XmlElement* response)> ReplyCallback;
31 39
32 explicit IqSender(SignalStrategy* signal_strategy); 40 explicit IqSender(SignalStrategy* signal_strategy);
33 virtual ~IqSender(); 41 virtual ~IqSender();
34 42
35 // Send an iq stanza. Returns an IqRequest object that represends 43 // Send an iq stanza. Returns an IqRequest object that represends
36 // the request. |callback| is called when response to |stanza| is 44 // the request. |callback| is called when response to |stanza| is
37 // received. Destroy the returned IqRequest to cancel the callback. 45 // received. Destroy the returned IqRequest to cancel the callback.
38 // Caller must take ownership of the result. Result must be 46 // Caller must take ownership of the result. Result must be
39 // destroyed before sender is destroyed. 47 // destroyed before sender is destroyed.
40 scoped_ptr<IqRequest> SendIq(scoped_ptr<buzz::XmlElement> stanza, 48 scoped_ptr<IqRequest> SendIq(scoped_ptr<buzz::XmlElement> stanza,
(...skipping 24 matching lines...) Expand all
65 // Removes |request| from the list of pending requests. Called by IqRequest. 73 // Removes |request| from the list of pending requests. Called by IqRequest.
66 void RemoveRequest(IqRequest* request); 74 void RemoveRequest(IqRequest* request);
67 75
68 SignalStrategy* signal_strategy_; 76 SignalStrategy* signal_strategy_;
69 IqRequestMap requests_; 77 IqRequestMap requests_;
70 78
71 DISALLOW_COPY_AND_ASSIGN(IqSender); 79 DISALLOW_COPY_AND_ASSIGN(IqSender);
72 }; 80 };
73 81
74 // This call must only be used on the thread it was created on. 82 // This call must only be used on the thread it was created on.
75 class IqRequest { 83 class IqRequest : public base::SupportsWeakPtr<IqRequest> {
76 public: 84 public:
77 IqRequest(IqSender* sender, const IqSender::ReplyCallback& callback); 85 IqRequest(IqSender* sender, const IqSender::ReplyCallback& callback,
86 const std::string& addressee);
78 ~IqRequest(); 87 ~IqRequest();
79 88
89 // Sets timeout for the request. When the timeout expires the
90 // callback is called with the |response| set to NULL.
91 void SetTimeout(base::TimeDelta timeout);
92
80 private: 93 private:
81 friend class IqSender; 94 friend class IqSender;
82 95
96 void CallCallback(const buzz::XmlElement* stanza);
97 void OnTimeout();
98
83 // Called by IqSender when a response is received. 99 // Called by IqSender when a response is received.
84 void OnResponse(const buzz::XmlElement* stanza); 100 void OnResponse(const buzz::XmlElement* stanza);
85 101
86 IqSender* sender_; 102 IqSender* sender_;
87 IqSender::ReplyCallback callback_; 103 IqSender::ReplyCallback callback_;
104 std::string addressee_;
88 105
89 DISALLOW_COPY_AND_ASSIGN(IqRequest); 106 DISALLOW_COPY_AND_ASSIGN(IqRequest);
90 }; 107 };
91 108
92 } // namespace remoting 109 } // namespace remoting
93 110
94 #endif // REMOTING_JINGLE_GLUE_IQ_SENDER_H_ 111 #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