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
3 // found in the LICENSE file.
5 #ifndef REMOTING_HOST_REGISTER_SUPPORT_HOST_REQUEST_H_
6 #define REMOTING_HOST_REGISTER_SUPPORT_HOST_REQUEST_H_
10 #include "base/callback.h"
11 #include "base/memory/ref_counted.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "remoting/base/rsa_key_pair.h"
14 #include "remoting/signaling/signal_strategy.h"
15 #include "testing/gtest/include/gtest/gtest_prod.h"
30 // RegisterSupportHostRequest sends a request to register the host for
31 // a SupportID, as soon as the associated SignalStrategy becomes
32 // connected. When a response is received from the bot, it calls the
33 // callback specified in the Init() method.
34 class RegisterSupportHostRequest
: public SignalStrategy::Listener
{
36 // First parameter is set to true on success. Second parameter is
37 // the new SessionID received from the bot. Third parameter is the
38 // amount of time until that id expires.
39 typedef base::Callback
<void(bool, const std::string
&,
40 const base::TimeDelta
&)> RegisterCallback
;
42 // |signal_strategy| and |key_pair| must outlive this
43 // object. |callback| is called when registration response is
44 // received from the server. Callback is never called if the bot
45 // malfunctions and doesn't respond to the request.
47 // TODO(sergeyu): This class should have timeout for the bot
49 RegisterSupportHostRequest(SignalStrategy
* signal_strategy
,
50 scoped_refptr
<RsaKeyPair
> key_pair
,
51 const std::string
& directory_bot_jid
,
52 const RegisterCallback
& callback
);
53 virtual ~RegisterSupportHostRequest();
55 // HostStatusObserver implementation.
56 virtual void OnSignalStrategyStateChange(
57 SignalStrategy::State state
) OVERRIDE
;
58 virtual bool OnSignalStrategyIncomingStanza(
59 const buzz::XmlElement
* stanza
) OVERRIDE
;
64 scoped_ptr
<buzz::XmlElement
> CreateRegistrationRequest(
65 const std::string
& jid
);
66 scoped_ptr
<buzz::XmlElement
> CreateSignature(const std::string
& jid
);
68 void ProcessResponse(IqRequest
* request
, const buzz::XmlElement
* response
);
69 bool ParseResponse(const buzz::XmlElement
* response
,
70 std::string
* support_id
, base::TimeDelta
* lifetime
);
73 bool success
, const std::string
& support_id
, base::TimeDelta lifetime
);
75 SignalStrategy
* signal_strategy_
;
76 scoped_refptr
<RsaKeyPair
> key_pair_
;
77 std::string directory_bot_jid_
;
78 RegisterCallback callback_
;
80 scoped_ptr
<IqSender
> iq_sender_
;
81 scoped_ptr
<IqRequest
> request_
;
83 DISALLOW_COPY_AND_ASSIGN(RegisterSupportHostRequest
);
86 } // namespace remoting
88 #endif // REMOTING_HOST_REGISTER_SUPPORT_HOST_REQUEST_H_