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 "chrome/browser/safe_browsing/incident_reporting/environment_data_collection.h"
10 #include "base/sys_info.h"
11 #include "chrome/common/channel_info.h"
12 #include "chrome/common/safe_browsing/csd.pb.h"
13 #include "components/version_info/version_info.h"
15 namespace safe_browsing
{
17 // Populates |process| with platform-specific data related to the chrome browser
19 void CollectPlatformProcessData(
20 ClientIncidentReport_EnvironmentData_Process
* process
);
22 // Populates |os_data| with platform-specific data related to the OS.
23 void CollectPlatformOSData(ClientIncidentReport_EnvironmentData_OS
* os_data
);
27 ClientIncidentReport_EnvironmentData_Process_Channel
MapChannelToProtobuf(
28 version_info::Channel channel
) {
29 typedef ClientIncidentReport_EnvironmentData_Process Process
;
31 case version_info::Channel::CANARY
:
32 return Process::CHANNEL_CANARY
;
33 case version_info::Channel::DEV
:
34 return Process::CHANNEL_DEV
;
35 case version_info::Channel::BETA
:
36 return Process::CHANNEL_BETA
;
37 case version_info::Channel::STABLE
:
38 return Process::CHANNEL_STABLE
;
40 return Process::CHANNEL_UNKNOWN
;
44 // Populates |process| with data related to the chrome browser process.
45 void CollectProcessData(ClientIncidentReport_EnvironmentData_Process
* process
) {
46 // TODO(grt): Move this logic into VersionInfo (it also appears in
47 // ChromeMetricsServiceClient).
48 std::string
version(version_info::GetVersionNumber());
49 #if defined(ARCH_CPU_64_BITS)
51 #endif // defined(ARCH_CPU_64_BITS)
52 if (!version_info::IsOfficialBuild())
54 process
->set_version(version
);
56 process
->set_chrome_update_channel(
57 MapChannelToProtobuf(chrome::GetChannel()));
59 CollectPlatformProcessData(process
);
64 void CollectEnvironmentData(ClientIncidentReport_EnvironmentData
* data
) {
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 CollectPlatformOSData(os
);
76 ClientIncidentReport_EnvironmentData_Machine
* machine
=
77 data
->mutable_machine();
78 machine
->set_cpu_architecture(base::SysInfo::OperatingSystemArchitecture());
79 machine
->set_cpu_vendor(cpu_info
.vendor_name());
80 machine
->set_cpuid(cpu_info
.signature());
84 CollectProcessData(data
->mutable_process());
88 void CollectPlatformProcessData(
89 ClientIncidentReport_EnvironmentData_Process
* process
) {
90 // Empty implementation for platforms that do not (yet) have their own
94 void CollectPlatformOSData(ClientIncidentReport_EnvironmentData_OS
* os_data
) {
95 // Empty implementation for platforms that do not (yet) have their own
100 } // namespace safe_browsing