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

Unified Diff: remoting/client/server_log_entry_client.cc

Issue 282063005: Pull out common code from client and host versions of ServerLogEntry. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 7 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/client/server_log_entry_client.cc
diff --git a/remoting/client/server_log_entry.cc b/remoting/client/server_log_entry_client.cc
similarity index 53%
rename from remoting/client/server_log_entry.cc
rename to remoting/client/server_log_entry_client.cc
index cd580d8863145b12b646e2cc30db20901b5a9cee..3af5e9f661428a84cda02156d9e0e246a431bef2 100644
--- a/remoting/client/server_log_entry.cc
+++ b/remoting/client/server_log_entry_client.cc
@@ -2,50 +2,36 @@
// Use of this source code is governed by a BSD-style license that can be
// 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/stringize_macros.h"
#include "base/strings/stringprintf.h"
#include "base/sys_info.h"
-#include "remoting/base/constants.h"
#include "remoting/client/chromoting_stats.h"
-#include "remoting/protocol/connection_to_host.h"
-#include "remoting/protocol/errors.h"
-#include "third_party/libjingle/source/talk/xmllite/xmlelement.h"
+#include "remoting/protocol/server_log_entry.h"
using base::StringPrintf;
using base::SysInfo;
-using buzz::QName;
-using buzz::XmlElement;
using remoting::protocol::ConnectionToHost;
+using remoting::protocol::ErrorCode;
+using remoting::protocol::ServerLogEntry;
namespace remoting {
-namespace client {
-
namespace {
-const char kLogCommand[] = "log";
-
-const char kLogEntry[] = "entry";
+const char kValueRoleClient[] = "client";
-const char kKeyEventName[] = "event-name";
const char kValueEventNameSessionState[] = "session-state";
const char kValueEventNameStatistics[] = "connection-statistics";
const char kValueEventNameSessionIdOld[] = "session-id-old";
const char kValueEventNameSessionIdNew[] = "session-id-new";
-const char kKeyRole[] = "role";
-const char kValueRoleClient[] = "client";
-
-const char kKeyMode[] = "mode";
-const char kValueModeIt2Me[] = "it2me";
-const char kValueModeMe2Me[] = "me2me";
+const char kKeySessionId[] = "session-id";
+const char kKeySessionDuration[] = "session-duration";
const char kKeySessionState[] = "session-state";
+const char kKeyConnectionError[] = "connection-error";
const char kValueSessionStateConnected[] = "connected";
const char kValueSessionStateClosed[] = "closed";
@@ -53,126 +39,7 @@ const char kKeyOsName[] = "os-name";
const char kKeyOsVersion[] = "os-version";
const char kKeyAppVersion[] = "app-version";
-const char kKeyCpu[] = "cpu";
-
-} // 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) {
+const char* GetValueSessionState(ConnectionToHost::State state) {
switch (state) {
// Where possible, these are the same strings that the webapp sends for the
// corresponding state - see remoting/webapp/server_log_entry.js.
@@ -194,8 +61,7 @@ const char* ServerLogEntry::GetValueSessionState(
}
}
-// static
-const char* ServerLogEntry::GetValueError(protocol::ErrorCode error) {
+const char* GetValueError(ErrorCode error) {
switch (error) {
// Where possible, these are the same strings that the webapp sends for the
// corresponding error - see remoting/webapp/server_log_entry.js.
@@ -225,14 +91,77 @@ const char* ServerLogEntry::GetValueError(protocol::ErrorCode error) {
}
}
-void ServerLogEntry::AddEventName(const std::string& event_name) {
- Set("event-name", event_name);
+} // namespace
+
+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) {
- values_map_[key] = value;
+scoped_ptr<ServerLogEntry> MakeLogEntryForSessionIdNew(
+ 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

Powered by Google App Engine
This is Rietveld 408576698