Update content setting for app banners to store more information.
[chromium-blink-merge.git] / remoting / host / register_support_host_request.h
blob00c1d711dc21017aa3a3b56a619e9e556926a49b
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_
8 #include <string>
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"
17 namespace buzz {
18 class XmlElement;
19 } // namespace buzz
21 namespace base {
22 class TimeDelta;
23 } // namespace base
25 namespace remoting {
27 class IqRequest;
28 class IqSender;
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 {
35 public:
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
48 // response.
49 RegisterSupportHostRequest(SignalStrategy* signal_strategy,
50 scoped_refptr<RsaKeyPair> key_pair,
51 const std::string& directory_bot_jid,
52 const RegisterCallback& callback);
53 ~RegisterSupportHostRequest() override;
55 // HostStatusObserver implementation.
56 void OnSignalStrategyStateChange(SignalStrategy::State state) override;
57 bool OnSignalStrategyIncomingStanza(const buzz::XmlElement* stanza) override;
59 private:
60 void DoSend();
62 scoped_ptr<buzz::XmlElement> CreateRegistrationRequest(
63 const std::string& jid);
64 scoped_ptr<buzz::XmlElement> CreateSignature(const std::string& jid);
66 void ProcessResponse(IqRequest* request, const buzz::XmlElement* response);
67 bool ParseResponse(const buzz::XmlElement* response,
68 std::string* support_id, base::TimeDelta* lifetime);
70 void CallCallback(
71 bool success, const std::string& support_id, base::TimeDelta lifetime);
73 SignalStrategy* signal_strategy_;
74 scoped_refptr<RsaKeyPair> key_pair_;
75 std::string directory_bot_jid_;
76 RegisterCallback callback_;
78 scoped_ptr<IqSender> iq_sender_;
79 scoped_ptr<IqRequest> request_;
81 DISALLOW_COPY_AND_ASSIGN(RegisterSupportHostRequest);
84 } // namespace remoting
86 #endif // REMOTING_HOST_REGISTER_SUPPORT_HOST_REQUEST_H_