ozone: evdev: Sync caps lock LED state to evdev
[chromium-blink-merge.git] / chrome / browser / safe_browsing / incident_reporting / environment_data_collection.cc
blob0075ce010dd25eb78bd45aa76718167d747e5a47
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/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
17 // process.
18 void CollectPlatformProcessData(
19 ClientIncidentReport_EnvironmentData_Process* process);
21 namespace {
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;
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)
48 version += "-64";
49 #endif // defined(ARCH_CPU_64_BITS)
50 if (!version_info.IsOfficialBuild())
51 version += "-devel";
52 process->set_version(version);
54 process->set_chrome_update_channel(
55 MapChannelToProtobuf(chrome::VersionInfo::GetChannel()));
57 CollectPlatformProcessData(process);
60 } // namespace
62 void CollectEnvironmentData(ClientIncidentReport_EnvironmentData* data) {
63 // OS
65 ClientIncidentReport_EnvironmentData_OS* os = data->mutable_os();
66 os->set_os_name(base::SysInfo::OperatingSystemName());
67 os->set_os_version(base::SysInfo::OperatingSystemVersion());
70 // Machine
72 base::CPU cpu_info;
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());
80 // Process
81 CollectProcessData(data->mutable_process());
84 #if !defined(OS_WIN)
85 void CollectPlatformProcessData(
86 ClientIncidentReport_EnvironmentData_Process* process) {
87 // Empty implementation for platforms that do not (yet) have their own
88 // implementations.
90 #endif
92 } // namespace safe_browsing