ExtensionInstallDialogView: fix scrolling behavior on Views (Win,Linux)
[chromium-blink-merge.git] / remoting / client / server_log_entry_client.cc
blob2f78150205d19efd08c5374c4d63bbb7056346bc
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
3 // found in the LICENSE file.
5 #include "remoting/client/server_log_entry_client.h"
7 #include "base/logging.h"
8 #include "base/strings/string_number_conversions.h"
9 #include "base/strings/stringize_macros.h"
10 #include "base/strings/stringprintf.h"
11 #include "base/sys_info.h"
12 #include "remoting/client/chromoting_stats.h"
13 #include "remoting/signaling/server_log_entry.h"
15 using base::StringPrintf;
16 using base::SysInfo;
17 using remoting::protocol::ConnectionToHost;
18 using remoting::protocol::ErrorCode;
20 namespace remoting {
22 namespace {
23 const char kValueRoleClient[] = "client";
25 const char kValueEventNameSessionState[] = "session-state";
26 const char kValueEventNameStatistics[] = "connection-statistics";
27 const char kValueEventNameSessionIdOld[] = "session-id-old";
28 const char kValueEventNameSessionIdNew[] = "session-id-new";
30 const char kKeySessionId[] = "session-id";
31 const char kKeySessionDuration[] = "session-duration";
33 const char kKeySessionState[] = "session-state";
34 const char kKeyConnectionError[] = "connection-error";
35 const char kValueSessionStateConnected[] = "connected";
36 const char kValueSessionStateClosed[] = "closed";
38 const char kKeyOsName[] = "os-name";
39 const char kKeyOsVersion[] = "os-version";
40 const char kKeyAppVersion[] = "app-version";
42 const char* GetValueSessionState(ConnectionToHost::State state) {
43 switch (state) {
44 // Where possible, these are the same strings that the webapp sends for the
45 // corresponding state - see remoting/webapp/server_log_entry.js.
46 case ConnectionToHost::INITIALIZING:
47 return "initializing";
48 case ConnectionToHost::CONNECTING:
49 return "connecting";
50 case ConnectionToHost::AUTHENTICATED:
51 return "authenticated";
52 case ConnectionToHost::CONNECTED:
53 return kValueSessionStateConnected;
54 case ConnectionToHost::FAILED:
55 return "connection-failed";
56 case ConnectionToHost::CLOSED:
57 return kValueSessionStateClosed;
58 default:
59 NOTREACHED();
60 return nullptr;
64 const char* GetValueError(ErrorCode error) {
65 switch (error) {
66 // Where possible, these are the same strings that the webapp sends for the
67 // corresponding error - see remoting/webapp/crd/js/server_log_entry.js.
68 case protocol::OK:
69 return "none";
70 case protocol::PEER_IS_OFFLINE:
71 return "host-is-offline";
72 case protocol::SESSION_REJECTED:
73 return "session-rejected";
74 case protocol::INCOMPATIBLE_PROTOCOL:
75 return "incompatible-protocol";
76 case protocol::AUTHENTICATION_FAILED:
77 return "authentication-failed";
78 case protocol::CHANNEL_CONNECTION_ERROR:
79 return "p2p-failure";
80 case protocol::SIGNALING_ERROR:
81 return "network-failure";
82 case protocol::SIGNALING_TIMEOUT:
83 return "network-failure";
84 case protocol::HOST_OVERLOAD:
85 return "host-overload";
86 case protocol::UNKNOWN_ERROR:
87 return "unknown-error";
88 default:
89 NOTREACHED();
90 return nullptr;
94 } // namespace
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);
103 entry->Set(kKeySessionState, GetValueSessionState(state));
104 if (error != protocol::OK) {
105 entry->Set(kKeyConnectionError, GetValueError(error));
108 return entry.Pass();
111 scoped_ptr<ServerLogEntry> MakeLogEntryForStatistics(
112 ChromotingStats* statistics) {
113 scoped_ptr<ServerLogEntry> entry(new ServerLogEntry());
114 entry->AddRoleField(kValueRoleClient);
115 entry->AddEventNameField(kValueEventNameStatistics);
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()));
130 return entry.Pass();
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();
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();
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();
158 void AddSessionIdToLogEntry(ServerLogEntry* entry, const std::string& id) {
159 entry->Set(kKeySessionId, id);
162 void AddSessionDurationToLogEntry(ServerLogEntry* entry,
163 base::TimeDelta duration) {
164 entry->Set(kKeySessionDuration, base::Int64ToString(duration.InSeconds()));
167 } // namespace remoting