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 "chrome/browser/policy/device_management_service_configuration.h" 6 7#include "base/basictypes.h" 8#include "base/logging.h" 9#include "base/strings/stringprintf.h" 10#include "base/sys_info.h" 11#include "chrome/common/chrome_version_info.h" 12#include "components/policy/core/browser/browser_policy_connector.h" 13 14#if defined(OS_CHROMEOS) 15#include "chromeos/system/statistics_provider.h" 16#endif 17 18namespace policy { 19 20DeviceManagementServiceConfiguration::DeviceManagementServiceConfiguration( 21 const std::string& server_url) 22 : server_url_(server_url) { 23} 24 25DeviceManagementServiceConfiguration::~DeviceManagementServiceConfiguration() { 26} 27 28std::string DeviceManagementServiceConfiguration::GetServerUrl() { 29 return server_url_; 30} 31 32std::string DeviceManagementServiceConfiguration::GetAgentParameter() { 33 chrome::VersionInfo version_info; 34 return base::StringPrintf("%s %s(%s)", 35 version_info.Name().c_str(), 36 version_info.Version().c_str(), 37 version_info.LastChange().c_str()); 38} 39 40std::string DeviceManagementServiceConfiguration::GetPlatformParameter() { 41 std::string os_name = base::SysInfo::OperatingSystemName(); 42 std::string os_hardware = base::SysInfo::OperatingSystemArchitecture(); 43 44#if defined(OS_CHROMEOS) 45 chromeos::system::StatisticsProvider* provider = 46 chromeos::system::StatisticsProvider::GetInstance(); 47 48 std::string hwclass; 49 if (!provider->GetMachineStatistic(chromeos::system::kHardwareClassKey, 50 &hwclass)) { 51 LOG(ERROR) << "Failed to get machine information"; 52 } 53 os_name += ",CrOS," + base::SysInfo::GetLsbReleaseBoard(); 54 os_hardware += "," + hwclass; 55#endif 56 57 std::string os_version("-"); 58#if defined(OS_WIN) || defined(OS_MACOSX) || defined(OS_CHROMEOS) 59 int32 os_major_version = 0; 60 int32 os_minor_version = 0; 61 int32 os_bugfix_version = 0; 62 base::SysInfo::OperatingSystemVersionNumbers(&os_major_version, 63 &os_minor_version, 64 &os_bugfix_version); 65 os_version = base::StringPrintf("%d.%d.%d", 66 os_major_version, 67 os_minor_version, 68 os_bugfix_version); 69#endif 70 71 return base::StringPrintf( 72 "%s|%s|%s", os_name.c_str(), os_hardware.c_str(), os_version.c_str()); 73} 74 75} // namespace policy 76