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
);
24 ClientIncidentReport_EnvironmentData_Process_Channel
MapChannelToProtobuf(
25 version_info::Channel channel
) {
26 typedef ClientIncidentReport_EnvironmentData_Process Process
;
28 case version_info::Channel::CANARY
:
29 return Process::CHANNEL_CANARY
;
30 case version_info::Channel::DEV
:
31 return Process::CHANNEL_DEV
;
32 case version_info::Channel::BETA
:
33 return Process::CHANNEL_BETA
;
34 case version_info::Channel::STABLE
:
35 return Process::CHANNEL_STABLE
;
37 return Process::CHANNEL_UNKNOWN
;
41 // Populates |process| with data related to the chrome browser process.
42 void CollectProcessData(ClientIncidentReport_EnvironmentData_Process
* process
) {
43 // TODO(grt): Move this logic into VersionInfo (it also appears in
44 // ChromeMetricsServiceClient).
45 std::string
version(version_info::GetVersionNumber());
46 #if defined(ARCH_CPU_64_BITS)
48 #endif // defined(ARCH_CPU_64_BITS)
49 if (!version_info::IsOfficialBuild())
51 process
->set_version(version
);
53 process
->set_chrome_update_channel(
54 MapChannelToProtobuf(chrome::GetChannel()));
56 CollectPlatformProcessData(process
);
61 void CollectEnvironmentData(ClientIncidentReport_EnvironmentData
* data
) {
64 ClientIncidentReport_EnvironmentData_OS
* os
= data
->mutable_os();
65 os
->set_os_name(base::SysInfo::OperatingSystemName());
66 os
->set_os_version(base::SysInfo::OperatingSystemVersion());
72 ClientIncidentReport_EnvironmentData_Machine
* machine
=
73 data
->mutable_machine();
74 machine
->set_cpu_architecture(base::SysInfo::OperatingSystemArchitecture());
75 machine
->set_cpu_vendor(cpu_info
.vendor_name());
76 machine
->set_cpuid(cpu_info
.signature());
80 CollectProcessData(data
->mutable_process());
84 void CollectPlatformProcessData(
85 ClientIncidentReport_EnvironmentData_Process
* process
) {
86 // Empty implementation for platforms that do not (yet) have their own
91 } // namespace safe_browsing