Refactor WebsiteSettings to operate on a SecurityInfo
[chromium-blink-merge.git] / chrome / browser / safe_browsing / incident_reporting / environment_data_collection.cc
blobf207502a3ac742370b8253646d1c654def211c02
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"
7 #include <string>
9 #include "base/cpu.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
18 // process.
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);
25 namespace {
27 ClientIncidentReport_EnvironmentData_Process_Channel MapChannelToProtobuf(
28 version_info::Channel channel) {
29 typedef ClientIncidentReport_EnvironmentData_Process Process;
30 switch (channel) {
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;
39 default:
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)
50 version += "-64";
51 #endif // defined(ARCH_CPU_64_BITS)
52 if (!version_info::IsOfficialBuild())
53 version += "-devel";
54 process->set_version(version);
56 process->set_chrome_update_channel(
57 MapChannelToProtobuf(chrome::GetChannel()));
59 CollectPlatformProcessData(process);
62 } // namespace
64 void CollectEnvironmentData(ClientIncidentReport_EnvironmentData* data) {
65 // OS
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);
73 // Machine
75 base::CPU cpu_info;
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());
83 // Process
84 CollectProcessData(data->mutable_process());
87 #if !defined(OS_WIN)
88 void CollectPlatformProcessData(
89 ClientIncidentReport_EnvironmentData_Process* process) {
90 // Empty implementation for platforms that do not (yet) have their own
91 // implementations.
94 void CollectPlatformOSData(ClientIncidentReport_EnvironmentData_OS* os_data) {
95 // Empty implementation for platforms that do not (yet) have their own
96 // implementations.
98 #endif
100 } // namespace safe_browsing