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

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

Issue 8432009: Refactor IqRequest. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: - Created 9 years, 1 month 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
(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 REMOTING_JINGLE_GLUE_IQ_REQUEST_H_
6 #define REMOTING_JINGLE_GLUE_IQ_REQUEST_H_
7
8 #include <map>
9 #include <string>
10
11 #include "base/callback.h"
12 #include "base/compiler_specific.h"
13 #include "base/gtest_prod_util.h"
14 #include "base/memory/scoped_ptr.h"
15 #include "remoting/jingle_glue/iq_request.h"
16
17 namespace buzz {
18 class XmlElement;
19 } // namespace buzz
20
21 namespace remoting {
22
23 class IqRequest;
24 class SignalStrategy;
25
26 // IqRegistry handles routing of iq responses to corresponding
27 // IqRequest objects. Created in SignalStrategy and should not be used
28 // directly.
29 //
30 // TODO(sergeyu): Separate IqRegistry and IqRequest from
31 // SignalStrategy and remove CreateIqRequest() method from SignalStrategy.
32 class IqRegistry {
33 public:
34 IqRegistry();
35 ~IqRegistry();
36
37 // Dispatches the response to the IqRequest callback immediately.
38 //
39 // Does not take ownership of stanza.
40 void DispatchResponse(buzz::XmlElement* stanza);
41
42 // Registers |request| with the specified |id|.
43 void RegisterRequest(IqRequest* request, const std::string& id);
44
45 // Removes all entries in the registry that refer to |request|.
46 void RemoveAllRequests(IqRequest* request);
47
48 void SetDefaultHandler(IqRequest* default_request);
49
50 // Called by SignalStrategy implementation. Returns true if the
51 // stanza was handled and should not be processed further.
52 bool OnIncomingStanza(const buzz::XmlElement* stanza);
53
54 private:
55 typedef std::map<std::string, IqRequest*> IqRequestMap;
56
57 IqRequestMap requests_;
58
59 DISALLOW_COPY_AND_ASSIGN(IqRegistry);
60 };
61
62 // This call must only be used on the thread it was created on.
63 class IqRequest {
64 public:
65 typedef base::Callback<void(const buzz::XmlElement*)> ReplyCallback;
66
67 static buzz::XmlElement* MakeIqStanza(const std::string& type,
68 const std::string& addressee,
69 buzz::XmlElement* iq_body);
70
71 IqRequest(); // Should be used for tests only.
72 IqRequest(SignalStrategy* signal_strategy, IqRegistry* registry);
73 virtual ~IqRequest();
74
75 // Sends Iq stanza. Takes ownership of |stanza|.
76 virtual void SendIq(buzz::XmlElement* stanza);
77
78 // Sets callback that is called when reply stanza is received.
79 virtual void set_callback(const ReplyCallback& callback);
80
81 private:
82 friend class IqRegistry;
83 FRIEND_TEST_ALL_PREFIXES(IqRequestTest, MakeIqStanza);
84
85 ReplyCallback callback_;
86 SignalStrategy* signal_strategy_;
87 IqRegistry* registry_;
88
89 DISALLOW_COPY_AND_ASSIGN(IqRequest);
90 };
91
92 } // namespace remoting
93
94 #endif // REMOTING_JINGLE_GLUE_IQ_REQUEST_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698