Commit 4f33972f authored by Joe Downing's avatar Joe Downing Committed by Chromium LUCI CQ

Include fqdn hostname for Windows hosts

Change-Id: I4673b4bec0b3f2c0a75ec690124c5f2c02470de7
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2565770Reviewed-by: default avatarJamie Walch <jamiewalch@chromium.org>
Commit-Queue: Joe Downing <joedow@chromium.org>
Cr-Commit-Position: refs/heads/master@{#832029}
parent 54215abe
...@@ -33,6 +33,10 @@ ...@@ -33,6 +33,10 @@
#include "remoting/signaling/signaling_address.h" #include "remoting/signaling/signaling_address.h"
#include "services/network/public/cpp/shared_url_loader_factory.h" #include "services/network/public/cpp/shared_url_loader_factory.h"
#if defined(OS_WIN)
#include "base/strings/utf_string_conversions.h"
#endif
namespace remoting { namespace remoting {
namespace { namespace {
...@@ -105,6 +109,29 @@ const net::BackoffEntry::Policy kBackoffPolicy = { ...@@ -105,6 +109,29 @@ const net::BackoffEntry::Policy kBackoffPolicy = {
false, false,
}; };
std::string GetHostname() {
// TODO(crbug.com/1052397): Revisit the macro expression once build flag
// switch of lacros-chrome is complete.
#if defined(OS_LINUX) || BUILDFLAG(IS_CHROMEOS_LACROS)
return net::GetHostName();
#elif defined(OS_WIN)
wchar_t buffer[MAX_PATH] = {0};
DWORD size = MAX_PATH;
if (!::GetComputerNameExW(ComputerNameDnsFullyQualified, buffer, &size)) {
PLOG(ERROR) << "GetComputerNameExW failed";
return std::string();
}
std::string hostname;
if (!base::UTF16ToUTF8(buffer, size, &hostname)) {
LOG(ERROR) << "Failed to convert from UTF16 to UTF8";
return std::string();
}
return hostname;
#else
return std::string();
#endif
}
} // namespace } // namespace
class HeartbeatSender::HeartbeatClientImpl final class HeartbeatSender::HeartbeatClientImpl final
...@@ -383,15 +410,15 @@ HeartbeatSender::CreateHeartbeatRequest() { ...@@ -383,15 +410,15 @@ HeartbeatSender::CreateHeartbeatRequest() {
heartbeat->set_host_os_version(GetHostOperatingSystemVersion()); heartbeat->set_host_os_version(GetHostOperatingSystemVersion());
heartbeat->set_host_cpu_type(base::SysInfo::OperatingSystemArchitecture()); heartbeat->set_host_cpu_type(base::SysInfo::OperatingSystemArchitecture());
heartbeat->set_is_initial_heartbeat(!initial_heartbeat_sent_); heartbeat->set_is_initial_heartbeat(!initial_heartbeat_sent_);
// Only set the hostname if the user's email is @google.com and they are using
// a Linux OS. // Only set the hostname if the user's email is @google.com.
// TODO(crbug.com/1052397): Revisit the macro expression once build flag switch
// of lacros-chrome is complete.
#if defined(OS_LINUX) || BUILDFLAG(IS_CHROMEOS_LACROS)
if (is_googler_) { if (is_googler_) {
heartbeat->set_hostname(net::GetHostName()); std::string hostname = GetHostname();
if (!hostname.empty()) {
heartbeat->set_hostname(hostname);
}
} }
#endif
return heartbeat; return heartbeat;
} }
......
...@@ -73,17 +73,14 @@ void ValidateHeartbeat(std::unique_ptr<apis::v1::HeartbeatRequest> request, ...@@ -73,17 +73,14 @@ void ValidateHeartbeat(std::unique_ptr<apis::v1::HeartbeatRequest> request,
ASSERT_TRUE(request->has_host_os_name()); ASSERT_TRUE(request->has_host_os_name());
ASSERT_TRUE(request->has_host_cpu_type()); ASSERT_TRUE(request->has_host_cpu_type());
ASSERT_EQ(expected_is_initial_heartbeat, request->is_initial_heartbeat()); ASSERT_EQ(expected_is_initial_heartbeat, request->is_initial_heartbeat());
bool is_linux = false;
// TODO(crbug.com/1052397): Revisit the macro expression once build flag switch // TODO(crbug.com/1052397): Revisit the macro expression once build flag switch
// of lacros-chrome is complete. // of lacros-chrome is complete.
#if defined(OS_LINUX) || BUILDFLAG(IS_CHROMEOS_LACROS) #if defined(OS_WIN) || defined(OS_LINUX) || BUILDFLAG(IS_CHROMEOS_LACROS)
is_linux = true; ASSERT_EQ(is_googler, request->has_hostname());
#else
ASSERT_FALSE(request->has_hostname());
#endif #endif
if (is_googler && is_linux) {
ASSERT_TRUE(request->has_hostname());
} else {
ASSERT_FALSE(request->has_hostname());
}
} }
decltype(auto) DoValidateHeartbeatAndRespondOk( decltype(auto) DoValidateHeartbeatAndRespondOk(
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment