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

Unified Diff: remoting/host/offline_status_sender.cc

Issue 18075003: Host offline status reporting. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 7 years, 6 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 side-by-side diff with in-line comments
Download patch
Index: remoting/host/offline_status_sender.cc
diff --git a/remoting/host/offline_status_sender.cc b/remoting/host/offline_status_sender.cc
new file mode 100644
index 0000000000000000000000000000000000000000..32a54009e8590eaf0bdd10cb063d1f35d29e4317
--- /dev/null
+++ b/remoting/host/offline_status_sender.cc
@@ -0,0 +1,121 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "remoting/host/offline_status_sender.h"
+
+#include "base/logging.h"
+#include "base/strings/string_number_conversions.h"
+#include "base/strings/stringize_macros.h"
+#include "base/time.h"
+#include "remoting/base/constants.h"
+#include "remoting/jingle_glue/iq_sender.h"
+#include "remoting/jingle_glue/signal_strategy.h"
+#include "third_party/libjingle/source/talk/xmllite/xmlelement.h"
+#include "third_party/libjingle/source/talk/xmpp/constants.h"
+
+using buzz::QName;
+using buzz::XmlElement;
+
+namespace remoting {
+
+namespace {
+
+const char kOfflineStatusTag[] = "offline-status";
rmsousa 2013/07/02 02:09:24 Can you make the tag "host-status", and make "offl
+const char kHostIdAttr[] = "hostid";
+const char kHostVersionTag[] = "host-version";
+const char kHeartbeatSignatureTag[] = "signature";
+const char kStatusAttr[] = "status";
rmsousa 2013/07/02 02:09:24 if we add the separate online/offline "status" att
+const char kErrorCodeAttr[] = "errorcode";
+
+} // namespace
+
+OfflineStatusSender::OfflineStatusSender(
rmsousa 2013/07/02 02:09:24 Please rename to HostStatusSender (see above)
+ const std::string& host_id,
+ SignalStrategy* signal_strategy,
+ scoped_refptr<RsaKeyPair> key_pair,
+ const std::string& directory_bot_jid)
+ : host_id_(host_id),
+ signal_strategy_(signal_strategy),
+ key_pair_(key_pair),
+ directory_bot_jid_(directory_bot_jid) {
+ DCHECK(signal_strategy_);
+ DCHECK(key_pair_.get());
+
+ VLOG(1) << "Creating OfflineStatusSender";
+
+ signal_strategy_->AddListener(this);
+}
+
+OfflineStatusSender::~OfflineStatusSender() {
+ signal_strategy_->RemoveListener(this);
+}
+
+void OfflineStatusSender::OnSignalStrategyStateChange(
+ SignalStrategy::State state) {
+ if (state == SignalStrategy::CONNECTED)
+ iq_sender_.reset(new IqSender(signal_strategy_));
+ else if (state == SignalStrategy::DISCONNECTED)
+ iq_sender_.reset();
+}
+
+bool OfflineStatusSender::OnSignalStrategyIncomingStanza(
+ const XmlElement* stanza) {
+ return false;
+}
+
+void OfflineStatusSender::SendOfflineStatus(int status, uint errorcode) {
+ SignalStrategy::State state = signal_strategy_->GetState();
+ if (state == SignalStrategy::CONNECTED) {
+ LOG(INFO) << "Sending offline status '"
+ << status
+ << "' to "
+ << directory_bot_jid_;
+
+ iq_sender_->SendIq(buzz::STR_SET,
+ directory_bot_jid_,
+ CreateOfflineStatusMessage(status, errorcode),
+ IqSender::ReplyCallback());
+ } else {
+ LOG(INFO) << "Cannot send offline status to '"
+ << directory_bot_jid_
+ << " ' because the state of the SignalStrategy is "
+ << state;
+ }
+}
+
+scoped_ptr<XmlElement> OfflineStatusSender::CreateOfflineStatusMessage(
+ int status, uint errorcode) {
+ // Create offline status stanza.
+ scoped_ptr<XmlElement> offline_status(new XmlElement(
+ QName(kChromotingXmlNamespace, kOfflineStatusTag)));
+ offline_status->AddAttr(
+ QName(kChromotingXmlNamespace, kHostIdAttr), host_id_);
+ offline_status->AddAttr(
+ QName(kChromotingXmlNamespace, kStatusAttr), base::IntToString(status));
+ // The error code is currently unused and always contains a value of 0.
rmsousa 2013/07/02 02:09:24 We should add this only when we know where it'll c
+ // In the future we may use it for things like windows error code.
rmsousa 2013/07/02 02:09:24 Nit: Comments describing the arguments should be i
+ offline_status->AddAttr(
+ QName(kChromotingXmlNamespace, kErrorCodeAttr),
+ base::IntToString(errorcode));
+ offline_status->AddElement(CreateSignature().release());
+ // Append host version.
+ scoped_ptr<XmlElement> version_tag(new XmlElement(
+ QName(kChromotingXmlNamespace, kHostVersionTag)));
+ version_tag->AddText(STRINGIZE(VERSION));
+ offline_status->AddElement(version_tag.release());
rmsousa 2013/07/02 02:09:24 please piggyback a log message, like heartbeat sen
+ return offline_status.Pass();
+}
+
+scoped_ptr<XmlElement> OfflineStatusSender::CreateSignature() {
+ scoped_ptr<XmlElement> signature_tag(new XmlElement(
+ QName(kChromotingXmlNamespace, kHeartbeatSignatureTag)));
rmsousa 2013/07/02 02:09:24 s/Heartbeat/OfflineStatus
+
+ std::string message = signal_strategy_->GetLocalJid();
rmsousa 2013/07/02 02:09:24 I'm not sure we need to sign this message, but if
+ std::string signature(key_pair_->SignMessage(message));
+ signature_tag->AddText(signature);
+
+ return signature_tag.Pass();
+}
+
+} // namespace remoting

Powered by Google App Engine
This is Rietveld 408576698