Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(376)

Side by Side Diff: chrome/browser/chromeos/policy/device_status_collector.cc

Issue 2736903004: Add sound volume to device attribute reporting (Closed)
Patch Set: Fixed tests (initialize CrasAudioHandler), added sound volume test Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/chromeos/policy/device_status_collector.h" 5 #include "chrome/browser/chromeos/policy/device_status_collector.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <algorithm> 10 #include <algorithm>
(...skipping 25 matching lines...) Expand all
36 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h" 36 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h"
37 #include "chrome/browser/chromeos/policy/device_local_account.h" 37 #include "chrome/browser/chromeos/policy/device_local_account.h"
38 #include "chrome/browser/chromeos/policy/user_cloud_policy_manager_chromeos.h" 38 #include "chrome/browser/chromeos/policy/user_cloud_policy_manager_chromeos.h"
39 #include "chrome/browser/chromeos/policy/user_policy_manager_factory_chromeos.h" 39 #include "chrome/browser/chromeos/policy/user_policy_manager_factory_chromeos.h"
40 #include "chrome/browser/chromeos/profiles/profile_helper.h" 40 #include "chrome/browser/chromeos/profiles/profile_helper.h"
41 #include "chrome/browser/chromeos/settings/cros_settings.h" 41 #include "chrome/browser/chromeos/settings/cros_settings.h"
42 #include "chrome/browser/policy/profile_policy_connector.h" 42 #include "chrome/browser/policy/profile_policy_connector.h"
43 #include "chrome/browser/policy/profile_policy_connector_factory.h" 43 #include "chrome/browser/policy/profile_policy_connector_factory.h"
44 #include "chrome/browser/profiles/profile_manager.h" 44 #include "chrome/browser/profiles/profile_manager.h"
45 #include "chrome/common/pref_names.h" 45 #include "chrome/common/pref_names.h"
46 #include "chromeos/audio/cras_audio_handler.h"
46 #include "chromeos/dbus/dbus_thread_manager.h" 47 #include "chromeos/dbus/dbus_thread_manager.h"
47 #include "chromeos/dbus/update_engine_client.h" 48 #include "chromeos/dbus/update_engine_client.h"
48 #include "chromeos/disks/disk_mount_manager.h" 49 #include "chromeos/disks/disk_mount_manager.h"
49 #include "chromeos/network/device_state.h" 50 #include "chromeos/network/device_state.h"
50 #include "chromeos/network/network_handler.h" 51 #include "chromeos/network/network_handler.h"
51 #include "chromeos/network/network_state.h" 52 #include "chromeos/network/network_state.h"
52 #include "chromeos/network/network_state_handler.h" 53 #include "chromeos/network/network_state_handler.h"
53 #include "chromeos/settings/cros_settings_names.h" 54 #include "chromeos/settings/cros_settings_names.h"
54 #include "chromeos/system/statistics_provider.h" 55 #include "chromeos/system/statistics_provider.h"
55 #include "components/arc/arc_bridge_service.h" 56 #include "components/arc/arc_bridge_service.h"
(...skipping 422 matching lines...) Expand 10 before | Expand all | Expand 10 after
478 users_subscription_ = cros_settings_->AddSettingsObserver( 479 users_subscription_ = cros_settings_->AddSettingsObserver(
479 chromeos::kReportDeviceUsers, callback); 480 chromeos::kReportDeviceUsers, callback);
480 hardware_status_subscription_ = cros_settings_->AddSettingsObserver( 481 hardware_status_subscription_ = cros_settings_->AddSettingsObserver(
481 chromeos::kReportDeviceHardwareStatus, callback); 482 chromeos::kReportDeviceHardwareStatus, callback);
482 session_status_subscription_ = cros_settings_->AddSettingsObserver( 483 session_status_subscription_ = cros_settings_->AddSettingsObserver(
483 chromeos::kReportDeviceSessionStatus, callback); 484 chromeos::kReportDeviceSessionStatus, callback);
484 os_update_status_subscription_ = cros_settings_->AddSettingsObserver( 485 os_update_status_subscription_ = cros_settings_->AddSettingsObserver(
485 chromeos::kReportOsUpdateStatus, callback); 486 chromeos::kReportOsUpdateStatus, callback);
486 running_kiosk_app_subscription_ = cros_settings_->AddSettingsObserver( 487 running_kiosk_app_subscription_ = cros_settings_->AddSettingsObserver(
487 chromeos::kReportRunningKioskApp, callback); 488 chromeos::kReportRunningKioskApp, callback);
489 sound_volume_subscription_ = cros_settings_->AddSettingsObserver(
490 chromeos::kReportSoundVolume, callback);
488 491
489 // Fetch the current values of the policies. 492 // Fetch the current values of the policies.
490 UpdateReportingSettings(); 493 UpdateReportingSettings();
491 494
492 // Get the the OS and firmware version info. 495 // Get the the OS and firmware version info.
493 base::PostTaskAndReplyWithResult( 496 base::PostTaskAndReplyWithResult(
494 content::BrowserThread::GetBlockingPool(), 497 content::BrowserThread::GetBlockingPool(),
495 FROM_HERE, 498 FROM_HERE,
496 base::Bind(&chromeos::version_loader::GetVersion, 499 base::Bind(&chromeos::version_loader::GetVersion,
497 chromeos::version_loader::VERSION_FULL), 500 chromeos::version_loader::VERSION_FULL),
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
551 } 554 }
552 if (!cros_settings_->GetBoolean( 555 if (!cros_settings_->GetBoolean(
553 chromeos::kReportDeviceNetworkInterfaces, 556 chromeos::kReportDeviceNetworkInterfaces,
554 &report_network_interfaces_)) { 557 &report_network_interfaces_)) {
555 report_network_interfaces_ = true; 558 report_network_interfaces_ = true;
556 } 559 }
557 if (!cros_settings_->GetBoolean( 560 if (!cros_settings_->GetBoolean(
558 chromeos::kReportDeviceUsers, &report_users_)) { 561 chromeos::kReportDeviceUsers, &report_users_)) {
559 report_users_ = true; 562 report_users_ = true;
560 } 563 }
564 if (!cros_settings_->GetBoolean(
565 chromeos::kReportSoundVolume, &report_sound_volume_)) {
566 report_sound_volume_ = true;
567 }
561 568
562 const bool already_reporting_hardware_status = report_hardware_status_; 569 const bool already_reporting_hardware_status = report_hardware_status_;
563 if (!cros_settings_->GetBoolean( 570 if (!cros_settings_->GetBoolean(
564 chromeos::kReportDeviceHardwareStatus, &report_hardware_status_)) { 571 chromeos::kReportDeviceHardwareStatus, &report_hardware_status_)) {
565 report_hardware_status_ = true; 572 report_hardware_status_ = true;
566 } 573 }
567 574
568 if (!cros_settings_->GetBoolean(chromeos::kReportDeviceSessionStatus, 575 if (!cros_settings_->GetBoolean(chromeos::kReportDeviceSessionStatus,
569 &report_kiosk_session_status_)) { 576 &report_kiosk_session_status_)) {
570 report_kiosk_session_status_ = true; 577 report_kiosk_session_status_ = true;
(...skipping 404 matching lines...) Expand 10 before | Expand all | Expand 10 after
975 scoped_refptr<GetStatusState> state) { 982 scoped_refptr<GetStatusState> state) {
976 // Sample disk volume info in a background thread. 983 // Sample disk volume info in a background thread.
977 state->SampleVolumeInfo(volume_info_fetcher_); 984 state->SampleVolumeInfo(volume_info_fetcher_);
978 985
979 // Sample CPU temperature in a background thread. 986 // Sample CPU temperature in a background thread.
980 state->SampleCPUTempInfo(cpu_temp_fetcher_); 987 state->SampleCPUTempInfo(cpu_temp_fetcher_);
981 988
982 // Add CPU utilization and free RAM. Note that these stats are sampled in 989 // Add CPU utilization and free RAM. Note that these stats are sampled in
983 // regular intervals. Unlike CPU temp and volume info these are not one-time 990 // regular intervals. Unlike CPU temp and volume info these are not one-time
984 // sampled values, hence the difference in logic. 991 // sampled values, hence the difference in logic.
985 status->set_system_ram_total(base::SysInfo::AmountOfPhysicalMemory()); 992 status->set_system_ram_total(base::SysInfo::AmountOfPhysicalMemory());
Andrew T Wilson (Slow) 2017/03/09 15:56:34 I'd include the volume reporting here.
986 status->clear_system_ram_free(); 993 status->clear_system_ram_free();
987 status->clear_cpu_utilization_pct(); 994 status->clear_cpu_utilization_pct();
988 for (const ResourceUsage& usage : resource_usage_) { 995 for (const ResourceUsage& usage : resource_usage_) {
989 status->add_cpu_utilization_pct(usage.cpu_usage_percent); 996 status->add_cpu_utilization_pct(usage.cpu_usage_percent);
990 status->add_system_ram_free(usage.bytes_of_ram_free); 997 status->add_system_ram_free(usage.bytes_of_ram_free);
991 } 998 }
992 return true; 999 return true;
993 } 1000 }
994 1001
995 bool DeviceStatusCollector::GetOsUpdateStatus( 1002 bool DeviceStatusCollector::GetOsUpdateStatus(
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
1072 1079
1073 chromeos::KioskAppManager::App app_info; 1080 chromeos::KioskAppManager::App app_info;
1074 if (chromeos::KioskAppManager::Get()->GetApp(account->kiosk_app_id, 1081 if (chromeos::KioskAppManager::Get()->GetApp(account->kiosk_app_id,
1075 &app_info)) { 1082 &app_info)) {
1076 running_kiosk_app->set_required_platform_version( 1083 running_kiosk_app->set_required_platform_version(
1077 app_info.required_platform_version); 1084 app_info.required_platform_version);
1078 } 1085 }
1079 return true; 1086 return true;
1080 } 1087 }
1081 1088
1089 bool DeviceStatusCollector::GetSoundVolume(
1090 em::DeviceStatusReportRequest* status) {
1091 chromeos::CrasAudioHandler* audio_handler = chromeos::CrasAudioHandler::Get();
1092 status->set_sound_volume(audio_handler->GetOutputVolumePercent());
1093 return true;
1094 }
1095
1082 void DeviceStatusCollector::GetDeviceAndSessionStatusAsync( 1096 void DeviceStatusCollector::GetDeviceAndSessionStatusAsync(
1083 const StatusCallback& response) { 1097 const StatusCallback& response) {
1084 // Must be on creation thread since some stats are written to in that thread 1098 // Must be on creation thread since some stats are written to in that thread
1085 // and accessing them from another thread would lead to race conditions. 1099 // and accessing them from another thread would lead to race conditions.
1086 DCHECK(thread_checker_.CalledOnValidThread()); 1100 DCHECK(thread_checker_.CalledOnValidThread());
1087 1101
1088 // Some of the data we're collecting is gathered in background threads. 1102 // Some of the data we're collecting is gathered in background threads.
1089 // This object keeps track of the state of each async request. 1103 // This object keeps track of the state of each async request.
1090 scoped_refptr<GetStatusState> state( 1104 scoped_refptr<GetStatusState> state(
1091 new GetStatusState(task_runner_, response)); 1105 new GetStatusState(task_runner_, response));
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
1124 1138
1125 if (report_hardware_status_) 1139 if (report_hardware_status_)
1126 anything_reported |= GetHardwareStatus(status, state); 1140 anything_reported |= GetHardwareStatus(status, state);
1127 1141
1128 if (report_os_update_status_) 1142 if (report_os_update_status_)
1129 anything_reported |= GetOsUpdateStatus(status); 1143 anything_reported |= GetOsUpdateStatus(status);
1130 1144
1131 if (report_running_kiosk_app_) 1145 if (report_running_kiosk_app_)
1132 anything_reported |= GetRunningKioskApp(status); 1146 anything_reported |= GetRunningKioskApp(status);
1133 1147
1148 if (report_sound_volume_)
1149 anything_reported |= GetSoundVolume(status);
1150
1134 // Wipe pointer if we didn't actually add any data. 1151 // Wipe pointer if we didn't actually add any data.
1135 if (!anything_reported) 1152 if (!anything_reported)
1136 state->ResetDeviceStatus(); 1153 state->ResetDeviceStatus();
1137 } 1154 }
1138 1155
1139 std::string DeviceStatusCollector::GetDMTokenForProfile(Profile* profile) { 1156 std::string DeviceStatusCollector::GetDMTokenForProfile(Profile* profile) {
1140 CloudPolicyManager* user_cloud_policy_manager = 1157 CloudPolicyManager* user_cloud_policy_manager =
1141 UserPolicyManagerFactoryChromeOS::GetCloudPolicyManagerForProfile( 1158 UserPolicyManagerFactoryChromeOS::GetCloudPolicyManagerForProfile(
1142 profile); 1159 profile);
1143 if (!user_cloud_policy_manager) { 1160 if (!user_cloud_policy_manager) {
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
1245 1262
1246 void DeviceStatusCollector::OnOSVersion(const std::string& version) { 1263 void DeviceStatusCollector::OnOSVersion(const std::string& version) {
1247 os_version_ = version; 1264 os_version_ = version;
1248 } 1265 }
1249 1266
1250 void DeviceStatusCollector::OnOSFirmware(const std::string& version) { 1267 void DeviceStatusCollector::OnOSFirmware(const std::string& version) {
1251 firmware_version_ = version; 1268 firmware_version_ = version;
1252 } 1269 }
1253 1270
1254 } // namespace policy 1271 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698