Chromium Code Reviews| Index: remoting/host/register_support_host_request.cc |
| diff --git a/remoting/host/register_support_host_request.cc b/remoting/host/register_support_host_request.cc |
| index 5668f278d793c88711a7b6107aa3e736be191cd0..9e19d8fa68bbadde84d21663b3a91186407fbfc9 100644 |
| --- a/remoting/host/register_support_host_request.cc |
| +++ b/remoting/host/register_support_host_request.cc |
| @@ -36,58 +36,54 @@ const char kSupportIdLifetimeTag[] = "support-id-lifetime"; |
| } |
| RegisterSupportHostRequest::RegisterSupportHostRequest() |
| - : message_loop_(NULL) { |
| + : signal_strategy_(NULL) { |
| } |
| RegisterSupportHostRequest::~RegisterSupportHostRequest() { |
| + if (signal_strategy_) |
| + signal_strategy_->RemoveListener(this); |
| } |
| -bool RegisterSupportHostRequest::Init(HostConfig* config, |
| +bool RegisterSupportHostRequest::Init(SignalStrategy* signal_strategy, |
| + HostConfig* config, |
| const RegisterCallback& callback) { |
| - callback_ = callback; |
| - |
| 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.
|
| return false; |
| } |
| - return true; |
| -} |
| -void RegisterSupportHostRequest::OnSignallingConnected( |
| - SignalStrategy* signal_strategy) { |
| - DCHECK(!callback_.is_null()); |
| - |
| - message_loop_ = MessageLoop::current(); |
| + callback_ = callback; |
| + signal_strategy_ = signal_strategy; |
| + signal_strategy_->AddListener(this); |
| + iq_sender_.reset(new IqSender(signal_strategy_)); |
| - iq_sender_.reset(new IqSender(signal_strategy)); |
| - request_.reset(iq_sender_->SendIq( |
| - buzz::STR_SET, kChromotingBotJid, |
| - CreateRegistrationRequest(signal_strategy->GetLocalJid()), |
| - base::Bind(&RegisterSupportHostRequest::ProcessResponse, |
| - base::Unretained(this)))); |
| + return true; |
| } |
| -void RegisterSupportHostRequest::OnSignallingDisconnected() { |
| - if (!message_loop_) { |
| - // We will reach here with |message_loop_| NULL if the Host's |
| - // XMPP connection attempt fails. |
| - CHECK(!callback_.is_null()); |
| - DCHECK(!request_.get()); |
| - callback_.Run(false, std::string(), base::TimeDelta()); |
| - return; |
| +void RegisterSupportHostRequest::OnSignalStrategyStateChange( |
| + SignalStrategy::State state) { |
| + if (state == SignalStrategy::CONNECTED) { |
| + DCHECK(!callback_.is_null()); |
| + |
| + request_.reset(iq_sender_->SendIq( |
| + buzz::STR_SET, kChromotingBotJid, |
| + CreateRegistrationRequest(signal_strategy_->GetLocalJid()), |
| + base::Bind(&RegisterSupportHostRequest::ProcessResponse, |
| + base::Unretained(this)))); |
| + } else if (state == SignalStrategy::DISCONNECTED) { |
| + request_.reset(); |
| + if (!callback_.is_null()) { |
| + // 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.
|
| + RegisterCallback callback = callback_; |
| + callback_.Reset(); |
| + callback.Run(false, std::string(), base::TimeDelta()); |
| + } |
| } |
| - DCHECK_EQ(message_loop_, MessageLoop::current()); |
| - request_.reset(); |
| - iq_sender_.reset(); |
| } |
| -// Ignore any notifications other than signalling |
| -// connected/disconnected events. |
| -void RegisterSupportHostRequest::OnAccessDenied() { } |
| -void RegisterSupportHostRequest::OnClientAuthenticated( |
| - const std::string& jid) { } |
| -void RegisterSupportHostRequest::OnClientDisconnected( |
| - const std::string& jid) { } |
| -void RegisterSupportHostRequest::OnShutdown() { } |
| +bool RegisterSupportHostRequest::OnSignalStrategyIncomingStanza( |
| + const buzz::XmlElement* stanza) { |
| + return false; |
| +} |
| XmlElement* RegisterSupportHostRequest::CreateRegistrationRequest( |
| const std::string& jid) { |
| @@ -178,11 +174,12 @@ bool RegisterSupportHostRequest::ParseResponse(const XmlElement* response, |
| void RegisterSupportHostRequest::ProcessResponse(const XmlElement* response) { |
| - DCHECK_EQ(message_loop_, MessageLoop::current()); |
| std::string support_id; |
| base::TimeDelta lifetime; |
| bool success = ParseResponse(response, &support_id, &lifetime); |
| - callback_.Run(success, support_id, lifetime); |
| + RegisterCallback callback = callback_; |
| + callback_.Reset(); |
| + callback.Run(success, support_id, lifetime); |
| } |
| } // namespace remoting |