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

Side by Side Diff: remoting/host/register_support_host_request.h

Issue 9004050: Move signaling connection creation out of ChromotingHost. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: - Created 8 years, 11 months 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
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef REMOTING_HOST_REGISTER_SUPPORT_HOST_REQUEST_H_ 5 #ifndef REMOTING_HOST_REGISTER_SUPPORT_HOST_REQUEST_H_
6 #define REMOTING_HOST_REGISTER_SUPPORT_HOST_REQUEST_H_ 6 #define REMOTING_HOST_REGISTER_SUPPORT_HOST_REQUEST_H_
7 7
8 #include <string> 8 #include <string>
9 9
10 #include "base/callback.h" 10 #include "base/callback.h"
11 #include "base/memory/ref_counted.h" 11 #include "base/memory/ref_counted.h"
12 #include "base/memory/scoped_ptr.h" 12 #include "base/memory/scoped_ptr.h"
13 #include "remoting/jingle_glue/signal_strategy.h"
13 #include "remoting/host/host_key_pair.h" 14 #include "remoting/host/host_key_pair.h"
14 #include "remoting/host/host_status_observer.h"
15 #include "testing/gtest/include/gtest/gtest_prod.h" 15 #include "testing/gtest/include/gtest/gtest_prod.h"
16 16
17 class MessageLoop; 17 class MessageLoop;
18 18
19 namespace buzz { 19 namespace buzz {
20 class XmlElement; 20 class XmlElement;
21 } // namespace buzz 21 } // namespace buzz
22 22
23 namespace base { 23 namespace base {
24 class TimeDelta; 24 class TimeDelta;
25 } // namespace base 25 } // namespace base
26 26
27 namespace remoting { 27 namespace remoting {
28 28
29 class IqRequest; 29 class IqRequest;
30 class IqSender; 30 class IqSender;
31 31
32 // RegisterSupportHostRequest sends support host registeration request 32 // RegisterSupportHostRequest sends a request to register the host for
33 // to the Chromoting Bot. It listens to the status of the host using 33 // a SupportID, as soon as the associated SignalStrategy becomes
34 // HostStatusObserver interface and sends the request when signalling 34 // connected. When a response is received from the bot, it calls the
35 // channel is connected. When a response is received from the bot, it 35 // callback specified in the Init() method.
36 // calls the callback specified in the Init() method. 36 class RegisterSupportHostRequest : public SignalStrategy::Listener {
37 class RegisterSupportHostRequest : public HostStatusObserver {
38 public: 37 public:
39 // First parameter is set to true on success. Second parameter is 38 // First parameter is set to true on success. Second parameter is
40 // the new SessionID received from the bot. Third parameter is the 39 // the new SessionID received from the bot. Third parameter is the
41 // amount of time until that id expires. 40 // amount of time until that id expires.
42 typedef base::Callback<void(bool, const std::string&, 41 typedef base::Callback<void(bool, const std::string&,
43 const base::TimeDelta&)> RegisterCallback; 42 const base::TimeDelta&)> RegisterCallback;
44 43
45 RegisterSupportHostRequest(); 44 RegisterSupportHostRequest();
46 virtual ~RegisterSupportHostRequest(); 45 virtual ~RegisterSupportHostRequest();
47 46
48 // Provide the configuration to use to register the host, and a 47 // Initializes the registration to use the |signal_startegy| and to
49 // callback to invoke when a registration response is received. 48 // notify |callback| upon completion or failure. Returns false on
50 // |callback| is called when registration response is received from 49 // falure (e.g. config is invalid). Callback is never called if the
51 // the server. Ownership of |callback| is given to the request 50 // bot malfunctions and doesn't respond to the request.
52 // object. Caller must ensure that the callback object is valid 51 //
53 // while signalling connection exists. Returns false on falure 52 // TODO(sergeyu): This class should have timeout for the bot
54 // (e.g. config is invalid). Callback is never called if the bot 53 // response.
55 // malfunctions and doesn't respond to the request. 54 bool Init(SignalStrategy* signal_strategy,
56 bool Init(HostConfig* config, const RegisterCallback& callback); 55 HostConfig* config,
56 const RegisterCallback& callback);
57 57
58 // HostStatusObserver implementation. 58 // HostStatusObserver implementation.
59 virtual void OnSignallingConnected(SignalStrategy* signal_strategy) OVERRIDE; 59 virtual void OnSignalStrategyStateChange(
60 virtual void OnSignallingDisconnected() OVERRIDE; 60 SignalStrategy::State state) OVERRIDE;
61 virtual void OnClientAuthenticated(const std::string& jid) OVERRIDE; 61 virtual bool OnSignalStrategyIncomingStanza(
62 virtual void OnClientDisconnected(const std::string& jid) OVERRIDE; 62 const buzz::XmlElement* stanza) OVERRIDE;
63 virtual void OnAccessDenied() OVERRIDE;
64 virtual void OnShutdown() OVERRIDE;
65 63
66 private: 64 private:
67 void DoSend(); 65 void DoSend();
68 66
69 // Caller owns the result. 67 // Caller owns the result.
70 buzz::XmlElement* CreateRegistrationRequest(const std::string& jid); 68 buzz::XmlElement* CreateRegistrationRequest(const std::string& jid);
71 buzz::XmlElement* CreateSignature(const std::string& jid); 69 buzz::XmlElement* CreateSignature(const std::string& jid);
72 70
73 void ProcessResponse(const buzz::XmlElement* response); 71 void ProcessResponse(const buzz::XmlElement* response);
74 bool ParseResponse(const buzz::XmlElement* response, 72 bool ParseResponse(const buzz::XmlElement* response,
75 std::string* support_id, base::TimeDelta* lifetime); 73 std::string* support_id, base::TimeDelta* lifetime);
76 74
77 MessageLoop* message_loop_; 75 void CallCallback(
76 bool success, const std::string& support_id, base::TimeDelta lifetime);
77
78 SignalStrategy* signal_strategy_;
78 RegisterCallback callback_; 79 RegisterCallback callback_;
79 scoped_ptr<IqSender> iq_sender_; 80 scoped_ptr<IqSender> iq_sender_;
80 scoped_ptr<IqRequest> request_; 81 scoped_ptr<IqRequest> request_;
81 HostKeyPair key_pair_; 82 HostKeyPair key_pair_;
82 83
83 DISALLOW_COPY_AND_ASSIGN(RegisterSupportHostRequest); 84 DISALLOW_COPY_AND_ASSIGN(RegisterSupportHostRequest);
84 }; 85 };
85 86
86 } // namespace remoting 87 } // namespace remoting
87 88
88 #endif // REMOTING_HOST_REGISTER_SUPPORT_HOST_REQUEST_H_ 89 #endif // REMOTING_HOST_REGISTER_SUPPORT_HOST_REQUEST_H_
OLDNEW
« no previous file with comments | « remoting/host/plugin/host_script_object.cc ('k') | remoting/host/register_support_host_request.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698