| OLD | NEW |
| (Empty) |
| 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/safe_browsing/environment_data_collection.h" | |
| 6 | |
| 7 #include <string> | |
| 8 | |
| 9 #include "base/cpu.h" | |
| 10 #include "base/sys_info.h" | |
| 11 #include "chrome/common/chrome_version_info.h" | |
| 12 #include "chrome/common/safe_browsing/csd.pb.h" | |
| 13 | |
| 14 namespace safe_browsing { | |
| 15 | |
| 16 // Populates |process| with platform-specific data related to the chrome browser | |
| 17 // process. | |
| 18 void CollectPlatformProcessData( | |
| 19 ClientIncidentReport_EnvironmentData_Process* process); | |
| 20 | |
| 21 namespace { | |
| 22 | |
| 23 ClientIncidentReport_EnvironmentData_Process_Channel MapChannelToProtobuf( | |
| 24 chrome::VersionInfo::Channel channel) { | |
| 25 typedef chrome::VersionInfo VersionInfo; | |
| 26 typedef ClientIncidentReport_EnvironmentData_Process Process; | |
| 27 switch (channel) { | |
| 28 case VersionInfo::CHANNEL_CANARY: | |
| 29 return Process::CHANNEL_CANARY; | |
| 30 case VersionInfo::CHANNEL_DEV: | |
| 31 return Process::CHANNEL_DEV; | |
| 32 case VersionInfo::CHANNEL_BETA: | |
| 33 return Process::CHANNEL_BETA; | |
| 34 case VersionInfo::CHANNEL_STABLE: | |
| 35 return Process::CHANNEL_STABLE; | |
| 36 default: | |
| 37 return Process::CHANNEL_UNKNOWN; | |
| 38 } | |
| 39 } | |
| 40 | |
| 41 // Populates |process| with data related to the chrome browser process. | |
| 42 void CollectProcessData(ClientIncidentReport_EnvironmentData_Process* process) { | |
| 43 chrome::VersionInfo version_info; | |
| 44 if (version_info.is_valid()) { | |
| 45 // TODO(grt): Move this logic into VersionInfo (it also appears in | |
| 46 // ChromeMetricsServiceClient). | |
| 47 std::string version(version_info.Version()); | |
| 48 #if defined(ARCH_CPU_64_BITS) | |
| 49 version += "-64"; | |
| 50 #endif // defined(ARCH_CPU_64_BITS) | |
| 51 if (!version_info.IsOfficialBuild()) | |
| 52 version += "-devel"; | |
| 53 process->set_version(version); | |
| 54 } | |
| 55 | |
| 56 process->set_chrome_update_channel( | |
| 57 MapChannelToProtobuf(chrome::VersionInfo::GetChannel())); | |
| 58 | |
| 59 CollectPlatformProcessData(process); | |
| 60 } | |
| 61 | |
| 62 } // namespace | |
| 63 | |
| 64 void CollectEnvironmentData(ClientIncidentReport_EnvironmentData* data) { | |
| 65 // OS | |
| 66 { | |
| 67 ClientIncidentReport_EnvironmentData_OS* os = data->mutable_os(); | |
| 68 os->set_os_name(base::SysInfo::OperatingSystemName()); | |
| 69 os->set_os_version(base::SysInfo::OperatingSystemVersion()); | |
| 70 } | |
| 71 | |
| 72 // Machine | |
| 73 { | |
| 74 base::CPU cpu_info; | |
| 75 ClientIncidentReport_EnvironmentData_Machine* machine = | |
| 76 data->mutable_machine(); | |
| 77 machine->set_cpu_architecture(base::SysInfo::OperatingSystemArchitecture()); | |
| 78 machine->set_cpu_vendor(cpu_info.vendor_name()); | |
| 79 machine->set_cpuid(cpu_info.signature()); | |
| 80 } | |
| 81 | |
| 82 // Process | |
| 83 CollectProcessData(data->mutable_process()); | |
| 84 } | |
| 85 | |
| 86 #if !defined(OS_WIN) | |
| 87 void CollectPlatformProcessData( | |
| 88 ClientIncidentReport_EnvironmentData_Process* process) { | |
| 89 // Empty implementation for platforms that do not (yet) have their own | |
| 90 // implementations. | |
| 91 } | |
| 92 #endif | |
| 93 | |
| 94 } // namespace safe_browsing | |
| OLD | NEW |