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/chrome_version_info.h"
12 #include "chrome/common/safe_browsing/csd.pb.h"
14 namespace safe_browsing
{
16 // Populates |process| with platform-specific data related to the chrome browser
18 void CollectPlatformProcessData(
19 ClientIncidentReport_EnvironmentData_Process
* process
);
23 ClientIncidentReport_EnvironmentData_Process_Channel
MapChannelToProtobuf(
24 chrome::VersionInfo::Channel channel
) {
25 typedef chrome::VersionInfo VersionInfo
;
26 typedef ClientIncidentReport_EnvironmentData_Process Process
;
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
;
37 return Process::CHANNEL_UNKNOWN
;
41 // Populates |process| with data related to the chrome browser process.
42 void CollectProcessData(ClientIncidentReport_EnvironmentData_Process
* process
) {
43 chrome::VersionInfo version_info
;
44 // TODO(grt): Move this logic into VersionInfo (it also appears in
45 // ChromeMetricsServiceClient).
46 std::string
version(version_info
.Version());
47 #if defined(ARCH_CPU_64_BITS)
49 #endif // defined(ARCH_CPU_64_BITS)
50 if (!version_info
.IsOfficialBuild())
52 process
->set_version(version
);
54 process
->set_chrome_update_channel(
55 MapChannelToProtobuf(chrome::VersionInfo::GetChannel()));
57 CollectPlatformProcessData(process
);
62 void CollectEnvironmentData(ClientIncidentReport_EnvironmentData
* data
) {
65 ClientIncidentReport_EnvironmentData_OS
* os
= data
->mutable_os();
66 os
->set_os_name(base::SysInfo::OperatingSystemName());
67 os
->set_os_version(base::SysInfo::OperatingSystemVersion());
73 ClientIncidentReport_EnvironmentData_Machine
* machine
=
74 data
->mutable_machine();
75 machine
->set_cpu_architecture(base::SysInfo::OperatingSystemArchitecture());
76 machine
->set_cpu_vendor(cpu_info
.vendor_name());
77 machine
->set_cpuid(cpu_info
.signature());
81 CollectProcessData(data
->mutable_process());
85 void CollectPlatformProcessData(
86 ClientIncidentReport_EnvironmentData_Process
* process
) {
87 // Empty implementation for platforms that do not (yet) have their own
92 } // namespace safe_browsing