Pull out common code from client and host versions of ServerLogEntry.

This also adds unittests for ServerLogEntry client code, with common code
pulled out to a separate file.

This doesn't affect LogToServer classes - they will be refactored in a
separate CL. Also fix some IWYU issues uncovered by the refactor.

TEST=unittests

Review URL: https://codereview.chromium.org/282063005

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@272346 0039d316-1c4b-4281-b951-d872f2087c98
parent 49701e0a
...@@ -13,11 +13,11 @@ ...@@ -13,11 +13,11 @@
#include "remoting/client/jni/android_keymap.h" #include "remoting/client/jni/android_keymap.h"
#include "remoting/client/jni/chromoting_jni_runtime.h" #include "remoting/client/jni/chromoting_jni_runtime.h"
#include "remoting/client/log_to_server.h" #include "remoting/client/log_to_server.h"
#include "remoting/client/server_log_entry.h"
#include "remoting/client/software_video_renderer.h" #include "remoting/client/software_video_renderer.h"
#include "remoting/jingle_glue/chromium_port_allocator.h" #include "remoting/jingle_glue/chromium_port_allocator.h"
#include "remoting/jingle_glue/chromium_socket_factory.h" #include "remoting/jingle_glue/chromium_socket_factory.h"
#include "remoting/jingle_glue/network_settings.h" #include "remoting/jingle_glue/network_settings.h"
#include "remoting/jingle_glue/server_log_entry.h"
#include "remoting/protocol/host_stub.h" #include "remoting/protocol/host_stub.h"
#include "remoting/protocol/libjingle_transport_factory.h" #include "remoting/protocol/libjingle_transport_factory.h"
...@@ -336,7 +336,7 @@ void ChromotingJniInstance::ConnectToHostOnNetworkThread() { ...@@ -336,7 +336,7 @@ void ChromotingJniInstance::ConnectToHostOnNetworkThread() {
net::ClientSocketFactory::GetDefaultFactory(), net::ClientSocketFactory::GetDefaultFactory(),
jni_runtime_->url_requester(), xmpp_config_)); jni_runtime_->url_requester(), xmpp_config_));
log_to_server_.reset(new client::LogToServer(client::ServerLogEntry::ME2ME, log_to_server_.reset(new client::LogToServer(ServerLogEntry::ME2ME,
signaling_.get(), signaling_.get(),
"remoting@bot.talk.google.com")); "remoting@bot.talk.google.com"));
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#include "base/rand_util.h" #include "base/rand_util.h"
#include "remoting/base/constants.h" #include "remoting/base/constants.h"
#include "remoting/client/chromoting_stats.h" #include "remoting/client/chromoting_stats.h"
#include "remoting/client/server_log_entry_client.h"
#include "remoting/jingle_glue/iq_sender.h" #include "remoting/jingle_glue/iq_sender.h"
#include "remoting/jingle_glue/signal_strategy.h" #include "remoting/jingle_glue/signal_strategy.h"
#include "third_party/libjingle/source/talk/xmllite/xmlelement.h" #include "third_party/libjingle/source/talk/xmllite/xmlelement.h"
...@@ -69,8 +70,8 @@ void LogToServer::LogSessionStateChange( ...@@ -69,8 +70,8 @@ void LogToServer::LogSessionStateChange(
DCHECK(CalledOnValidThread()); DCHECK(CalledOnValidThread());
scoped_ptr<ServerLogEntry> entry( scoped_ptr<ServerLogEntry> entry(
ServerLogEntry::MakeForSessionStateChange(state, error)); MakeLogEntryForSessionStateChange(state, error));
entry->AddClientFields(); AddClientFieldsToLogEntry(entry.get());
entry->AddModeField(mode_); entry->AddModeField(mode_);
MaybeExpireSessionId(); MaybeExpireSessionId();
...@@ -85,12 +86,13 @@ void LogToServer::LogSessionStateChange( ...@@ -85,12 +86,13 @@ void LogToServer::LogSessionStateChange(
} }
if (!session_id_.empty()) { if (!session_id_.empty()) {
entry->AddSessionId(session_id_); AddSessionIdToLogEntry(entry.get(), session_id_);
} }
// Maybe clear the session start time and log the session duration. // Maybe clear the session start time and log the session duration.
if (ShouldAddDuration(state) && !session_start_time_.is_null()) { if (ShouldAddDuration(state) && !session_start_time_.is_null()) {
entry->AddSessionDuration(base::TimeTicks::Now() - session_start_time_); AddSessionDurationToLogEntry(entry.get(),
base::TimeTicks::Now() - session_start_time_);
} }
if (IsEndOfSession(state)) { if (IsEndOfSession(state)) {
...@@ -106,11 +108,10 @@ void LogToServer::LogStatistics(ChromotingStats* statistics) { ...@@ -106,11 +108,10 @@ void LogToServer::LogStatistics(ChromotingStats* statistics) {
MaybeExpireSessionId(); MaybeExpireSessionId();
scoped_ptr<ServerLogEntry> entry( scoped_ptr<ServerLogEntry> entry(MakeLogEntryForStatistics(statistics));
ServerLogEntry::MakeForStatistics(statistics)); AddClientFieldsToLogEntry(entry.get());
entry->AddClientFields();
entry->AddModeField(mode_); entry->AddModeField(mode_);
entry->AddSessionId(session_id_); AddSessionIdToLogEntry(entry.get(), session_id_);
Log(*entry.get()); Log(*entry.get());
} }
...@@ -174,8 +175,7 @@ void LogToServer::MaybeExpireSessionId() { ...@@ -174,8 +175,7 @@ void LogToServer::MaybeExpireSessionId() {
base::TimeDelta max_age = base::TimeDelta::FromDays(kMaxSessionIdAgeDays); base::TimeDelta max_age = base::TimeDelta::FromDays(kMaxSessionIdAgeDays);
if (base::TimeTicks::Now() - session_id_generation_time_ > max_age) { if (base::TimeTicks::Now() - session_id_generation_time_ > max_age) {
// Log the old session ID. // Log the old session ID.
scoped_ptr<ServerLogEntry> entry( scoped_ptr<ServerLogEntry> entry(MakeLogEntryForSessionIdOld(session_id_));
ServerLogEntry::MakeForSessionIdOld(session_id_));
entry->AddModeField(mode_); entry->AddModeField(mode_);
Log(*entry.get()); Log(*entry.get());
...@@ -183,7 +183,7 @@ void LogToServer::MaybeExpireSessionId() { ...@@ -183,7 +183,7 @@ void LogToServer::MaybeExpireSessionId() {
GenerateSessionId(); GenerateSessionId();
// Log the new session ID. // Log the new session ID.
entry = ServerLogEntry::MakeForSessionIdNew(session_id_); entry = MakeLogEntryForSessionIdNew(session_id_);
entry->AddModeField(mode_); entry->AddModeField(mode_);
Log(*entry.get()); Log(*entry.get());
} }
......
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
#include "base/threading/non_thread_safe.h" #include "base/threading/non_thread_safe.h"
#include "base/time/time.h" #include "base/time/time.h"
#include "remoting/client/server_log_entry.h" #include "remoting/jingle_glue/server_log_entry.h"
#include "remoting/jingle_glue/signal_strategy.h" #include "remoting/jingle_glue/signal_strategy.h"
#include "remoting/protocol/connection_to_host.h" #include "remoting/protocol/connection_to_host.h"
#include "remoting/protocol/errors.h" #include "remoting/protocol/errors.h"
......
// Copyright 2014 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.
#ifndef REMOTING_CLIENT_SERVER_LOG_ENTRY_H_
#define REMOTING_CLIENT_SERVER_LOG_ENTRY_H_
#include <map>
#include <string>
#include "base/memory/scoped_ptr.h"
#include "base/time/time.h"
#include "remoting/protocol/connection_to_host.h"
#include "remoting/protocol/errors.h"
namespace buzz {
class XmlElement;
} // namespace buzz
namespace remoting {
class ChromotingStats;
// Temporary namespace to prevent conflict with the same-named class in
// remoting/host when linking unittests.
//
// TODO(lambroslambrou): Remove this and factor out any shared code.
namespace client {
class ServerLogEntry {
public:
// The mode of a connection.
enum Mode {
IT2ME,
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.
static scoped_ptr<ServerLogEntry> MakeForSessionStateChange(
remoting::protocol::ConnectionToHost::State state,
remoting::protocol::ErrorCode error);
// Constructs a log entry for reporting statistics.
static scoped_ptr<ServerLogEntry> MakeForStatistics(
remoting::ChromotingStats* statistics);
// Constructs a log entry for reporting session ID is old.
static scoped_ptr<ServerLogEntry> MakeForSessionIdOld(
const std::string& session_id);
// Constructs a log entry for reporting session ID is old.
static scoped_ptr<ServerLogEntry> MakeForSessionIdNew(
const std::string& session_id);
~ServerLogEntry();
// Adds fields describing the client to this log entry.
void AddClientFields();
// Adds a field describing the mode of a connection to this log entry.
void AddModeField(Mode mode);
void AddEventName(const std::string& event_name);
void AddSessionId(const std::string& session_id);
void AddSessionDuration(base::TimeDelta duration);
// Converts this object to an XML stanza.
scoped_ptr<buzz::XmlElement> ToStanza() const;
private:
typedef std::map<std::string, std::string> ValuesMap;
ServerLogEntry();
void Set(const std::string& key, const std::string& value);
static const char* GetValueSessionState(
remoting::protocol::ConnectionToHost::State state);
static const char* GetValueError(remoting::protocol::ErrorCode error);
static const char* GetValueMode(Mode mode);
ValuesMap values_map_;
};
} // namespace client
} // namespace remoting
#endif // REMOTING_CLIENT_SERVER_LOG_ENTRY_H_
...@@ -2,50 +2,35 @@ ...@@ -2,50 +2,35 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#include "remoting/client/server_log_entry.h" #include "remoting/client/server_log_entry_client.h"
#include "base/logging.h"
#include "base/macros.h"
#include "base/rand_util.h"
#include "base/strings/string_number_conversions.h" #include "base/strings/string_number_conversions.h"
#include "base/strings/stringize_macros.h" #include "base/strings/stringize_macros.h"
#include "base/strings/stringprintf.h" #include "base/strings/stringprintf.h"
#include "base/sys_info.h" #include "base/sys_info.h"
#include "remoting/base/constants.h"
#include "remoting/client/chromoting_stats.h" #include "remoting/client/chromoting_stats.h"
#include "remoting/protocol/connection_to_host.h" #include "remoting/jingle_glue/server_log_entry.h"
#include "remoting/protocol/errors.h"
#include "third_party/libjingle/source/talk/xmllite/xmlelement.h"
using base::StringPrintf; using base::StringPrintf;
using base::SysInfo; using base::SysInfo;
using buzz::QName;
using buzz::XmlElement;
using remoting::protocol::ConnectionToHost; using remoting::protocol::ConnectionToHost;
using remoting::protocol::ErrorCode;
namespace remoting { namespace remoting {
namespace client {
namespace { namespace {
const char kLogCommand[] = "log"; const char kValueRoleClient[] = "client";
const char kLogEntry[] = "entry";
const char kKeyEventName[] = "event-name";
const char kValueEventNameSessionState[] = "session-state"; const char kValueEventNameSessionState[] = "session-state";
const char kValueEventNameStatistics[] = "connection-statistics"; const char kValueEventNameStatistics[] = "connection-statistics";
const char kValueEventNameSessionIdOld[] = "session-id-old"; const char kValueEventNameSessionIdOld[] = "session-id-old";
const char kValueEventNameSessionIdNew[] = "session-id-new"; const char kValueEventNameSessionIdNew[] = "session-id-new";
const char kKeyRole[] = "role"; const char kKeySessionId[] = "session-id";
const char kValueRoleClient[] = "client"; const char kKeySessionDuration[] = "session-duration";
const char kKeyMode[] = "mode";
const char kValueModeIt2Me[] = "it2me";
const char kValueModeMe2Me[] = "me2me";
const char kKeySessionState[] = "session-state"; const char kKeySessionState[] = "session-state";
const char kKeyConnectionError[] = "connection-error";
const char kValueSessionStateConnected[] = "connected"; const char kValueSessionStateConnected[] = "connected";
const char kValueSessionStateClosed[] = "closed"; const char kValueSessionStateClosed[] = "closed";
...@@ -53,126 +38,7 @@ const char kKeyOsName[] = "os-name"; ...@@ -53,126 +38,7 @@ const char kKeyOsName[] = "os-name";
const char kKeyOsVersion[] = "os-version"; const char kKeyOsVersion[] = "os-version";
const char kKeyAppVersion[] = "app-version"; const char kKeyAppVersion[] = "app-version";
const char kKeyCpu[] = "cpu"; const char* GetValueSessionState(ConnectionToHost::State state) {
} // namespace
ServerLogEntry::ServerLogEntry() {
}
ServerLogEntry::~ServerLogEntry() {
}
// static
scoped_ptr<buzz::XmlElement> ServerLogEntry::MakeStanza() {
return scoped_ptr<buzz::XmlElement>(
new XmlElement(QName(kChromotingXmlNamespace, kLogCommand)));
}
// static
scoped_ptr<ServerLogEntry> ServerLogEntry::MakeForSessionStateChange(
protocol::ConnectionToHost::State state,
protocol::ErrorCode error) {
scoped_ptr<ServerLogEntry> entry(new ServerLogEntry());
entry->Set(kKeyRole, kValueRoleClient);
entry->Set(kKeyEventName, kValueEventNameSessionState);
entry->Set(kKeySessionState, GetValueSessionState(state));
if (error != protocol::OK) {
entry->Set("connection-error", GetValueError(error));
}
return entry.Pass();
}
// static
scoped_ptr<ServerLogEntry> ServerLogEntry::MakeForStatistics(
ChromotingStats* statistics) {
scoped_ptr<ServerLogEntry> entry(new ServerLogEntry());
entry->Set(kKeyRole, kValueRoleClient);
entry->Set(kKeyEventName, kValueEventNameStatistics);
entry->Set("video-bandwidth",
StringPrintf("%.2f", statistics->video_bandwidth()->Rate()));
entry->Set("capture-latency",
StringPrintf("%.2f", statistics->video_capture_ms()->Average()));
entry->Set("encode-latency",
StringPrintf("%.2f", statistics->video_encode_ms()->Average()));
entry->Set("decode-latency",
StringPrintf("%.2f", statistics->video_decode_ms()->Average()));
entry->Set("render-latency",
StringPrintf("%.2f", statistics->video_frame_rate()->Rate()));
entry->Set("roundtrip-latency",
StringPrintf("%.2f", statistics->round_trip_ms()->Average()));
return entry.Pass();
}
// static
scoped_ptr<ServerLogEntry> ServerLogEntry::MakeForSessionIdOld(
const std::string& session_id) {
scoped_ptr<ServerLogEntry> entry(new ServerLogEntry());
entry->Set(kKeyRole, kValueRoleClient);
entry->Set(kKeyEventName, kValueEventNameSessionIdOld);
entry->AddSessionId(session_id);
return entry.Pass();
}
// static
scoped_ptr<ServerLogEntry> ServerLogEntry::MakeForSessionIdNew(
const std::string& session_id) {
scoped_ptr<ServerLogEntry> entry(new ServerLogEntry());
entry->Set(kKeyRole, kValueRoleClient);
entry->Set(kKeyEventName, kValueEventNameSessionIdNew);
entry->AddSessionId(session_id);
return entry.Pass();
}
void ServerLogEntry::AddClientFields() {
Set(kKeyOsName, SysInfo::OperatingSystemName());
Set(kKeyOsVersion, SysInfo::OperatingSystemVersion());
Set(kKeyAppVersion, STRINGIZE(VERSION));
Set(kKeyCpu, SysInfo::OperatingSystemArchitecture());
};
void ServerLogEntry::AddModeField(ServerLogEntry::Mode mode) {
Set(kKeyMode, GetValueMode(mode));
}
void ServerLogEntry::AddSessionId(const std::string& session_id) {
Set("session-id", session_id);
}
void ServerLogEntry::AddSessionDuration(base::TimeDelta duration) {
Set("session-duration", base::Int64ToString(duration.InSeconds()));
}
// static
const char* ServerLogEntry::GetValueMode(ServerLogEntry::Mode mode) {
switch (mode) {
case IT2ME:
return kValueModeIt2Me;
case ME2ME:
return kValueModeMe2Me;
default:
NOTREACHED();
return NULL;
}
}
scoped_ptr<XmlElement> ServerLogEntry::ToStanza() const {
scoped_ptr<XmlElement> stanza(new XmlElement(QName(
kChromotingXmlNamespace, kLogEntry)));
ValuesMap::const_iterator iter;
for (iter = values_map_.begin(); iter != values_map_.end(); ++iter) {
stanza->AddAttr(QName(std::string(), iter->first), iter->second);
}
return stanza.Pass();
}
// static
const char* ServerLogEntry::GetValueSessionState(
ConnectionToHost::State state) {
switch (state) { switch (state) {
// Where possible, these are the same strings that the webapp sends for the // Where possible, these are the same strings that the webapp sends for the
// corresponding state - see remoting/webapp/server_log_entry.js. // corresponding state - see remoting/webapp/server_log_entry.js.
...@@ -194,8 +60,7 @@ const char* ServerLogEntry::GetValueSessionState( ...@@ -194,8 +60,7 @@ const char* ServerLogEntry::GetValueSessionState(
} }
} }
// static const char* GetValueError(ErrorCode error) {
const char* ServerLogEntry::GetValueError(protocol::ErrorCode error) {
switch (error) { switch (error) {
// Where possible, these are the same strings that the webapp sends for the // Where possible, these are the same strings that the webapp sends for the
// corresponding error - see remoting/webapp/server_log_entry.js. // corresponding error - see remoting/webapp/server_log_entry.js.
...@@ -225,14 +90,77 @@ const char* ServerLogEntry::GetValueError(protocol::ErrorCode error) { ...@@ -225,14 +90,77 @@ const char* ServerLogEntry::GetValueError(protocol::ErrorCode error) {
} }
} }
void ServerLogEntry::AddEventName(const std::string& event_name) { } // namespace
Set("event-name", event_name);
scoped_ptr<ServerLogEntry> MakeLogEntryForSessionStateChange(
ConnectionToHost::State state,
ErrorCode error) {
scoped_ptr<ServerLogEntry> entry(new ServerLogEntry());
entry->AddRoleField(kValueRoleClient);
entry->AddEventNameField(kValueEventNameSessionState);
entry->Set(kKeySessionState, GetValueSessionState(state));
if (error != protocol::OK) {
entry->Set(kKeyConnectionError, GetValueError(error));
}
return entry.Pass();
}
scoped_ptr<ServerLogEntry> MakeLogEntryForStatistics(
ChromotingStats* statistics) {
scoped_ptr<ServerLogEntry> entry(new ServerLogEntry());
entry->AddRoleField(kValueRoleClient);
entry->AddEventNameField(kValueEventNameStatistics);
entry->Set("video-bandwidth",
StringPrintf("%.2f", statistics->video_bandwidth()->Rate()));
entry->Set("capture-latency",
StringPrintf("%.2f", statistics->video_capture_ms()->Average()));
entry->Set("encode-latency",
StringPrintf("%.2f", statistics->video_encode_ms()->Average()));
entry->Set("decode-latency",
StringPrintf("%.2f", statistics->video_decode_ms()->Average()));
entry->Set("render-latency",
StringPrintf("%.2f", statistics->video_frame_rate()->Rate()));
entry->Set("roundtrip-latency",
StringPrintf("%.2f", statistics->round_trip_ms()->Average()));
return entry.Pass();
}
scoped_ptr<ServerLogEntry> MakeLogEntryForSessionIdOld(
const std::string& session_id) {
scoped_ptr<ServerLogEntry> entry(new ServerLogEntry());
entry->AddRoleField(kValueRoleClient);
entry->AddEventNameField(kValueEventNameSessionIdOld);
AddSessionIdToLogEntry(entry.get(), session_id);
return entry.Pass();
} }
void ServerLogEntry::Set(const std::string& key, const std::string& value) { scoped_ptr<ServerLogEntry> MakeLogEntryForSessionIdNew(
values_map_[key] = value; const std::string& session_id) {
scoped_ptr<ServerLogEntry> entry(new ServerLogEntry());
entry->AddRoleField(kValueRoleClient);
entry->AddEventNameField(kValueEventNameSessionIdNew);
AddSessionIdToLogEntry(entry.get(), session_id);
return entry.Pass();
}
void AddClientFieldsToLogEntry(ServerLogEntry* entry) {
entry->Set(kKeyOsName, SysInfo::OperatingSystemName());
entry->Set(kKeyOsVersion, SysInfo::OperatingSystemVersion());
entry->Set(kKeyAppVersion, STRINGIZE(VERSION));
entry->AddCpuField();
} }
} // namespace client void AddSessionIdToLogEntry(ServerLogEntry* entry, const std::string& id) {
entry->Set(kKeySessionId, id);
}
void AddSessionDurationToLogEntry(ServerLogEntry* entry,
base::TimeDelta duration) {
entry->Set(kKeySessionDuration, base::Int64ToString(duration.InSeconds()));
}
} // namespace remoting } // namespace remoting
// Copyright 2014 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.
#ifndef REMOTING_CLIENT_SERVER_LOG_ENTRY_CLIENT_H_
#define REMOTING_CLIENT_SERVER_LOG_ENTRY_CLIENT_H_
#include "base/time/time.h"
#include "remoting/protocol/connection_to_host.h"
#include "remoting/protocol/errors.h"
namespace remoting {
class ChromotingStats;
class ServerLogEntry;
// Constructs a log entry for a session state change.
scoped_ptr<ServerLogEntry> MakeLogEntryForSessionStateChange(
protocol::ConnectionToHost::State state,
protocol::ErrorCode error);
// Constructs a log entry for reporting statistics.
scoped_ptr<ServerLogEntry> MakeLogEntryForStatistics(
ChromotingStats* statistics);
// Constructs a log entry for reporting session ID is old.
scoped_ptr<ServerLogEntry> MakeLogEntryForSessionIdOld(
const std::string& session_id);
// Constructs a log entry for reporting session ID is old.
scoped_ptr<ServerLogEntry> MakeLogEntryForSessionIdNew(
const std::string& session_id);
void AddClientFieldsToLogEntry(ServerLogEntry* entry);
void AddSessionIdToLogEntry(ServerLogEntry* entry, const std::string& id);
void AddSessionDurationToLogEntry(ServerLogEntry* entry,
base::TimeDelta duration);
} // namespace remoting
#endif // REMOTING_CLIENT_SERVER_LOG_ENTRY_CLIENT_H_
// Copyright 2014 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 "base/memory/scoped_ptr.h"
#include "base/strings/stringize_macros.h"
#include "base/sys_info.h"
#include "remoting/client/chromoting_stats.h"
#include "remoting/client/server_log_entry_client.h"
#include "remoting/jingle_glue/server_log_entry.h"
#include "remoting/jingle_glue/server_log_entry_unittest.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/libjingle/source/talk/xmllite/xmlelement.h"
using base::SysInfo;
using buzz::XmlAttr;
using buzz::XmlElement;
using remoting::protocol::ConnectionToHost;
namespace remoting {
TEST(ServerLogEntryClientTest, SessionStateChange) {
scoped_ptr<ServerLogEntry> entry(MakeLogEntryForSessionStateChange(
ConnectionToHost::CONNECTED, remoting::protocol::OK));
scoped_ptr<XmlElement> stanza = entry->ToStanza();
std::string error;
std::map<std::string, std::string> key_value_pairs;
key_value_pairs["role"] = "client";
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;
}
TEST(ServerLogEntryClientTest, SessionStateChangeWithError) {
scoped_ptr<ServerLogEntry> entry(MakeLogEntryForSessionStateChange(
ConnectionToHost::FAILED, remoting::protocol::PEER_IS_OFFLINE));
scoped_ptr<XmlElement> stanza = entry->ToStanza();
std::string error;
std::map<std::string, std::string> key_value_pairs;
key_value_pairs["role"] = "client";
key_value_pairs["event-name"] = "session-state";
key_value_pairs["session-state"] = "connection-failed";
key_value_pairs["connection-error"] = "host-is-offline";
std::set<std::string> keys;
ASSERT_TRUE(VerifyStanza(key_value_pairs, keys, stanza.get(), &error))
<< error;
}
TEST(ServerLogEntryClientTest, Statistics) {
ChromotingStats statistics;
scoped_ptr<ServerLogEntry> entry(MakeLogEntryForStatistics(&statistics));
scoped_ptr<XmlElement> stanza = entry->ToStanza();
std::string error;
std::map<std::string, std::string> key_value_pairs;
key_value_pairs["role"] = "client";
key_value_pairs["event-name"] = "connection-statistics";
std::set<std::string> keys;
keys.insert("video-bandwidth");
keys.insert("capture-latency");
keys.insert("encode-latency");
keys.insert("decode-latency");
keys.insert("render-latency");
keys.insert("roundtrip-latency");
ASSERT_TRUE(VerifyStanza(key_value_pairs, keys, stanza.get(), &error))
<< error;
}
TEST(ServerLogEntryClientTest, SessionIdChanged) {
scoped_ptr<ServerLogEntry> entry(MakeLogEntryForSessionIdOld("abc"));
scoped_ptr<XmlElement> stanza = entry->ToStanza();
std::string error;
std::map<std::string, std::string> key_value_pairs;
key_value_pairs["role"] = "client";
key_value_pairs["event-name"] = "session-id-old";
key_value_pairs["session-id"] = "abc";
std::set<std::string> keys;
ASSERT_TRUE(VerifyStanza(key_value_pairs, keys, stanza.get(), &error))
<< error;
entry = MakeLogEntryForSessionIdNew("def");
stanza = entry->ToStanza();
key_value_pairs["event-name"] = "session-id-new";
key_value_pairs["session-id"] = "def";
ASSERT_TRUE(VerifyStanza(key_value_pairs, keys, stanza.get(), &error))
<< error;
}
TEST(ServerLogEntryClientTest, AddClientFields) {
scoped_ptr<ServerLogEntry> entry(MakeLogEntryForSessionStateChange(
ConnectionToHost::CONNECTED, remoting::protocol::OK));
AddClientFieldsToLogEntry(entry.get());
scoped_ptr<XmlElement> stanza = entry->ToStanza();
std::string error;
std::map<std::string, std::string> key_value_pairs;
key_value_pairs["role"] = "client";
key_value_pairs["event-name"] = "session-state";
key_value_pairs["session-state"] = "connected";
key_value_pairs["os-name"] = SysInfo::OperatingSystemName();
key_value_pairs["os-version"] = SysInfo::OperatingSystemVersion();
key_value_pairs["app-version"] = STRINGIZE(VERSION);
key_value_pairs["cpu"] = SysInfo::OperatingSystemArchitecture();
std::set<std::string> keys;
ASSERT_TRUE(VerifyStanza(key_value_pairs, keys, stanza.get(), &error)) <<
error;
}
TEST(ServerLogEntryClientTest, AddSessionDuration) {
scoped_ptr<ServerLogEntry> entry(MakeLogEntryForSessionStateChange(
ConnectionToHost::CONNECTED, remoting::protocol::OK));
AddSessionDurationToLogEntry(entry.get(), base::TimeDelta::FromSeconds(123));
scoped_ptr<XmlElement> stanza = entry->ToStanza();
std::string error;
std::map<std::string, std::string> key_value_pairs;
key_value_pairs["role"] = "client";
key_value_pairs["event-name"] = "session-state";
key_value_pairs["session-state"] = "connected";
key_value_pairs["session-duration"] = "123";
std::set<std::string> keys;
ASSERT_TRUE(VerifyStanza(key_value_pairs, keys, stanza.get(), &error))
<< error;
}
} // namespace remoting
...@@ -14,8 +14,9 @@ ...@@ -14,8 +14,9 @@
#include "base/time/time.h" #include "base/time/time.h"
#include "remoting/base/constants.h" #include "remoting/base/constants.h"
#include "remoting/base/logging.h" #include "remoting/base/logging.h"
#include "remoting/host/server_log_entry.h" #include "remoting/host/server_log_entry_host.h"
#include "remoting/jingle_glue/iq_sender.h" #include "remoting/jingle_glue/iq_sender.h"
#include "remoting/jingle_glue/server_log_entry.h"
#include "remoting/jingle_glue/signal_strategy.h" #include "remoting/jingle_glue/signal_strategy.h"
#include "third_party/libjingle/source/talk/xmllite/xmlelement.h" #include "third_party/libjingle/source/talk/xmllite/xmlelement.h"
#include "third_party/libjingle/source/talk/xmpp/constants.h" #include "third_party/libjingle/source/talk/xmpp/constants.h"
...@@ -255,8 +256,8 @@ scoped_ptr<XmlElement> HeartbeatSender::CreateHeartbeatMessage() { ...@@ -255,8 +256,8 @@ scoped_ptr<XmlElement> HeartbeatSender::CreateHeartbeatMessage() {
heartbeat->AddElement(version_tag.release()); heartbeat->AddElement(version_tag.release());
// Append log message (which isn't signed). // Append log message (which isn't signed).
scoped_ptr<XmlElement> log(ServerLogEntry::MakeStanza()); scoped_ptr<XmlElement> log(ServerLogEntry::MakeStanza());
scoped_ptr<ServerLogEntry> log_entry(ServerLogEntry::MakeForHeartbeat()); scoped_ptr<ServerLogEntry> log_entry(MakeLogEntryForHeartbeat());
log_entry->AddHostFields(); AddHostFieldsToLogEntry(log_entry.get());
log->AddElement(log_entry->ToStanza().release()); log->AddElement(log_entry->ToStanza().release());
heartbeat->AddElement(log.release()); heartbeat->AddElement(log.release());
return heartbeat.Pass(); return heartbeat.Pass();
......
...@@ -9,8 +9,9 @@ ...@@ -9,8 +9,9 @@
#include "base/time/time.h" #include "base/time/time.h"
#include "remoting/base/constants.h" #include "remoting/base/constants.h"
#include "remoting/base/logging.h" #include "remoting/base/logging.h"
#include "remoting/host/server_log_entry.h" #include "remoting/host/server_log_entry_host.h"
#include "remoting/jingle_glue/iq_sender.h" #include "remoting/jingle_glue/iq_sender.h"
#include "remoting/jingle_glue/server_log_entry.h"
#include "remoting/jingle_glue/signal_strategy.h" #include "remoting/jingle_glue/signal_strategy.h"
#include "third_party/libjingle/source/talk/xmllite/xmlelement.h" #include "third_party/libjingle/source/talk/xmllite/xmlelement.h"
#include "third_party/libjingle/source/talk/xmpp/constants.h" #include "third_party/libjingle/source/talk/xmpp/constants.h"
...@@ -123,8 +124,8 @@ scoped_ptr<XmlElement> HostStatusSender::CreateHostStatusMessage( ...@@ -123,8 +124,8 @@ scoped_ptr<XmlElement> HostStatusSender::CreateHostStatusMessage(
// Append log message (which isn't signed). // Append log message (which isn't signed).
scoped_ptr<XmlElement> log(ServerLogEntry::MakeStanza()); scoped_ptr<XmlElement> log(ServerLogEntry::MakeStanza());
scoped_ptr<ServerLogEntry> log_entry( scoped_ptr<ServerLogEntry> log_entry(
ServerLogEntry::MakeForHostStatus(status, exit_code)); MakeLogEntryForHostStatus(status, exit_code));
log_entry->AddHostFields(); AddHostFieldsToLogEntry(log_entry.get());
log->AddElement(log_entry->ToStanza().release()); log->AddElement(log_entry->ToStanza().release());
host_status->AddElement(log.release()); host_status->AddElement(log.release());
return host_status.Pass(); return host_status.Pass();
......
...@@ -21,6 +21,7 @@ ...@@ -21,6 +21,7 @@
#include "remoting/host/register_support_host_request.h" #include "remoting/host/register_support_host_request.h"
#include "remoting/host/session_manager_factory.h" #include "remoting/host/session_manager_factory.h"
#include "remoting/jingle_glue/network_settings.h" #include "remoting/jingle_glue/network_settings.h"
#include "remoting/jingle_glue/server_log_entry.h"
#include "remoting/protocol/it2me_host_authenticator_factory.h" #include "remoting/protocol/it2me_host_authenticator_factory.h"
namespace remoting { namespace remoting {
......
...@@ -18,12 +18,13 @@ class DictionaryValue; ...@@ -18,12 +18,13 @@ class DictionaryValue;
namespace remoting { namespace remoting {
class RegisterSupportHostRequest;
class HostNPScriptObject;
class DesktopEnvironmentFactory;
class HostEventLogger;
class ChromotingHost; class ChromotingHost;
class ChromotingHostContext; class ChromotingHostContext;
class DesktopEnvironmentFactory;
class HostEventLogger;
class HostNPScriptObject;
class RegisterSupportHostRequest;
class RsaKeyPair;
namespace policy_hack { namespace policy_hack {
......
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
#include "net/socket/ssl_server_socket.h" #include "net/socket/ssl_server_socket.h"
#include "remoting/base/breakpad.h" #include "remoting/base/breakpad.h"
#include "remoting/base/resources.h" #include "remoting/base/resources.h"
#include "remoting/host/host_exit_codes.h"
#include "remoting/host/it2me/it2me_native_messaging_host.h" #include "remoting/host/it2me/it2me_native_messaging_host.h"
#include "remoting/host/logging.h" #include "remoting/host/logging.h"
#include "remoting/host/usage_stats_consent.h" #include "remoting/host/usage_stats_consent.h"
......
...@@ -8,8 +8,9 @@ ...@@ -8,8 +8,9 @@
#include "base/message_loop/message_loop_proxy.h" #include "base/message_loop/message_loop_proxy.h"
#include "remoting/base/constants.h" #include "remoting/base/constants.h"
#include "remoting/host/host_status_monitor.h" #include "remoting/host/host_status_monitor.h"
#include "remoting/host/server_log_entry.h" #include "remoting/host/server_log_entry_host.h"
#include "remoting/jingle_glue/iq_sender.h" #include "remoting/jingle_glue/iq_sender.h"
#include "remoting/jingle_glue/server_log_entry.h"
#include "remoting/jingle_glue/signal_strategy.h" #include "remoting/jingle_glue/signal_strategy.h"
#include "remoting/protocol/transport.h" #include "remoting/protocol/transport.h"
#include "third_party/libjingle/source/talk/xmllite/xmlelement.h" #include "third_party/libjingle/source/talk/xmllite/xmlelement.h"
...@@ -43,13 +44,13 @@ void LogToServer::LogSessionStateChange(const std::string& jid, ...@@ -43,13 +44,13 @@ void LogToServer::LogSessionStateChange(const std::string& jid,
DCHECK(CalledOnValidThread()); DCHECK(CalledOnValidThread());
scoped_ptr<ServerLogEntry> entry( scoped_ptr<ServerLogEntry> entry(
ServerLogEntry::MakeForSessionStateChange(connected)); MakeLogEntryForSessionStateChange(connected));
entry->AddHostFields(); AddHostFieldsToLogEntry(entry.get());
entry->AddModeField(mode_); entry->AddModeField(mode_);
if (connected) { if (connected) {
DCHECK(connection_route_type_.count(jid) == 1); DCHECK(connection_route_type_.count(jid) == 1);
entry->AddConnectionTypeField(connection_route_type_[jid]); AddConnectionTypeToLogEntry(entry.get(), connection_route_type_[jid]);
} }
Log(*entry.get()); Log(*entry.get());
} }
......
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
#include "base/memory/weak_ptr.h" #include "base/memory/weak_ptr.h"
#include "base/threading/non_thread_safe.h" #include "base/threading/non_thread_safe.h"
#include "remoting/host/host_status_observer.h" #include "remoting/host/host_status_observer.h"
#include "remoting/host/server_log_entry.h" #include "remoting/jingle_glue/server_log_entry.h"
#include "remoting/jingle_glue/signal_strategy.h" #include "remoting/jingle_glue/signal_strategy.h"
#include "remoting/protocol/transport.h" #include "remoting/protocol/transport.h"
......
// Copyright (c) 2012 The Chromium Authors. All rights reserved. // Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#include "remoting/host/server_log_entry.h" #include "remoting/host/server_log_entry_host.h"
#include "base/logging.h"
#include "base/strings/stringize_macros.h" #include "base/strings/stringize_macros.h"
#include "base/sys_info.h" #include "base/sys_info.h"
#include "remoting/base/constants.h" #include "remoting/jingle_glue/server_log_entry.h"
#include "remoting/protocol/session.h"
#include "third_party/libjingle/source/talk/xmllite/xmlelement.h"
using base::SysInfo; using base::SysInfo;
using buzz::QName;
using buzz::XmlElement;
using remoting::protocol::Session;
namespace remoting { namespace remoting {
namespace { namespace {
const char kLogCommand[] = "log";
const char kLogEntry[] = "entry";
const char kKeyEventName[] = "event-name";
const char kValueEventNameSessionState[] = "session-state"; const char kValueEventNameSessionState[] = "session-state";
const char kValueEventNameHeartbeat[] = "heartbeat"; const char kValueEventNameHeartbeat[] = "heartbeat";
const char kValueEventNameHostStatus[] = "host-status"; const char kValueEventNameHostStatus[] = "host-status";
const char kKeyRole[] = "role";
const char kValueRoleHost[] = "host"; const char kValueRoleHost[] = "host";
const char kKeyMode[] = "mode";
const char kValueModeIt2Me[] = "it2me";
const char kValueModeMe2Me[] = "me2me";
const char kKeySessionState[] = "session-state"; const char kKeySessionState[] = "session-state";
const char kValueSessionStateConnected[] = "connected"; const char kValueSessionStateConnected[] = "connected";
const char kValueSessionStateClosed[] = "closed"; const char kValueSessionStateClosed[] = "closed";
...@@ -50,63 +34,51 @@ const char kKeyOsVersion[] = "os-version"; ...@@ -50,63 +34,51 @@ const char kKeyOsVersion[] = "os-version";
const char kKeyHostVersion[] = "host-version"; const char kKeyHostVersion[] = "host-version";
const char kKeyCpu[] = "cpu";
const char kKeyConnectionType[] = "connection-type"; const char kKeyConnectionType[] = "connection-type";
} // namespace const char* GetValueSessionState(bool connected) {
return connected ? kValueSessionStateConnected : kValueSessionStateClosed;
ServerLogEntry::ServerLogEntry() {
}
ServerLogEntry::~ServerLogEntry() {
} }
// static } // namespace
scoped_ptr<buzz::XmlElement> ServerLogEntry::MakeStanza() {
return scoped_ptr<buzz::XmlElement>(
new XmlElement(QName(kChromotingXmlNamespace, kLogCommand)));
}
// static scoped_ptr<ServerLogEntry> MakeLogEntryForSessionStateChange(
scoped_ptr<ServerLogEntry> ServerLogEntry::MakeForSessionStateChange(
bool connected) { bool connected) {
scoped_ptr<ServerLogEntry> entry(new ServerLogEntry()); scoped_ptr<ServerLogEntry> entry(new ServerLogEntry());
entry->Set(kKeyRole, kValueRoleHost); entry->AddRoleField(kValueRoleHost);
entry->Set(kKeyEventName, kValueEventNameSessionState); entry->AddEventNameField(kValueEventNameSessionState);
entry->Set(kKeySessionState, GetValueSessionState(connected)); entry->Set(kKeySessionState, GetValueSessionState(connected));
return entry.Pass(); return entry.Pass();
} }
// static scoped_ptr<ServerLogEntry> MakeLogEntryForHeartbeat() {
scoped_ptr<ServerLogEntry> ServerLogEntry::MakeForHeartbeat() {
scoped_ptr<ServerLogEntry> entry(new ServerLogEntry()); scoped_ptr<ServerLogEntry> entry(new ServerLogEntry());
entry->Set(kKeyRole, kValueRoleHost); entry->AddRoleField(kValueRoleHost);
entry->Set(kKeyEventName, kValueEventNameHeartbeat); entry->AddEventNameField(kValueEventNameHeartbeat);
return entry.Pass(); return entry.Pass();
} }
// static // static
scoped_ptr<ServerLogEntry> ServerLogEntry::MakeForHostStatus( scoped_ptr<ServerLogEntry> MakeLogEntryForHostStatus(
HostStatusSender::HostStatus host_status, HostExitCodes exit_code) { HostStatusSender::HostStatus host_status, HostExitCodes exit_code) {
scoped_ptr<ServerLogEntry> entry(new ServerLogEntry()); scoped_ptr<ServerLogEntry> entry(new ServerLogEntry());
entry->Set(kKeyRole, kValueRoleHost); entry->AddRoleField(kValueRoleHost);
entry->Set(kKeyEventName, kValueEventNameHostStatus); entry->AddEventNameField(kValueEventNameHostStatus);
entry->Set(kStatusName, HostStatusSender::HostStatusToString(host_status)); entry->Set(kStatusName, HostStatusSender::HostStatusToString(host_status));
if (host_status == HostStatusSender::OFFLINE) if (host_status == HostStatusSender::OFFLINE)
entry->Set(kExitCodeName, ExitCodeToString(exit_code)); entry->Set(kExitCodeName, ExitCodeToString(exit_code));
return entry.Pass(); return entry.Pass();
} }
void ServerLogEntry::AddHostFields() { void AddHostFieldsToLogEntry(ServerLogEntry* entry) {
#if defined(OS_WIN) #if defined(OS_WIN)
Set(kKeyOsName, "Windows"); entry->Set(kKeyOsName, "Windows");
#elif defined(OS_MACOSX) #elif defined(OS_MACOSX)
Set(kKeyOsName, "Mac"); entry->Set(kKeyOsName, "Mac");
#elif defined(OS_CHROMEOS) #elif defined(OS_CHROMEOS)
Set(kKeyOsName, "ChromeOS"); entry->Set(kKeyOsName, "ChromeOS");
#elif defined(OS_LINUX) #elif defined(OS_LINUX)
Set(kKeyOsName, "Linux"); entry->Set(kKeyOsName, "Linux");
#endif #endif
// SysInfo::OperatingSystemVersionNumbers is only defined for the following // SysInfo::OperatingSystemVersionNumbers is only defined for the following
...@@ -120,52 +92,16 @@ void ServerLogEntry::AddHostFields() { ...@@ -120,52 +92,16 @@ void ServerLogEntry::AddHostFields() {
&os_bugfix_version); &os_bugfix_version);
os_version << os_major_version << "." << os_minor_version << "." os_version << os_major_version << "." << os_minor_version << "."
<< os_bugfix_version; << os_bugfix_version;
Set(kKeyOsVersion, os_version.str()); entry->Set(kKeyOsVersion, os_version.str());
#endif #endif
Set(kKeyHostVersion, STRINGIZE(VERSION)); entry->Set(kKeyHostVersion, STRINGIZE(VERSION));
Set(kKeyCpu, SysInfo::OperatingSystemArchitecture()); entry->AddCpuField();
}; };
void ServerLogEntry::AddModeField(ServerLogEntry::Mode mode) { void AddConnectionTypeToLogEntry(ServerLogEntry* entry,
Set(kKeyMode, GetValueMode(mode));
}
void ServerLogEntry::AddConnectionTypeField(
protocol::TransportRoute::RouteType type) { protocol::TransportRoute::RouteType type) {
Set(kKeyConnectionType, protocol::TransportRoute::GetTypeString(type)); entry->Set(kKeyConnectionType, protocol::TransportRoute::GetTypeString(type));
}
// static
const char* ServerLogEntry::GetValueMode(ServerLogEntry::Mode mode) {
switch (mode) {
case IT2ME:
return kValueModeIt2Me;
case ME2ME:
return kValueModeMe2Me;
default:
NOTREACHED();
return NULL;
}
}
scoped_ptr<XmlElement> ServerLogEntry::ToStanza() const {
scoped_ptr<XmlElement> stanza(new XmlElement(QName(
kChromotingXmlNamespace, kLogEntry)));
ValuesMap::const_iterator iter;
for (iter = values_map_.begin(); iter != values_map_.end(); ++iter) {
stanza->AddAttr(QName(std::string(), iter->first), iter->second);
}
return stanza.Pass();
}
// static
const char* ServerLogEntry::GetValueSessionState(bool connected) {
return connected ? kValueSessionStateConnected : kValueSessionStateClosed;
}
void ServerLogEntry::Set(const std::string& key, const std::string& value) {
values_map_[key] = value;
} }
} // namespace remoting } // namespace remoting
// Copyright 2014 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.
#ifndef REMOTING_HOST_SERVER_LOG_ENTRY_HOST_H_
#define REMOTING_HOST_SERVER_LOG_ENTRY_HOST_H_
#include "remoting/host/host_exit_codes.h"
#include "remoting/host/host_status_sender.h"
#include "remoting/protocol/transport.h"
namespace remoting {
class ServerLogEntry;
// Constructs a log entry for a session state change.
// Currently this is either connection or disconnection.
scoped_ptr<ServerLogEntry> MakeLogEntryForSessionStateChange(
bool connected);
// Constructs a log entry for a heartbeat.
scoped_ptr<ServerLogEntry> MakeLogEntryForHeartbeat();
// Constructs a log entry for a host status message.
scoped_ptr<ServerLogEntry> MakeLogEntryForHostStatus(
HostStatusSender::HostStatus host_status, HostExitCodes exit_code);
// Adds fields describing the host to this log entry.
void AddHostFieldsToLogEntry(ServerLogEntry* entry);
// Adds a field describing connection type (direct/stun/relay).
void AddConnectionTypeToLogEntry(ServerLogEntry* entry,
protocol::TransportRoute::RouteType type);
} // namespace remoting
#endif // REMOTING_HOST_SERVER_LOG_ENTRY_HOST_H_
// Copyright (c) 2012 The Chromium Authors. All rights reserved. // Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#include "base/memory/scoped_ptr.h" #include "base/memory/scoped_ptr.h"
#include "base/strings/stringize_macros.h" #include "base/strings/stringize_macros.h"
#include "remoting/host/server_log_entry.h" #include "remoting/host/server_log_entry_host.h"
#include "remoting/jingle_glue/server_log_entry.h"
#include "remoting/jingle_glue/server_log_entry_unittest.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
#include "third_party/libjingle/source/talk/xmllite/xmlelement.h" #include "third_party/libjingle/source/talk/xmllite/xmlelement.h"
...@@ -13,57 +15,8 @@ using buzz::XmlElement; ...@@ -13,57 +15,8 @@ using buzz::XmlElement;
namespace remoting { namespace remoting {
class ServerLogEntryTest : public testing::Test { TEST(ServerLogEntryHostTest, MakeForSessionStateChange) {
protected: scoped_ptr<ServerLogEntry> entry(MakeLogEntryForSessionStateChange(true));
// Verifies a logging stanza.
// |keyValuePairs| lists the keys that must have specified values, and |keys|
// lists the keys that must be present, but may have arbitrary values.
// There must be no other keys.
static bool VerifyStanza(
const std::map<std::string, std::string>& key_value_pairs,
const std::set<std::string> keys,
const XmlElement* elem,
std::string* error) {
int attrCount = 0;
for (const XmlAttr* attr = elem->FirstAttr(); attr != NULL;
attr = attr->NextAttr(), attrCount++) {
if (attr->Name().Namespace().length() != 0) {
*error = "attribute has non-empty namespace " +
attr->Name().Namespace();
return false;
}
const std::string& key = attr->Name().LocalPart();
const std::string& value = attr->Value();
std::map<std::string, std::string>::const_iterator iter =
key_value_pairs.find(key);
if (iter == key_value_pairs.end()) {
if (keys.find(key) == keys.end()) {
*error = "unexpected attribute " + key;
return false;
}
} else {
if (iter->second != value) {
*error = "attribute " + key + " has value " + iter->second +
": expected " + value;
return false;
}
}
}
int attr_count_expected = key_value_pairs.size() + keys.size();
if (attrCount != attr_count_expected) {
std::stringstream s;
s << "stanza has " << attrCount << " keys: expected "
<< attr_count_expected;
*error = s.str();
return false;
}
return true;
}
};
TEST_F(ServerLogEntryTest, MakeForSessionStateChange) {
scoped_ptr<ServerLogEntry> entry(
ServerLogEntry::MakeForSessionStateChange(true));
scoped_ptr<XmlElement> stanza = entry->ToStanza(); scoped_ptr<XmlElement> stanza = entry->ToStanza();
std::string error; std::string error;
std::map<std::string, std::string> key_value_pairs; std::map<std::string, std::string> key_value_pairs;
...@@ -75,8 +28,8 @@ TEST_F(ServerLogEntryTest, MakeForSessionStateChange) { ...@@ -75,8 +28,8 @@ TEST_F(ServerLogEntryTest, MakeForSessionStateChange) {
<< error; << error;
} }
TEST_F(ServerLogEntryTest, MakeForHeartbeat) { TEST(ServerLogEntryHostTest, MakeForHeartbeat) {
scoped_ptr<ServerLogEntry> entry(ServerLogEntry::MakeForHeartbeat()); scoped_ptr<ServerLogEntry> entry(MakeLogEntryForHeartbeat());
scoped_ptr<XmlElement> stanza = entry->ToStanza(); scoped_ptr<XmlElement> stanza = entry->ToStanza();
std::string error; std::string error;
std::map<std::string, std::string> key_value_pairs; std::map<std::string, std::string> key_value_pairs;
...@@ -87,10 +40,9 @@ TEST_F(ServerLogEntryTest, MakeForHeartbeat) { ...@@ -87,10 +40,9 @@ TEST_F(ServerLogEntryTest, MakeForHeartbeat) {
<< error; << error;
} }
TEST_F(ServerLogEntryTest, AddHostFields) { TEST(ServerLogEntryHostTest, AddHostFields) {
scoped_ptr<ServerLogEntry> entry( scoped_ptr<ServerLogEntry> entry(MakeLogEntryForSessionStateChange(true));
ServerLogEntry::MakeForSessionStateChange(true)); AddHostFieldsToLogEntry(entry.get());
entry->AddHostFields();
scoped_ptr<XmlElement> stanza = entry->ToStanza(); scoped_ptr<XmlElement> stanza = entry->ToStanza();
std::string error; std::string error;
std::map<std::string, std::string> key_value_pairs; std::map<std::string, std::string> key_value_pairs;
...@@ -116,9 +68,8 @@ TEST_F(ServerLogEntryTest, AddHostFields) { ...@@ -116,9 +68,8 @@ TEST_F(ServerLogEntryTest, AddHostFields) {
error; error;
} }
TEST_F(ServerLogEntryTest, AddModeField1) { TEST(ServerLogEntryHostTest, AddModeField1) {
scoped_ptr<ServerLogEntry> entry( scoped_ptr<ServerLogEntry> entry(MakeLogEntryForSessionStateChange(true));
ServerLogEntry::MakeForSessionStateChange(true));
entry->AddModeField(ServerLogEntry::IT2ME); entry->AddModeField(ServerLogEntry::IT2ME);
scoped_ptr<XmlElement> stanza = entry->ToStanza(); scoped_ptr<XmlElement> stanza = entry->ToStanza();
std::string error; std::string error;
...@@ -132,9 +83,8 @@ TEST_F(ServerLogEntryTest, AddModeField1) { ...@@ -132,9 +83,8 @@ TEST_F(ServerLogEntryTest, AddModeField1) {
error; error;
} }
TEST_F(ServerLogEntryTest, AddModeField2) { TEST(ServerLogEntryHostTest, AddModeField2) {
scoped_ptr<ServerLogEntry> entry( scoped_ptr<ServerLogEntry> entry(MakeLogEntryForSessionStateChange(true));
ServerLogEntry::MakeForSessionStateChange(true));
entry->AddModeField(ServerLogEntry::ME2ME); entry->AddModeField(ServerLogEntry::ME2ME);
scoped_ptr<XmlElement> stanza = entry->ToStanza(); scoped_ptr<XmlElement> stanza = entry->ToStanza();
std::string error; std::string error;
......
// Copyright 2014 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/jingle_glue/server_log_entry.h"
#include "base/logging.h"
#include "base/sys_info.h"
#include "remoting/base/constants.h"
#include "third_party/libjingle/source/talk/xmllite/xmlelement.h"
using base::SysInfo;
using buzz::QName;
using buzz::XmlElement;
namespace remoting {
namespace {
const char kLogCommand[] = "log";
const char kLogEntry[] = "entry";
const char kKeyEventName[] = "event-name";
const char kKeyRole[] = "role";
const char kKeyMode[] = "mode";
const char kValueModeIt2Me[] = "it2me";
const char kValueModeMe2Me[] = "me2me";
const char kKeyCpu[] = "cpu";
} // namespace
ServerLogEntry::ServerLogEntry() {
}
ServerLogEntry::~ServerLogEntry() {
}
void ServerLogEntry::Set(const std::string& key, const std::string& value) {
values_map_[key] = value;
}
void ServerLogEntry::AddCpuField() {
Set(kKeyCpu, SysInfo::OperatingSystemArchitecture());
}
void ServerLogEntry::AddModeField(ServerLogEntry::Mode mode) {
const char* mode_value = NULL;
switch (mode) {
case IT2ME:
mode_value = kValueModeIt2Me;
break;
case ME2ME:
mode_value = kValueModeMe2Me;
break;
default:
NOTREACHED();
}
Set(kKeyMode, mode_value);
}
void ServerLogEntry::AddRoleField(const char* role) {
Set(kKeyRole, role);
}
void ServerLogEntry::AddEventNameField(const char* name) {
Set(kKeyEventName, name);
}
// static
scoped_ptr<XmlElement> ServerLogEntry::MakeStanza() {
return scoped_ptr<XmlElement>(
new XmlElement(QName(kChromotingXmlNamespace, kLogCommand)));
}
scoped_ptr<XmlElement> ServerLogEntry::ToStanza() const {
scoped_ptr<XmlElement> stanza(new XmlElement(QName(
kChromotingXmlNamespace, kLogEntry)));
ValuesMap::const_iterator iter;
for (iter = values_map_.begin(); iter != values_map_.end(); ++iter) {
stanza->AddAttr(QName(std::string(), iter->first), iter->second);
}
return stanza.Pass();
}
} // namespace remoting
// Copyright (c) 2012 The Chromium Authors. All rights reserved. // Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#ifndef REMOTING_HOST_SERVER_LOG_ENTRY_H_ #ifndef REMOTING_JINGLE_GLUE_SERVER_LOG_ENTRY_H_
#define REMOTING_HOST_SERVER_LOG_ENTRY_H_ #define REMOTING_JINGLE_GLUE_SERVER_LOG_ENTRY_H_
#include <map> #include <map>
#include <string> #include <string>
#include "base/memory/scoped_ptr.h" #include "base/memory/scoped_ptr.h"
#include "remoting/host/host_exit_codes.h"
#include "remoting/host/host_status_sender.h"
#include "remoting/protocol/transport.h"
namespace buzz { namespace buzz {
class XmlElement; class XmlElement;
...@@ -19,6 +16,9 @@ class XmlElement; ...@@ -19,6 +16,9 @@ class XmlElement;
namespace remoting { namespace remoting {
// Utility class for building log entries to send to the remoting bot. This is
// a wrapper around a key/value map and is copyable so it can be used in STL
// containers.
class ServerLogEntry { class ServerLogEntry {
public: public:
// The mode of a connection. // The mode of a connection.
...@@ -27,32 +27,28 @@ class ServerLogEntry { ...@@ -27,32 +27,28 @@ class ServerLogEntry {
ME2ME ME2ME
}; };
// Constructs a log stanza. The caller should add one or more log entry ServerLogEntry();
// 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 scoped_ptr<ServerLogEntry> MakeForSessionStateChange(bool connection);
// Constructs a log entry for a heartbeat.
static scoped_ptr<ServerLogEntry> MakeForHeartbeat();
// Constructs a log entry for a host status message.
static scoped_ptr<ServerLogEntry> MakeForHostStatus(
HostStatusSender::HostStatus host_status, HostExitCodes exit_code);
~ServerLogEntry(); ~ServerLogEntry();
// Adds fields describing the host to this log entry. // Sets an arbitrary key/value entry.
void AddHostFields(); void Set(const std::string& key, const std::string& value);
// Adds a field describing the CPU type of the platform.
void AddCpuField();
// Adds a field describing the mode of a connection to this log entry. // Adds a field describing the mode of a connection to this log entry.
void AddModeField(Mode mode); void AddModeField(Mode mode);
// Adds a field describing connection type (direct/stun/relay). // Adds a field describing the role (client/host).
void AddConnectionTypeField(protocol::TransportRoute::RouteType type); void AddRoleField(const char* role);
// Adds a field describing the type of log entry.
void AddEventNameField(const char* name);
// 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();
// Converts this object to an XML stanza. // Converts this object to an XML stanza.
scoped_ptr<buzz::XmlElement> ToStanza() const; scoped_ptr<buzz::XmlElement> ToStanza() const;
...@@ -60,15 +56,9 @@ class ServerLogEntry { ...@@ -60,15 +56,9 @@ class ServerLogEntry {
private: private:
typedef std::map<std::string, std::string> ValuesMap; typedef std::map<std::string, std::string> ValuesMap;
ServerLogEntry();
void Set(const std::string& key, const std::string& value);
static const char* GetValueSessionState(bool connected);
static const char* GetValueMode(Mode mode);
ValuesMap values_map_; ValuesMap values_map_;
}; };
} // namespace remoting } // namespace remoting
#endif #endif // REMOTING_JINGLE_GLUE_SERVER_LOG_ENTRY_H_
// Copyright 2014 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/jingle_glue/server_log_entry_unittest.h"
#include <sstream>
#include "third_party/libjingle/source/talk/xmllite/xmlelement.h"
using buzz::XmlAttr;
using buzz::XmlElement;
namespace remoting {
bool VerifyStanza(
const std::map<std::string, std::string>& key_value_pairs,
const std::set<std::string> keys,
const XmlElement* elem,
std::string* error) {
int attrCount = 0;
for (const XmlAttr* attr = elem->FirstAttr(); attr != NULL;
attr = attr->NextAttr(), attrCount++) {
if (attr->Name().Namespace().length() != 0) {
*error = "attribute has non-empty namespace " +
attr->Name().Namespace();
return false;
}
const std::string& key = attr->Name().LocalPart();
const std::string& value = attr->Value();
std::map<std::string, std::string>::const_iterator iter =
key_value_pairs.find(key);
if (iter == key_value_pairs.end()) {
if (keys.find(key) == keys.end()) {
*error = "unexpected attribute " + key;
return false;
}
} else {
if (iter->second != value) {
*error = "attribute " + key + " has value " + iter->second +
": expected " + value;
return false;
}
}
}
int attr_count_expected = key_value_pairs.size() + keys.size();
if (attrCount != attr_count_expected) {
std::stringstream s;
s << "stanza has " << attrCount << " keys: expected "
<< attr_count_expected;
*error = s.str();
return false;
}
return true;
}
} // namespace remoting
// Copyright 2014 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 <map>
#include <set>
#include <string>
namespace buzz {
class XmlElement;
} // namespace buzz
namespace remoting {
// Verifies a logging stanza.
// |keyValuePairs| lists the keys that must have specified values, and |keys|
// lists the keys that must be present, but may have arbitrary values.
// There must be no other keys.
bool VerifyStanza(
const std::map<std::string, std::string>& key_value_pairs,
const std::set<std::string> keys,
const buzz::XmlElement* elem,
std::string* error);
} // namespace remoting
...@@ -221,8 +221,8 @@ ...@@ -221,8 +221,8 @@
'host/screen_controls.h', 'host/screen_controls.h',
'host/screen_resolution.cc', 'host/screen_resolution.cc',
'host/screen_resolution.h', 'host/screen_resolution.h',
'host/server_log_entry.cc', 'host/server_log_entry_host.cc',
'host/server_log_entry.h', 'host/server_log_entry_host.h',
'host/service_urls.cc', 'host/service_urls.cc',
'host/service_urls.h', 'host/service_urls.h',
'host/session_manager_factory.cc', 'host/session_manager_factory.cc',
......
...@@ -75,6 +75,8 @@ ...@@ -75,6 +75,8 @@
'jingle_glue/jingle_info_request.h', 'jingle_glue/jingle_info_request.h',
'jingle_glue/network_settings.cc', 'jingle_glue/network_settings.cc',
'jingle_glue/network_settings.h', 'jingle_glue/network_settings.h',
'jingle_glue/server_log_entry.cc',
'jingle_glue/server_log_entry.h',
'jingle_glue/signal_strategy.h', 'jingle_glue/signal_strategy.h',
'jingle_glue/xmpp_signal_strategy.cc', 'jingle_glue/xmpp_signal_strategy.cc',
'jingle_glue/xmpp_signal_strategy.h', 'jingle_glue/xmpp_signal_strategy.h',
...@@ -212,8 +214,8 @@ ...@@ -212,8 +214,8 @@
'client/key_event_mapper.h', 'client/key_event_mapper.h',
'client/log_to_server.cc', 'client/log_to_server.cc',
'client/log_to_server.h', 'client/log_to_server.h',
'client/server_log_entry.cc', 'client/server_log_entry_client.cc',
'client/server_log_entry.h', 'client/server_log_entry_client.h',
'client/software_video_renderer.cc', 'client/software_video_renderer.cc',
'client/software_video_renderer.h', 'client/software_video_renderer.h',
'client/video_renderer.h', 'client/video_renderer.h',
......
...@@ -56,6 +56,7 @@ ...@@ -56,6 +56,7 @@
'base/util_unittest.cc', 'base/util_unittest.cc',
'client/audio_player_unittest.cc', 'client/audio_player_unittest.cc',
'client/key_event_mapper_unittest.cc', 'client/key_event_mapper_unittest.cc',
'client/server_log_entry_client_unittest.cc',
'client/plugin/normalizing_input_filter_cros_unittest.cc', 'client/plugin/normalizing_input_filter_cros_unittest.cc',
'client/plugin/normalizing_input_filter_mac_unittest.cc', 'client/plugin/normalizing_input_filter_mac_unittest.cc',
'codec/audio_encoder_opus_unittest.cc', 'codec/audio_encoder_opus_unittest.cc',
...@@ -100,12 +101,12 @@ ...@@ -100,12 +101,12 @@
'host/register_support_host_request_unittest.cc', 'host/register_support_host_request_unittest.cc',
'host/remote_input_filter_unittest.cc', 'host/remote_input_filter_unittest.cc',
'host/resizing_host_observer_unittest.cc', 'host/resizing_host_observer_unittest.cc',
'host/setup/me2me_native_messaging_host.cc',
'host/setup/me2me_native_messaging_host.h',
'host/screen_capturer_fake.cc', 'host/screen_capturer_fake.cc',
'host/screen_capturer_fake.h', 'host/screen_capturer_fake.h',
'host/screen_resolution_unittest.cc', 'host/screen_resolution_unittest.cc',
'host/server_log_entry_unittest.cc', 'host/server_log_entry_host_unittest.cc',
'host/setup/me2me_native_messaging_host.cc',
'host/setup/me2me_native_messaging_host.h',
'host/setup/me2me_native_messaging_host_unittest.cc', 'host/setup/me2me_native_messaging_host_unittest.cc',
'host/setup/oauth_helper_unittest.cc', 'host/setup/oauth_helper_unittest.cc',
'host/setup/pin_validator_unittest.cc', 'host/setup/pin_validator_unittest.cc',
...@@ -123,6 +124,8 @@ ...@@ -123,6 +124,8 @@
'jingle_glue/mock_objects.cc', 'jingle_glue/mock_objects.cc',
'jingle_glue/mock_objects.h', 'jingle_glue/mock_objects.h',
'jingle_glue/network_settings_unittest.cc', 'jingle_glue/network_settings_unittest.cc',
'jingle_glue/server_log_entry_unittest.cc',
'jingle_glue/server_log_entry_unittest.h',
'protocol/authenticator_test_base.cc', 'protocol/authenticator_test_base.cc',
'protocol/authenticator_test_base.h', 'protocol/authenticator_test_base.h',
'protocol/buffered_socket_writer_unittest.cc', 'protocol/buffered_socket_writer_unittest.cc',
......
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