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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/client/server_log_entry.h" 5 #include "remoting/client/server_log_entry_client.h"
6 6
7 #include "base/logging.h"
8 #include "base/macros.h"
9 #include "base/rand_util.h"
10 #include "base/strings/string_number_conversions.h" 7 #include "base/strings/string_number_conversions.h"
11 #include "base/strings/stringize_macros.h" 8 #include "base/strings/stringize_macros.h"
12 #include "base/strings/stringprintf.h" 9 #include "base/strings/stringprintf.h"
13 #include "base/sys_info.h" 10 #include "base/sys_info.h"
14 #include "remoting/base/constants.h"
15 #include "remoting/client/chromoting_stats.h" 11 #include "remoting/client/chromoting_stats.h"
16 #include "remoting/protocol/connection_to_host.h" 12 #include "remoting/protocol/server_log_entry.h"
17 #include "remoting/protocol/errors.h"
18 #include "third_party/libjingle/source/talk/xmllite/xmlelement.h"
19 13
20 using base::StringPrintf; 14 using base::StringPrintf;
21 using base::SysInfo; 15 using base::SysInfo;
22 using buzz::QName;
23 using buzz::XmlElement;
24 using remoting::protocol::ConnectionToHost; 16 using remoting::protocol::ConnectionToHost;
17 using remoting::protocol::ErrorCode;
18 using remoting::protocol::ServerLogEntry;
25 19
26 namespace remoting { 20 namespace remoting {
27 21
28 namespace client { 22 namespace {
23 const char kValueRoleClient[] = "client";
29 24
30 namespace {
31 const char kLogCommand[] = "log";
32
33 const char kLogEntry[] = "entry";
34
35 const char kKeyEventName[] = "event-name";
36 const char kValueEventNameSessionState[] = "session-state"; 25 const char kValueEventNameSessionState[] = "session-state";
37 const char kValueEventNameStatistics[] = "connection-statistics"; 26 const char kValueEventNameStatistics[] = "connection-statistics";
38 const char kValueEventNameSessionIdOld[] = "session-id-old"; 27 const char kValueEventNameSessionIdOld[] = "session-id-old";
39 const char kValueEventNameSessionIdNew[] = "session-id-new"; 28 const char kValueEventNameSessionIdNew[] = "session-id-new";
40 29
41 const char kKeyRole[] = "role"; 30 const char kKeySessionId[] = "session-id";
42 const char kValueRoleClient[] = "client"; 31 const char kKeySessionDuration[] = "session-duration";
43
44 const char kKeyMode[] = "mode";
45 const char kValueModeIt2Me[] = "it2me";
46 const char kValueModeMe2Me[] = "me2me";
47 32
48 const char kKeySessionState[] = "session-state"; 33 const char kKeySessionState[] = "session-state";
34 const char kKeyConnectionError[] = "connection-error";
49 const char kValueSessionStateConnected[] = "connected"; 35 const char kValueSessionStateConnected[] = "connected";
50 const char kValueSessionStateClosed[] = "closed"; 36 const char kValueSessionStateClosed[] = "closed";
51 37
52 const char kKeyOsName[] = "os-name"; 38 const char kKeyOsName[] = "os-name";
53 const char kKeyOsVersion[] = "os-version"; 39 const char kKeyOsVersion[] = "os-version";
54 const char kKeyAppVersion[] = "app-version"; 40 const char kKeyAppVersion[] = "app-version";
55 41
56 const char kKeyCpu[] = "cpu"; 42 const char* GetValueSessionState(ConnectionToHost::State state) {
57
58 } // namespace
59
60 ServerLogEntry::ServerLogEntry() {
61 }
62
63 ServerLogEntry::~ServerLogEntry() {
64 }
65
66 // static
67 scoped_ptr<buzz::XmlElement> ServerLogEntry::MakeStanza() {
68 return scoped_ptr<buzz::XmlElement>(
69 new XmlElement(QName(kChromotingXmlNamespace, kLogCommand)));
70 }
71
72 // static
73 scoped_ptr<ServerLogEntry> ServerLogEntry::MakeForSessionStateChange(
74 protocol::ConnectionToHost::State state,
75 protocol::ErrorCode error) {
76 scoped_ptr<ServerLogEntry> entry(new ServerLogEntry());
77 entry->Set(kKeyRole, kValueRoleClient);
78 entry->Set(kKeyEventName, kValueEventNameSessionState);
79
80 entry->Set(kKeySessionState, GetValueSessionState(state));
81 if (error != protocol::OK) {
82 entry->Set("connection-error", GetValueError(error));
83 }
84
85 return entry.Pass();
86 }
87
88 // static
89 scoped_ptr<ServerLogEntry> ServerLogEntry::MakeForStatistics(
90 ChromotingStats* statistics) {
91 scoped_ptr<ServerLogEntry> entry(new ServerLogEntry());
92 entry->Set(kKeyRole, kValueRoleClient);
93 entry->Set(kKeyEventName, kValueEventNameStatistics);
94
95 entry->Set("video-bandwidth",
96 StringPrintf("%.2f", statistics->video_bandwidth()->Rate()));
97 entry->Set("capture-latency",
98 StringPrintf("%.2f", statistics->video_capture_ms()->Average()));
99 entry->Set("encode-latency",
100 StringPrintf("%.2f", statistics->video_encode_ms()->Average()));
101 entry->Set("decode-latency",
102 StringPrintf("%.2f", statistics->video_decode_ms()->Average()));
103 entry->Set("render-latency",
104 StringPrintf("%.2f", statistics->video_frame_rate()->Rate()));
105 entry->Set("roundtrip-latency",
106 StringPrintf("%.2f", statistics->round_trip_ms()->Average()));
107
108 return entry.Pass();
109 }
110
111 // static
112 scoped_ptr<ServerLogEntry> ServerLogEntry::MakeForSessionIdOld(
113 const std::string& session_id) {
114 scoped_ptr<ServerLogEntry> entry(new ServerLogEntry());
115 entry->Set(kKeyRole, kValueRoleClient);
116 entry->Set(kKeyEventName, kValueEventNameSessionIdOld);
117 entry->AddSessionId(session_id);
118 return entry.Pass();
119 }
120
121 // static
122 scoped_ptr<ServerLogEntry> ServerLogEntry::MakeForSessionIdNew(
123 const std::string& session_id) {
124 scoped_ptr<ServerLogEntry> entry(new ServerLogEntry());
125 entry->Set(kKeyRole, kValueRoleClient);
126 entry->Set(kKeyEventName, kValueEventNameSessionIdNew);
127 entry->AddSessionId(session_id);
128 return entry.Pass();
129 }
130
131 void ServerLogEntry::AddClientFields() {
132 Set(kKeyOsName, SysInfo::OperatingSystemName());
133 Set(kKeyOsVersion, SysInfo::OperatingSystemVersion());
134 Set(kKeyAppVersion, STRINGIZE(VERSION));
135 Set(kKeyCpu, SysInfo::OperatingSystemArchitecture());
136 };
137
138 void ServerLogEntry::AddModeField(ServerLogEntry::Mode mode) {
139 Set(kKeyMode, GetValueMode(mode));
140 }
141
142 void ServerLogEntry::AddSessionId(const std::string& session_id) {
143 Set("session-id", session_id);
144 }
145
146 void ServerLogEntry::AddSessionDuration(base::TimeDelta duration) {
147 Set("session-duration", base::Int64ToString(duration.InSeconds()));
148 }
149
150 // static
151 const char* ServerLogEntry::GetValueMode(ServerLogEntry::Mode mode) {
152 switch (mode) {
153 case IT2ME:
154 return kValueModeIt2Me;
155 case ME2ME:
156 return kValueModeMe2Me;
157 default:
158 NOTREACHED();
159 return NULL;
160 }
161 }
162
163 scoped_ptr<XmlElement> ServerLogEntry::ToStanza() const {
164 scoped_ptr<XmlElement> stanza(new XmlElement(QName(
165 kChromotingXmlNamespace, kLogEntry)));
166 ValuesMap::const_iterator iter;
167 for (iter = values_map_.begin(); iter != values_map_.end(); ++iter) {
168 stanza->AddAttr(QName(std::string(), iter->first), iter->second);
169 }
170 return stanza.Pass();
171 }
172
173 // static
174 const char* ServerLogEntry::GetValueSessionState(
175 ConnectionToHost::State state) {
176 switch (state) { 43 switch (state) {
177 // Where possible, these are the same strings that the webapp sends for the 44 // Where possible, these are the same strings that the webapp sends for the
178 // corresponding state - see remoting/webapp/server_log_entry.js. 45 // corresponding state - see remoting/webapp/server_log_entry.js.
179 case ConnectionToHost::INITIALIZING: 46 case ConnectionToHost::INITIALIZING:
180 return "initializing"; 47 return "initializing";
181 case ConnectionToHost::CONNECTING: 48 case ConnectionToHost::CONNECTING:
182 return "connecting"; 49 return "connecting";
183 case ConnectionToHost::AUTHENTICATED: 50 case ConnectionToHost::AUTHENTICATED:
184 return "authenticated"; 51 return "authenticated";
185 case ConnectionToHost::CONNECTED: 52 case ConnectionToHost::CONNECTED:
186 return kValueSessionStateConnected; 53 return kValueSessionStateConnected;
187 case ConnectionToHost::FAILED: 54 case ConnectionToHost::FAILED:
188 return "connection-failed"; 55 return "connection-failed";
189 case ConnectionToHost::CLOSED: 56 case ConnectionToHost::CLOSED:
190 return kValueSessionStateClosed; 57 return kValueSessionStateClosed;
191 default: 58 default:
192 NOTREACHED(); 59 NOTREACHED();
193 return NULL; 60 return NULL;
194 } 61 }
195 } 62 }
196 63
197 // static 64 const char* GetValueError(ErrorCode error) {
198 const char* ServerLogEntry::GetValueError(protocol::ErrorCode error) {
199 switch (error) { 65 switch (error) {
200 // Where possible, these are the same strings that the webapp sends for the 66 // Where possible, these are the same strings that the webapp sends for the
201 // corresponding error - see remoting/webapp/server_log_entry.js. 67 // corresponding error - see remoting/webapp/server_log_entry.js.
202 case protocol::OK: 68 case protocol::OK:
203 return "none"; 69 return "none";
204 case protocol::PEER_IS_OFFLINE: 70 case protocol::PEER_IS_OFFLINE:
205 return "host-is-offline"; 71 return "host-is-offline";
206 case protocol::SESSION_REJECTED: 72 case protocol::SESSION_REJECTED:
207 return "session-rejected"; 73 return "session-rejected";
208 case protocol::INCOMPATIBLE_PROTOCOL: 74 case protocol::INCOMPATIBLE_PROTOCOL:
209 return "incompatible-protocol"; 75 return "incompatible-protocol";
210 case protocol::AUTHENTICATION_FAILED: 76 case protocol::AUTHENTICATION_FAILED:
211 return "authentication-failed"; 77 return "authentication-failed";
212 case protocol::CHANNEL_CONNECTION_ERROR: 78 case protocol::CHANNEL_CONNECTION_ERROR:
213 return "channel-connection-error"; 79 return "channel-connection-error";
214 case protocol::SIGNALING_ERROR: 80 case protocol::SIGNALING_ERROR:
215 return "signaling-error"; 81 return "signaling-error";
216 case protocol::SIGNALING_TIMEOUT: 82 case protocol::SIGNALING_TIMEOUT:
217 return "signaling-timeout"; 83 return "signaling-timeout";
218 case protocol::HOST_OVERLOAD: 84 case protocol::HOST_OVERLOAD:
219 return "host-overload"; 85 return "host-overload";
220 case protocol::UNKNOWN_ERROR: 86 case protocol::UNKNOWN_ERROR:
221 return "unknown-error"; 87 return "unknown-error";
222 default: 88 default:
223 NOTREACHED(); 89 NOTREACHED();
224 return NULL; 90 return NULL;
225 } 91 }
226 } 92 }
227 93
228 void ServerLogEntry::AddEventName(const std::string& event_name) { 94 } // namespace
229 Set("event-name", event_name); 95
96 scoped_ptr<ServerLogEntry> MakeLogEntryForSessionStateChange(
97 ConnectionToHost::State state,
98 ErrorCode error) {
99 scoped_ptr<ServerLogEntry> entry(new ServerLogEntry());
100 entry->AddRoleField(kValueRoleClient);
101 entry->AddEventNameField(kValueEventNameSessionState);
102
103 entry->Set(kKeySessionState, GetValueSessionState(state));
104 if (error != protocol::OK) {
105 entry->Set(kKeyConnectionError, GetValueError(error));
106 }
107
108 return entry.Pass();
230 } 109 }
231 110
232 void ServerLogEntry::Set(const std::string& key, const std::string& value) { 111 scoped_ptr<ServerLogEntry> MakeLogEntryForStatistics(
233 values_map_[key] = value; 112 ChromotingStats* statistics) {
113 scoped_ptr<ServerLogEntry> entry(new ServerLogEntry());
114 entry->AddRoleField(kValueRoleClient);
115 entry->AddEventNameField(kValueEventNameStatistics);
116
117 entry->Set("video-bandwidth",
118 StringPrintf("%.2f", statistics->video_bandwidth()->Rate()));
119 entry->Set("capture-latency",
120 StringPrintf("%.2f", statistics->video_capture_ms()->Average()));
121 entry->Set("encode-latency",
122 StringPrintf("%.2f", statistics->video_encode_ms()->Average()));
123 entry->Set("decode-latency",
124 StringPrintf("%.2f", statistics->video_decode_ms()->Average()));
125 entry->Set("render-latency",
126 StringPrintf("%.2f", statistics->video_frame_rate()->Rate()));
127 entry->Set("roundtrip-latency",
128 StringPrintf("%.2f", statistics->round_trip_ms()->Average()));
129
130 return entry.Pass();
234 } 131 }
235 132
236 } // namespace client 133 scoped_ptr<ServerLogEntry> MakeLogEntryForSessionIdOld(
134 const std::string& session_id) {
135 scoped_ptr<ServerLogEntry> entry(new ServerLogEntry());
136 entry->AddRoleField(kValueRoleClient);
137 entry->AddEventNameField(kValueEventNameSessionIdOld);
138 AddSessionIdToLogEntry(entry.get(), session_id);
139 return entry.Pass();
140 }
141
142 scoped_ptr<ServerLogEntry> MakeLogEntryForSessionIdNew(
143 const std::string& session_id) {
144 scoped_ptr<ServerLogEntry> entry(new ServerLogEntry());
145 entry->AddRoleField(kValueRoleClient);
146 entry->AddEventNameField(kValueEventNameSessionIdNew);
147 AddSessionIdToLogEntry(entry.get(), session_id);
148 return entry.Pass();
149 }
150
151 void AddClientFieldsToLogEntry(ServerLogEntry* entry) {
152 entry->Set(kKeyOsName, SysInfo::OperatingSystemName());
153 entry->Set(kKeyOsVersion, SysInfo::OperatingSystemVersion());
154 entry->Set(kKeyAppVersion, STRINGIZE(VERSION));
155 entry->AddCpuField();
156 }
157
158 void AddSessionIdToLogEntry(ServerLogEntry* entry, const std::string& id) {
159 entry->Set(kKeySessionId, id);
160 }
161
162 void AddSessionDurationToLogEntry(ServerLogEntry* entry,
163 base::TimeDelta duration) {
164 entry->Set(kKeySessionDuration, base::Int64ToString(duration.InSeconds()));
165 }
237 166
238 } // namespace remoting 167 } // namespace remoting
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698