Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / remoting / host / register_support_host_request.h
blob07b36bba33f9e53c1fb2deb1ce65ac2c2f18e352
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 the new SessionID received from the bot. Second
37 // parameter is the amount of time until that id expires. Third parameter
38 // is an error message if the request failed, or null if it succeeded.
39 typedef base::Callback<void(const std::string&,
40 const base::TimeDelta&,
41 const std::string&)> RegisterCallback;
43 // |signal_strategy| and |key_pair| must outlive this
44 // object. |callback| is called when registration response is
45 // received from the server. Callback is never called if the bot
46 // malfunctions and doesn't respond to the request.
48 // TODO(sergeyu): This class should have timeout for the bot
49 // response.
50 RegisterSupportHostRequest(SignalStrategy* signal_strategy,
51 scoped_refptr<RsaKeyPair> key_pair,
52 const std::string& directory_bot_jid,
53 const RegisterCallback& callback);
54 ~RegisterSupportHostRequest() override;
56 // HostStatusObserver implementation.
57 void OnSignalStrategyStateChange(SignalStrategy::State state) override;
58 bool OnSignalStrategyIncomingStanza(const buzz::XmlElement* stanza) override;
60 private:
61 void DoSend();
63 scoped_ptr<buzz::XmlElement> CreateRegistrationRequest(
64 const std::string& jid);
65 scoped_ptr<buzz::XmlElement> CreateSignature(const std::string& jid);
67 void ProcessResponse(IqRequest* request, const buzz::XmlElement* response);
68 void ParseResponse(const buzz::XmlElement* response,
69 std::string* support_id, base::TimeDelta* lifetime,
70 std::string* error_message);
72 void CallCallback(
73 const std::string& support_id, base::TimeDelta lifetime,
74 const std::string& error_message);
76 SignalStrategy* signal_strategy_;
77 scoped_refptr<RsaKeyPair> key_pair_;
78 std::string directory_bot_jid_;
79 RegisterCallback callback_;
81 scoped_ptr<IqSender> iq_sender_;
82 scoped_ptr<IqRequest> request_;
84 DISALLOW_COPY_AND_ASSIGN(RegisterSupportHostRequest);
87 } // namespace remoting
89 #endif // REMOTING_HOST_REGISTER_SUPPORT_HOST_REQUEST_H_