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. 4 5 #include "remoting/host/server_log_entry_host.h" 6 7 #include "base/strings/stringize_macros.h" 8 #include "base/sys_info.h" 9 #include "remoting/signaling/server_log_entry.h" 10 11 using base::SysInfo; 12 13 namespace remoting { 14 15 namespace { 16 const char kValueEventNameSessionState[] = "session-state"; 17 const char kValueEventNameHeartbeat[] = "heartbeat"; 18 const char kValueEventNameHostStatus[] = "host-status"; 19 20 const char kValueRoleHost[] = "host"; 21 22 const char kKeySessionState[] = "session-state"; 23 const char kValueSessionStateConnected[] = "connected"; 24 const char kValueSessionStateClosed[] = "closed"; 25 26 const char kStatusName[] = "status"; 27 const char kExitCodeName[] = "exit-code"; 28 29 const char kKeyOsName[] = "os-name"; 30 31 #if defined(OS_WIN) || defined(OS_MACOSX) || defined(OS_CHROMEOS) 32 const char kKeyOsVersion[] = "os-version"; 33 #endif 34 35 const char kKeyHostVersion[] = "host-version"; 36 37 const char kKeyConnectionType[] = "connection-type"; 38 39 const char* GetValueSessionState(bool connected) { 40 return connected ? kValueSessionStateConnected : kValueSessionStateClosed; 41 } 42 43 } // namespace 44 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(); 52 } 53 54 scoped_ptr<ServerLogEntry> MakeLogEntryForHeartbeat() { 55 scoped_ptr<ServerLogEntry> entry(new ServerLogEntry()); 56 entry->AddRoleField(kValueRoleHost); 57 entry->AddEventNameField(kValueEventNameHeartbeat); 58 return entry.Pass(); 59 } 60 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(); 71 } 72 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 83 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 97 98 entry->Set(kKeyHostVersion, STRINGIZE(VERSION)); 99 entry->AddCpuField(); 100 }; 101 102 void AddConnectionTypeToLogEntry(ServerLogEntry* entry, 103 protocol::TransportRoute::RouteType type) { 104 entry->Set(kKeyConnectionType, protocol::TransportRoute::GetTypeString(type)); 105 } 106 107 } // namespace remoting 108