Skia roll f73c237291b:8d84c995319
[chromium-blink-merge.git] / remoting / host / server_log_entry_host.cc
blobdc240f5de9061a0c9ac6840c06772129dbb273ae
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/host/server_log_entry_host.h"
7 #include "base/strings/stringize_macros.h"
8 #include "base/sys_info.h"
9 #include "remoting/signaling/server_log_entry.h"
11 using base::SysInfo;
13 namespace remoting {
15 namespace {
16 const char kValueEventNameSessionState[] = "session-state";
17 const char kValueEventNameHeartbeat[] = "heartbeat";
18 const char kValueEventNameHostStatus[] = "host-status";
20 const char kValueRoleHost[] = "host";
22 const char kKeySessionState[] = "session-state";
23 const char kValueSessionStateConnected[] = "connected";
24 const char kValueSessionStateClosed[] = "closed";
26 const char kStatusName[] = "status";
27 const char kExitCodeName[] = "exit-code";
29 const char kKeyOsName[] = "os-name";
31 #if defined(OS_WIN) || defined(OS_MACOSX) || defined(OS_CHROMEOS)
32 const char kKeyOsVersion[] = "os-version";
33 #endif
35 const char kKeyHostVersion[] = "host-version";
37 const char kKeyConnectionType[] = "connection-type";
39 const char* GetValueSessionState(bool connected) {
40 return connected ? kValueSessionStateConnected : kValueSessionStateClosed;
43 } // namespace
45 scoped_ptr<ServerLogEntry> MakeLogEntryForSessionStateChange(
46 bool connected) {
47 scoped_ptr<ServerLogEntry> entry(new ServerLogEntry());
48 entry->AddRoleField(kValueRoleHost);
49 entry->AddEventNameField(kValueEventNameSessionState);
50 entry->Set(kKeySessionState, GetValueSessionState(connected));
51 return entry.Pass();
54 scoped_ptr<ServerLogEntry> MakeLogEntryForHeartbeat() {
55 scoped_ptr<ServerLogEntry> entry(new ServerLogEntry());
56 entry->AddRoleField(kValueRoleHost);
57 entry->AddEventNameField(kValueEventNameHeartbeat);
58 return entry.Pass();
61 // static
62 scoped_ptr<ServerLogEntry> MakeLogEntryForHostStatus(
63 HostStatusSender::HostStatus host_status, HostExitCodes exit_code) {
64 scoped_ptr<ServerLogEntry> entry(new ServerLogEntry());
65 entry->AddRoleField(kValueRoleHost);
66 entry->AddEventNameField(kValueEventNameHostStatus);
67 entry->Set(kStatusName, HostStatusSender::HostStatusToString(host_status));
68 if (host_status == HostStatusSender::OFFLINE)
69 entry->Set(kExitCodeName, ExitCodeToString(exit_code));
70 return entry.Pass();
73 void AddHostFieldsToLogEntry(ServerLogEntry* entry) {
74 #if defined(OS_WIN)
75 entry->Set(kKeyOsName, "Windows");
76 #elif defined(OS_MACOSX)
77 entry->Set(kKeyOsName, "Mac");
78 #elif defined(OS_CHROMEOS)
79 entry->Set(kKeyOsName, "ChromeOS");
80 #elif defined(OS_LINUX)
81 entry->Set(kKeyOsName, "Linux");
82 #endif
84 // SysInfo::OperatingSystemVersionNumbers is only defined for the following
85 // OSes: see base/sys_info_unittest.cc.
86 #if defined(OS_WIN) || defined(OS_MACOSX) || defined(OS_CHROMEOS)
87 std::stringstream os_version;
88 int32 os_major_version = 0;
89 int32 os_minor_version = 0;
90 int32 os_bugfix_version = 0;
91 SysInfo::OperatingSystemVersionNumbers(&os_major_version, &os_minor_version,
92 &os_bugfix_version);
93 os_version << os_major_version << "." << os_minor_version << "."
94 << os_bugfix_version;
95 entry->Set(kKeyOsVersion, os_version.str());
96 #endif
98 entry->Set(kKeyHostVersion, STRINGIZE(VERSION));
99 entry->AddCpuField();
102 void AddConnectionTypeToLogEntry(ServerLogEntry* entry,
103 protocol::TransportRoute::RouteType type) {
104 entry->Set(kKeyConnectionType, protocol::TransportRoute::GetTypeString(type));
107 } // namespace remoting