[Chromoting] Add platform data to heartbeats.

BUG=126491

Review URL: https://chromiumcodereview.appspot.com/10409017

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@138275 0039d316-1c4b-4281-b951-d872f2087c98
parent 49a1f3fd
......@@ -14,6 +14,7 @@
#include "base/time.h"
#include "remoting/base/constants.h"
#include "remoting/host/constants.h"
#include "remoting/host/server_log_entry.h"
#include "remoting/jingle_glue/iq_sender.h"
#include "remoting/jingle_glue/jingle_thread.h"
#include "remoting/jingle_glue/signal_strategy.h"
......@@ -229,12 +230,19 @@ void HeartbeatSender::SetSequenceId(int sequence_id) {
}
scoped_ptr<XmlElement> HeartbeatSender::CreateHeartbeatMessage() {
// Create heartbeat stanza.
scoped_ptr<XmlElement> query(new XmlElement(
QName(kChromotingXmlNamespace, kHeartbeatQueryTag)));
query->AddAttr(QName(kChromotingXmlNamespace, kHostIdAttr), host_id_);
query->AddAttr(QName(kChromotingXmlNamespace, kSequenceIdAttr),
base::IntToString(sequence_id_));
query->AddElement(CreateSignature().release());
// Append log message (which isn't signed).
scoped_ptr<XmlElement> log(ServerLogEntry::MakeStanza());
scoped_ptr<ServerLogEntry> log_entry(ServerLogEntry::MakeForHeartbeat());
log_entry->AddHostFields();
log->AddElement(log_entry->ToStanza().release());
query->AddElement(log.release());
return query.Pass();
}
......
......@@ -21,10 +21,6 @@ using buzz::XmlElement;
namespace remoting {
namespace {
const char kLogCommand[] = "log";
} // namespace
LogToServer::LogToServer(ChromotingHost* host,
ServerLogEntry::Mode mode,
SignalStrategy* signal_strategy)
......@@ -112,8 +108,7 @@ void LogToServer::SendPendingEntries() {
return;
}
// Make one stanza containing all the pending entries.
scoped_ptr<XmlElement> stanza(new XmlElement(QName(
kChromotingXmlNamespace, kLogCommand)));
scoped_ptr<XmlElement> stanza(ServerLogEntry::MakeStanza());
while (!pending_entries_.empty()) {
ServerLogEntry& entry = pending_entries_.front();
stanza->AddElement(entry.ToStanza().release());
......
......@@ -17,10 +17,13 @@ using remoting::protocol::Session;
namespace remoting {
namespace {
const char kLogCommand[] = "log";
const char kLogEntry[] = "entry";
const char kKeyEventName[] = "event-name";
const char kValueEventNameSessionState[] = "session-state";
const char kValueEventNameHeartbeat[] = "heartbeat";
const char kKeyRole[] = "role";
const char kValueRoleHost[] = "host";
......@@ -53,6 +56,13 @@ ServerLogEntry::ServerLogEntry() {
ServerLogEntry::~ServerLogEntry() {
}
// static
scoped_ptr<buzz::XmlElement> ServerLogEntry::MakeStanza() {
return scoped_ptr<buzz::XmlElement>(
new XmlElement(QName(kChromotingXmlNamespace, kLogCommand)));
}
// static
ServerLogEntry* ServerLogEntry::MakeSessionStateChange(bool connected) {
ServerLogEntry* entry = new ServerLogEntry();
entry->Set(kKeyRole, kValueRoleHost);
......@@ -61,6 +71,14 @@ ServerLogEntry* ServerLogEntry::MakeSessionStateChange(bool connected) {
return entry;
}
// static
ServerLogEntry* ServerLogEntry::MakeForHeartbeat() {
ServerLogEntry* entry = new ServerLogEntry();
entry->Set(kKeyRole, kValueRoleHost);
entry->Set(kKeyEventName, kValueEventNameHeartbeat);
return entry;
}
void ServerLogEntry::AddHostFields() {
#if defined(OS_WIN)
Set(kKeyOsName, kValueOsNameWindows);
......@@ -98,6 +116,7 @@ void ServerLogEntry::AddConnectionTypeField(
Set(kKeyConnectionType, protocol::TransportRoute::GetTypeString(type));
}
// static
const char* ServerLogEntry::GetValueMode(ServerLogEntry::Mode mode) {
switch(mode) {
case IT2ME:
......@@ -120,6 +139,7 @@ scoped_ptr<XmlElement> ServerLogEntry::ToStanza() const {
return stanza.Pass();
}
// static
const char* ServerLogEntry::GetValueSessionState(bool connected) {
return connected ? kValueSessionStateConnected : kValueSessionStateClosed;
}
......
......@@ -25,10 +25,18 @@ class ServerLogEntry {
ME2ME
};
// Constructs a log stanza. The caller should add one or more log entry
// stanzas as children of this stanza, before sending the log stanza to
// the remoting bot.
static scoped_ptr<buzz::XmlElement> MakeStanza();
// Constructs a log entry for a session state change.
// Currently this is either connection or disconnection.
static ServerLogEntry* MakeSessionStateChange(bool connection);
// Constructs a log entry for a heartbeat.
static ServerLogEntry* MakeForHeartbeat();
~ServerLogEntry();
// Adds fields describing the host to this log entry.
......
......@@ -70,8 +70,20 @@ TEST_F(ServerLogEntryTest, MakeSessionStateChange) {
key_value_pairs["event-name"] = "session-state";
key_value_pairs["session-state"] = "connected";
std::set<std::string> keys;
ASSERT_TRUE(VerifyStanza(key_value_pairs, keys, stanza.get(), &error)) <<
error;
ASSERT_TRUE(VerifyStanza(key_value_pairs, keys, stanza.get(), &error))
<< error;
}
TEST_F(ServerLogEntryTest, MakeHeartbeat) {
scoped_ptr<ServerLogEntry> entry(ServerLogEntry::MakeForHeartbeat());
scoped_ptr<XmlElement> stanza = entry->ToStanza();
std::string error;
std::map<std::string, std::string> key_value_pairs;
key_value_pairs["role"] = "host";
key_value_pairs["event-name"] = "heartbeat";
std::set<std::string> keys;
ASSERT_TRUE(VerifyStanza(key_value_pairs, keys, stanza.get(), &error))
<< error;
}
TEST_F(ServerLogEntryTest, AddHostFields) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment