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

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

Issue 9004050: Move signaling connection creation out of ChromotingHost. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: - Created 8 years, 12 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 #include "remoting/host/register_support_host_request.h" 5 #include "remoting/host/register_support_host_request.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/message_loop.h" 9 #include "base/message_loop.h"
10 #include "base/string_number_conversions.h" 10 #include "base/string_number_conversions.h"
(...skipping 18 matching lines...) Expand all
29 const char kSignatureTag[] = "signature"; 29 const char kSignatureTag[] = "signature";
30 const char kSignatureTimeAttr[] = "time"; 30 const char kSignatureTimeAttr[] = "time";
31 31
32 // Strings used to parse responses received from the bot. 32 // Strings used to parse responses received from the bot.
33 const char kRegisterQueryResultTag[] = "register-support-host-result"; 33 const char kRegisterQueryResultTag[] = "register-support-host-result";
34 const char kSupportIdTag[] = "support-id"; 34 const char kSupportIdTag[] = "support-id";
35 const char kSupportIdLifetimeTag[] = "support-id-lifetime"; 35 const char kSupportIdLifetimeTag[] = "support-id-lifetime";
36 } 36 }
37 37
38 RegisterSupportHostRequest::RegisterSupportHostRequest() 38 RegisterSupportHostRequest::RegisterSupportHostRequest()
39 : message_loop_(NULL) { 39 : signal_strategy_(NULL) {
40 } 40 }
41 41
42 RegisterSupportHostRequest::~RegisterSupportHostRequest() { 42 RegisterSupportHostRequest::~RegisterSupportHostRequest() {
43 if (signal_strategy_)
44 signal_strategy_->RemoveListener(this);
43 } 45 }
44 46
45 bool RegisterSupportHostRequest::Init(HostConfig* config, 47 bool RegisterSupportHostRequest::Init(SignalStrategy* signal_strategy,
48 HostConfig* config,
46 const RegisterCallback& callback) { 49 const RegisterCallback& callback) {
47 callback_ = callback;
48
49 if (!key_pair_.Load(config)) { 50 if (!key_pair_.Load(config)) {
Wez 2012/01/03 16:25:04 nit: Consider DCHECK()ing |signal_strategy|, since
Sergey Ulanov 2012/01/03 21:51:02 Fixed in a different CL.
50 return false; 51 return false;
51 } 52 }
53
54 callback_ = callback;
55 signal_strategy_ = signal_strategy;
56 signal_strategy_->AddListener(this);
57 iq_sender_.reset(new IqSender(signal_strategy_));
58
52 return true; 59 return true;
53 } 60 }
54 61
55 void RegisterSupportHostRequest::OnSignallingConnected( 62 void RegisterSupportHostRequest::OnSignalStrategyStateChange(
56 SignalStrategy* signal_strategy) { 63 SignalStrategy::State state) {
57 DCHECK(!callback_.is_null()); 64 if (state == SignalStrategy::CONNECTED) {
65 DCHECK(!callback_.is_null());
58 66
59 message_loop_ = MessageLoop::current(); 67 request_.reset(iq_sender_->SendIq(
60 68 buzz::STR_SET, kChromotingBotJid,
61 iq_sender_.reset(new IqSender(signal_strategy)); 69 CreateRegistrationRequest(signal_strategy_->GetLocalJid()),
62 request_.reset(iq_sender_->SendIq( 70 base::Bind(&RegisterSupportHostRequest::ProcessResponse,
63 buzz::STR_SET, kChromotingBotJid, 71 base::Unretained(this))));
64 CreateRegistrationRequest(signal_strategy->GetLocalJid()), 72 } else if (state == SignalStrategy::DISCONNECTED) {
65 base::Bind(&RegisterSupportHostRequest::ProcessResponse, 73 request_.reset();
66 base::Unretained(this)))); 74 if (!callback_.is_null()) {
75 // We will reach here if signaling fails to connect.
Wez 2012/01/03 16:25:04 Or if signalling disconnects before we've received
Sergey Ulanov 2012/01/03 21:51:02 Done.
76 RegisterCallback callback = callback_;
77 callback_.Reset();
78 callback.Run(false, std::string(), base::TimeDelta());
79 }
80 }
67 } 81 }
68 82
69 void RegisterSupportHostRequest::OnSignallingDisconnected() { 83 bool RegisterSupportHostRequest::OnSignalStrategyIncomingStanza(
70 if (!message_loop_) { 84 const buzz::XmlElement* stanza) {
71 // We will reach here with |message_loop_| NULL if the Host's 85 return false;
72 // XMPP connection attempt fails.
73 CHECK(!callback_.is_null());
74 DCHECK(!request_.get());
75 callback_.Run(false, std::string(), base::TimeDelta());
76 return;
77 }
78 DCHECK_EQ(message_loop_, MessageLoop::current());
79 request_.reset();
80 iq_sender_.reset();
81 } 86 }
82 87
83 // Ignore any notifications other than signalling
84 // connected/disconnected events.
85 void RegisterSupportHostRequest::OnAccessDenied() { }
86 void RegisterSupportHostRequest::OnClientAuthenticated(
87 const std::string& jid) { }
88 void RegisterSupportHostRequest::OnClientDisconnected(
89 const std::string& jid) { }
90 void RegisterSupportHostRequest::OnShutdown() { }
91
92 XmlElement* RegisterSupportHostRequest::CreateRegistrationRequest( 88 XmlElement* RegisterSupportHostRequest::CreateRegistrationRequest(
93 const std::string& jid) { 89 const std::string& jid) {
94 XmlElement* query = new XmlElement( 90 XmlElement* query = new XmlElement(
95 QName(kChromotingXmlNamespace, kRegisterQueryTag)); 91 QName(kChromotingXmlNamespace, kRegisterQueryTag));
96 XmlElement* public_key = new XmlElement( 92 XmlElement* public_key = new XmlElement(
97 QName(kChromotingXmlNamespace, kPublicKeyTag)); 93 QName(kChromotingXmlNamespace, kPublicKeyTag));
98 public_key->AddText(key_pair_.GetPublicKey()); 94 public_key->AddText(key_pair_.GetPublicKey());
99 query->AddElement(public_key); 95 query->AddElement(public_key);
100 query->AddElement(CreateSignature(jid)); 96 query->AddElement(CreateSignature(jid));
101 return query; 97 return query;
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
171 return false; 167 return false;
172 } 168 }
173 169
174 *support_id = support_id_element->BodyText(); 170 *support_id = support_id_element->BodyText();
175 *lifetime = base::TimeDelta::FromSeconds(lifetime_int); 171 *lifetime = base::TimeDelta::FromSeconds(lifetime_int);
176 return true; 172 return true;
177 } 173 }
178 174
179 175
180 void RegisterSupportHostRequest::ProcessResponse(const XmlElement* response) { 176 void RegisterSupportHostRequest::ProcessResponse(const XmlElement* response) {
181 DCHECK_EQ(message_loop_, MessageLoop::current());
182 std::string support_id; 177 std::string support_id;
183 base::TimeDelta lifetime; 178 base::TimeDelta lifetime;
184 bool success = ParseResponse(response, &support_id, &lifetime); 179 bool success = ParseResponse(response, &support_id, &lifetime);
185 callback_.Run(success, support_id, lifetime); 180 RegisterCallback callback = callback_;
181 callback_.Reset();
182 callback.Run(success, support_id, lifetime);
186 } 183 }
187 184
188 } // namespace remoting 185 } // namespace remoting
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698