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

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: Move ServerLogEntry to jingle_glue 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/jingle_glue/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;
25 18
26 namespace remoting { 19 namespace remoting {
27 20
28 namespace client { 21 namespace {
22 const char kValueRoleClient[] = "client";
29 23
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"; 24 const char kValueEventNameSessionState[] = "session-state";
37 const char kValueEventNameStatistics[] = "connection-statistics"; 25 const char kValueEventNameStatistics[] = "connection-statistics";
38 const char kValueEventNameSessionIdOld[] = "session-id-old"; 26 const char kValueEventNameSessionIdOld[] = "session-id-old";
39 const char kValueEventNameSessionIdNew[] = "session-id-new"; 27 const char kValueEventNameSessionIdNew[] = "session-id-new";
40 28
41 const char kKeyRole[] = "role"; 29 const char kKeySessionId[] = "session-id";
42 const char kValueRoleClient[] = "client"; 30 const char kKeySessionDuration[] = "session-duration";
43
44 const char kKeyMode[] = "mode";
45 const char kValueModeIt2Me[] = "it2me";
46 const char kValueModeMe2Me[] = "me2me";
47 31
48 const char kKeySessionState[] = "session-state"; 32 const char kKeySessionState[] = "session-state";
33 const char kKeyConnectionError[] = "connection-error";
49 const char kValueSessionStateConnected[] = "connected"; 34 const char kValueSessionStateConnected[] = "connected";
50 const char kValueSessionStateClosed[] = "closed"; 35 const char kValueSessionStateClosed[] = "closed";
51 36
52 const char kKeyOsName[] = "os-name"; 37 const char kKeyOsName[] = "os-name";
53 const char kKeyOsVersion[] = "os-version"; 38 const char kKeyOsVersion[] = "os-version";
54 const char kKeyAppVersion[] = "app-version"; 39 const char kKeyAppVersion[] = "app-version";
55 40
56 const char kKeyCpu[] = "cpu"; 41 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) { 42 switch (state) {
177 // Where possible, these are the same strings that the webapp sends for the 43 // Where possible, these are the same strings that the webapp sends for the
178 // corresponding state - see remoting/webapp/server_log_entry.js. 44 // corresponding state - see remoting/webapp/server_log_entry.js.
179 case ConnectionToHost::INITIALIZING: 45 case ConnectionToHost::INITIALIZING:
180 return "initializing"; 46 return "initializing";
181 case ConnectionToHost::CONNECTING: 47 case ConnectionToHost::CONNECTING:
182 return "connecting"; 48 return "connecting";
183 case ConnectionToHost::AUTHENTICATED: 49 case ConnectionToHost::AUTHENTICATED:
184 return "authenticated"; 50 return "authenticated";
185 case ConnectionToHost::CONNECTED: 51 case ConnectionToHost::CONNECTED:
186 return kValueSessionStateConnected; 52 return kValueSessionStateConnected;
187 case ConnectionToHost::FAILED: 53 case ConnectionToHost::FAILED:
188 return "connection-failed"; 54 return "connection-failed";
189 case ConnectionToHost::CLOSED: 55 case ConnectionToHost::CLOSED:
190 return kValueSessionStateClosed; 56 return kValueSessionStateClosed;
191 default: 57 default:
192 NOTREACHED(); 58 NOTREACHED();
193 return NULL; 59 return NULL;
194 } 60 }
195 } 61 }
196 62
197 // static 63 const char* GetValueError(ErrorCode error) {
198 const char* ServerLogEntry::GetValueError(protocol::ErrorCode error) {
199 switch (error) { 64 switch (error) {
200 // Where possible, these are the same strings that the webapp sends for the 65 // Where possible, these are the same strings that the webapp sends for the
201 // corresponding error - see remoting/webapp/server_log_entry.js. 66 // corresponding error - see remoting/webapp/server_log_entry.js.
202 case protocol::OK: 67 case protocol::OK:
203 return "none"; 68 return "none";
204 case protocol::PEER_IS_OFFLINE: 69 case protocol::PEER_IS_OFFLINE:
205 return "host-is-offline"; 70 return "host-is-offline";
206 case protocol::SESSION_REJECTED: 71 case protocol::SESSION_REJECTED:
207 return "session-rejected"; 72 return "session-rejected";
208 case protocol::INCOMPATIBLE_PROTOCOL: 73 case protocol::INCOMPATIBLE_PROTOCOL:
209 return "incompatible-protocol"; 74 return "incompatible-protocol";
210 case protocol::AUTHENTICATION_FAILED: 75 case protocol::AUTHENTICATION_FAILED:
211 return "authentication-failed"; 76 return "authentication-failed";
212 case protocol::CHANNEL_CONNECTION_ERROR: 77 case protocol::CHANNEL_CONNECTION_ERROR:
213 return "channel-connection-error"; 78 return "channel-connection-error";
214 case protocol::SIGNALING_ERROR: 79 case protocol::SIGNALING_ERROR:
215 return "signaling-error"; 80 return "signaling-error";
216 case protocol::SIGNALING_TIMEOUT: 81 case protocol::SIGNALING_TIMEOUT:
217 return "signaling-timeout"; 82 return "signaling-timeout";
218 case protocol::HOST_OVERLOAD: 83 case protocol::HOST_OVERLOAD:
219 return "host-overload"; 84 return "host-overload";
220 case protocol::UNKNOWN_ERROR: 85 case protocol::UNKNOWN_ERROR:
221 return "unknown-error"; 86 return "unknown-error";
222 default: 87 default:
223 NOTREACHED(); 88 NOTREACHED();
224 return NULL; 89 return NULL;
225 } 90 }
226 } 91 }
227 92
228 void ServerLogEntry::AddEventName(const std::string& event_name) { 93 } // namespace
229 Set("event-name", event_name); 94
95 scoped_ptr<ServerLogEntry> MakeLogEntryForSessionStateChange(
96 ConnectionToHost::State state,
97 ErrorCode error) {
98 scoped_ptr<ServerLogEntry> entry(new ServerLogEntry());
99 entry->AddRoleField(kValueRoleClient);
100 entry->AddEventNameField(kValueEventNameSessionState);
101
102 entry->Set(kKeySessionState, GetValueSessionState(state));
103 if (error != protocol::OK) {
104 entry->Set(kKeyConnectionError, GetValueError(error));
105 }
106
107 return entry.Pass();
230 } 108 }
231 109
232 void ServerLogEntry::Set(const std::string& key, const std::string& value) { 110 scoped_ptr<ServerLogEntry> MakeLogEntryForStatistics(
233 values_map_[key] = value; 111 ChromotingStats* statistics) {
112 scoped_ptr<ServerLogEntry> entry(new ServerLogEntry());
113 entry->AddRoleField(kValueRoleClient);
114 entry->AddEventNameField(kValueEventNameStatistics);
115
116 entry->Set("video-bandwidth",
117 StringPrintf("%.2f", statistics->video_bandwidth()->Rate()));
118 entry->Set("capture-latency",
119 StringPrintf("%.2f", statistics->video_capture_ms()->Average()));
120 entry->Set("encode-latency",
121 StringPrintf("%.2f", statistics->video_encode_ms()->Average()));
122 entry->Set("decode-latency",
123 StringPrintf("%.2f", statistics->video_decode_ms()->Average()));
124 entry->Set("render-latency",
125 StringPrintf("%.2f", statistics->video_frame_rate()->Rate()));
126 entry->Set("roundtrip-latency",
127 StringPrintf("%.2f", statistics->round_trip_ms()->Average()));
128
129 return entry.Pass();
234 } 130 }
235 131
236 } // namespace client 132 scoped_ptr<ServerLogEntry> MakeLogEntryForSessionIdOld(
133 const std::string& session_id) {
134 scoped_ptr<ServerLogEntry> entry(new ServerLogEntry());
135 entry->AddRoleField(kValueRoleClient);
136 entry->AddEventNameField(kValueEventNameSessionIdOld);
137 AddSessionIdToLogEntry(entry.get(), session_id);
138 return entry.Pass();
139 }
140
141 scoped_ptr<ServerLogEntry> MakeLogEntryForSessionIdNew(
142 const std::string& session_id) {
143 scoped_ptr<ServerLogEntry> entry(new ServerLogEntry());
144 entry->AddRoleField(kValueRoleClient);
145 entry->AddEventNameField(kValueEventNameSessionIdNew);
146 AddSessionIdToLogEntry(entry.get(), session_id);
147 return entry.Pass();
148 }
149
150 void AddClientFieldsToLogEntry(ServerLogEntry* entry) {
151 entry->Set(kKeyOsName, SysInfo::OperatingSystemName());
152 entry->Set(kKeyOsVersion, SysInfo::OperatingSystemVersion());
153 entry->Set(kKeyAppVersion, STRINGIZE(VERSION));
154 entry->AddCpuField();
155 }
156
157 void AddSessionIdToLogEntry(ServerLogEntry* entry, const std::string& id) {
158 entry->Set(kKeySessionId, id);
159 }
160
161 void AddSessionDurationToLogEntry(ServerLogEntry* entry,
162 base::TimeDelta duration) {
163 entry->Set(kKeySessionDuration, base::Int64ToString(duration.InSeconds()));
164 }
237 165
238 } // namespace remoting 166 } // namespace remoting
OLDNEW
« no previous file with comments | « remoting/client/server_log_entry_client.h ('k') | remoting/client/server_log_entry_client_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698