| OLD | NEW |
| 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/heartbeat_sender.h" | 5 #include "remoting/host/heartbeat_sender.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/message_loop.h" | 8 #include "base/message_loop_proxy.h" |
| 9 #include "base/string_number_conversions.h" | 9 #include "base/string_number_conversions.h" |
| 10 #include "base/time.h" | 10 #include "base/time.h" |
| 11 #include "remoting/base/constants.h" | 11 #include "remoting/base/constants.h" |
| 12 #include "remoting/host/host_config.h" | 12 #include "remoting/host/host_config.h" |
| 13 #include "remoting/jingle_glue/iq_request.h" | 13 #include "remoting/jingle_glue/iq_request.h" |
| 14 #include "remoting/jingle_glue/jingle_thread.h" | 14 #include "remoting/jingle_glue/jingle_thread.h" |
| 15 #include "remoting/jingle_glue/signal_strategy.h" | 15 #include "remoting/jingle_glue/signal_strategy.h" |
| 16 #include "third_party/libjingle/source/talk/xmllite/xmlelement.h" | 16 #include "third_party/libjingle/source/talk/xmllite/xmlelement.h" |
| 17 #include "third_party/libjingle/source/talk/xmpp/constants.h" | 17 #include "third_party/libjingle/source/talk/xmpp/constants.h" |
| 18 | 18 |
| 19 using buzz::QName; | 19 using buzz::QName; |
| 20 using buzz::XmlElement; | 20 using buzz::XmlElement; |
| 21 | 21 |
| 22 namespace remoting { | 22 namespace remoting { |
| 23 | 23 |
| 24 namespace { | 24 namespace { |
| 25 const char kHeartbeatQueryTag[] = "heartbeat"; | 25 const char kHeartbeatQueryTag[] = "heartbeat"; |
| 26 const char kHostIdAttr[] = "hostid"; | 26 const char kHostIdAttr[] = "hostid"; |
| 27 const char kHeartbeatSignatureTag[] = "signature"; | 27 const char kHeartbeatSignatureTag[] = "signature"; |
| 28 const char kSignatureTimeAttr[] = "time"; | 28 const char kSignatureTimeAttr[] = "time"; |
| 29 | 29 |
| 30 const char kHeartbeatResultTag[] = "heartbeat-result"; | 30 const char kHeartbeatResultTag[] = "heartbeat-result"; |
| 31 const char kSetIntervalTag[] = "set-interval"; | 31 const char kSetIntervalTag[] = "set-interval"; |
| 32 | 32 |
| 33 const int64 kDefaultHeartbeatIntervalMs = 5 * 60 * 1000; // 5 minutes. | 33 const int64 kDefaultHeartbeatIntervalMs = 5 * 60 * 1000; // 5 minutes. |
| 34 } | 34 } |
| 35 | 35 |
| 36 HeartbeatSender::HeartbeatSender(MessageLoop* message_loop, | 36 HeartbeatSender::HeartbeatSender(base::MessageLoopProxy* message_loop, |
| 37 MutableHostConfig* config) | 37 MutableHostConfig* config) |
| 38 | 38 |
| 39 : state_(CREATED), | 39 : state_(CREATED), |
| 40 message_loop_(message_loop), | 40 message_loop_(message_loop), |
| 41 config_(config), | 41 config_(config), |
| 42 interval_ms_(kDefaultHeartbeatIntervalMs) { | 42 interval_ms_(kDefaultHeartbeatIntervalMs) { |
| 43 DCHECK(config_); | 43 DCHECK(config_); |
| 44 } | 44 } |
| 45 | 45 |
| 46 HeartbeatSender::~HeartbeatSender() { | 46 HeartbeatSender::~HeartbeatSender() { |
| (...skipping 12 matching lines...) Expand all Loading... |
| 59 return false; | 59 return false; |
| 60 } | 60 } |
| 61 | 61 |
| 62 state_ = INITIALIZED; | 62 state_ = INITIALIZED; |
| 63 | 63 |
| 64 return true; | 64 return true; |
| 65 } | 65 } |
| 66 | 66 |
| 67 void HeartbeatSender::OnSignallingConnected(SignalStrategy* signal_strategy, | 67 void HeartbeatSender::OnSignallingConnected(SignalStrategy* signal_strategy, |
| 68 const std::string& full_jid) { | 68 const std::string& full_jid) { |
| 69 DCHECK_EQ(MessageLoop::current(), message_loop_); | 69 DCHECK(message_loop_->BelongsToCurrentThread()); |
| 70 DCHECK(state_ == INITIALIZED || state_ == STOPPED); | 70 DCHECK(state_ == INITIALIZED || state_ == STOPPED); |
| 71 state_ = STARTED; | 71 state_ = STARTED; |
| 72 | 72 |
| 73 full_jid_ = full_jid; | 73 full_jid_ = full_jid; |
| 74 request_.reset(signal_strategy->CreateIqRequest()); | 74 request_.reset(signal_strategy->CreateIqRequest()); |
| 75 request_->set_callback(NewCallback(this, &HeartbeatSender::ProcessResponse)); | 75 request_->set_callback(NewCallback(this, &HeartbeatSender::ProcessResponse)); |
| 76 | 76 |
| 77 DoSendStanza(); | 77 DoSendStanza(); |
| 78 timer_.Start(base::TimeDelta::FromMilliseconds(interval_ms_), this, | 78 timer_.Start(base::TimeDelta::FromMilliseconds(interval_ms_), this, |
| 79 &HeartbeatSender::DoSendStanza); | 79 &HeartbeatSender::DoSendStanza); |
| 80 } | 80 } |
| 81 | 81 |
| 82 void HeartbeatSender::OnSignallingDisconnected() { | 82 void HeartbeatSender::OnSignallingDisconnected() { |
| 83 DCHECK_EQ(MessageLoop::current(), message_loop_); | 83 DCHECK(message_loop_->BelongsToCurrentThread()); |
| 84 state_ = STOPPED; | 84 state_ = STOPPED; |
| 85 request_.reset(NULL); | 85 request_.reset(NULL); |
| 86 } | 86 } |
| 87 | 87 |
| 88 // Ignore any notifications other than signalling | 88 // Ignore any notifications other than signalling |
| 89 // connected/disconnected events. | 89 // connected/disconnected events. |
| 90 void HeartbeatSender::OnAccessDenied() { } | 90 void HeartbeatSender::OnAccessDenied() { } |
| 91 void HeartbeatSender::OnClientAuthenticated( | 91 void HeartbeatSender::OnClientAuthenticated( |
| 92 remoting::protocol::ConnectionToClient* client) { } | 92 remoting::protocol::ConnectionToClient* client) { } |
| 93 void HeartbeatSender::OnClientDisconnected( | 93 void HeartbeatSender::OnClientDisconnected( |
| 94 remoting::protocol::ConnectionToClient* client) { } | 94 remoting::protocol::ConnectionToClient* client) { } |
| 95 void HeartbeatSender::OnShutdown() { } | 95 void HeartbeatSender::OnShutdown() { } |
| 96 | 96 |
| 97 void HeartbeatSender::DoSendStanza() { | 97 void HeartbeatSender::DoSendStanza() { |
| 98 DCHECK_EQ(MessageLoop::current(), message_loop_); | 98 DCHECK(message_loop_->BelongsToCurrentThread()); |
| 99 DCHECK_EQ(state_, STARTED); | 99 DCHECK_EQ(state_, STARTED); |
| 100 | 100 |
| 101 VLOG(1) << "Sending heartbeat stanza to " << kChromotingBotJid; | 101 VLOG(1) << "Sending heartbeat stanza to " << kChromotingBotJid; |
| 102 request_->SendIq(buzz::STR_SET, kChromotingBotJid, CreateHeartbeatMessage()); | 102 request_->SendIq(buzz::STR_SET, kChromotingBotJid, CreateHeartbeatMessage()); |
| 103 } | 103 } |
| 104 | 104 |
| 105 void HeartbeatSender::ProcessResponse(const XmlElement* response) { | 105 void HeartbeatSender::ProcessResponse(const XmlElement* response) { |
| 106 DCHECK_EQ(MessageLoop::current(), message_loop_); | 106 DCHECK(message_loop_->BelongsToCurrentThread()); |
| 107 | 107 |
| 108 std::string type = response->Attr(buzz::QN_TYPE); | 108 std::string type = response->Attr(buzz::QN_TYPE); |
| 109 if (type == buzz::STR_ERROR) { | 109 if (type == buzz::STR_ERROR) { |
| 110 LOG(ERROR) << "Received error in response to heartbeat: " | 110 LOG(ERROR) << "Received error in response to heartbeat: " |
| 111 << response->Str(); | 111 << response->Str(); |
| 112 return; | 112 return; |
| 113 } | 113 } |
| 114 | 114 |
| 115 // This method must only be called for error or result stanzas. | 115 // This method must only be called for error or result stanzas. |
| 116 DCHECK_EQ(buzz::STR_RESULT, type); | 116 DCHECK_EQ(buzz::STR_RESULT, type); |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 165 QName(kChromotingXmlNamespace, kSignatureTimeAttr), time_str); | 165 QName(kChromotingXmlNamespace, kSignatureTimeAttr), time_str); |
| 166 | 166 |
| 167 std::string message = full_jid_ + ' ' + time_str; | 167 std::string message = full_jid_ + ' ' + time_str; |
| 168 std::string signature(key_pair_.GetSignature(message)); | 168 std::string signature(key_pair_.GetSignature(message)); |
| 169 signature_tag->AddText(signature); | 169 signature_tag->AddText(signature); |
| 170 | 170 |
| 171 return signature_tag; | 171 return signature_tag; |
| 172 } | 172 } |
| 173 | 173 |
| 174 } // namespace remoting | 174 } // namespace remoting |
| OLD | NEW |