WebKit Roll 97377:97400.
[chromium-blink-merge.git] / remoting / jingle_glue / javascript_iq_request.h
blobf94fc3356898b380239a0baefe04ae347fe9f1ff
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.
5 #ifndef REMOTING_JINGLE_GLUE_JAVASCRIPT_IQ_REQUEST_H_
6 #define REMOTING_JINGLE_GLUE_JAVASCRIPT_IQ_REQUEST_H_
8 #include <map>
10 #include "base/compiler_specific.h"
11 #include "base/memory/scoped_ptr.h"
12 #include "remoting/jingle_glue/iq_request.h"
14 namespace remoting {
16 class JavascriptIqRequest;
17 class SignalStrategy;
19 class JavascriptIqRegistry {
20 public:
21 JavascriptIqRegistry();
22 virtual ~JavascriptIqRegistry();
24 // Dispatches the response to the IqRequest callback immediately.
26 // Does not take ownership of stanza.
27 void DispatchResponse(buzz::XmlElement* stanza);
29 // Registers |request| with the specified |id|.
30 void RegisterRequest(JavascriptIqRequest* request, const std::string& id);
32 // Removes all entries in the registry that refer to |request|. Useful when
33 // |request| is about to be destructed.
34 void RemoveAllRequests(JavascriptIqRequest* request);
36 void SetDefaultHandler(JavascriptIqRequest* default_request);
38 // Called by JavascriptSignalStrategy.
39 void OnIncomingStanza(const buzz::XmlElement* stanza);
41 private:
42 typedef std::map<std::string, JavascriptIqRequest*> IqRequestMap;
44 IqRequestMap requests_;
45 JavascriptIqRequest* default_handler_;
47 DISALLOW_COPY_AND_ASSIGN(JavascriptIqRegistry);
50 // This call must only be used on the thread it was created on.
51 class JavascriptIqRequest : public IqRequest {
52 public:
53 JavascriptIqRequest(SignalStrategy* signal_strategy,
54 JavascriptIqRegistry* registry);
55 virtual ~JavascriptIqRequest();
57 // IqRequest interface.
58 virtual void SendIq(buzz::XmlElement* iq_body) OVERRIDE;
59 virtual void set_callback(const ReplyCallback& callback) OVERRIDE;
61 private:
62 friend class JavascriptIqRegistry;
64 ReplyCallback callback_;
65 SignalStrategy* signal_strategy_;
66 JavascriptIqRegistry* registry_;
68 FRIEND_TEST_ALL_PREFIXES(IqRequestTest, MakeIqStanza);
71 } // namespace remoting
73 #endif // REMOTING_JINGLE_GLUE_JAVASCRIPT_IQ_REQUEST_H_