Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 30 matching lines...) Expand all Loading... | |
| 41 #include "chrome/common/pref_names.h" | 41 #include "chrome/common/pref_names.h" |
| 42 #include "chromeos/dbus/dbus_thread_manager.h" | 42 #include "chromeos/dbus/dbus_thread_manager.h" |
| 43 #include "chromeos/dbus/update_engine_client.h" | 43 #include "chromeos/dbus/update_engine_client.h" |
| 44 #include "chromeos/disks/disk_mount_manager.h" | 44 #include "chromeos/disks/disk_mount_manager.h" |
| 45 #include "chromeos/network/device_state.h" | 45 #include "chromeos/network/device_state.h" |
| 46 #include "chromeos/network/network_handler.h" | 46 #include "chromeos/network/network_handler.h" |
| 47 #include "chromeos/network/network_state.h" | 47 #include "chromeos/network/network_state.h" |
| 48 #include "chromeos/network/network_state_handler.h" | 48 #include "chromeos/network/network_state_handler.h" |
| 49 #include "chromeos/settings/cros_settings_names.h" | 49 #include "chromeos/settings/cros_settings_names.h" |
| 50 #include "chromeos/system/statistics_provider.h" | 50 #include "chromeos/system/statistics_provider.h" |
| 51 #include "components/arc/arc_bridge_service.h" | |
| 52 #include "components/arc/common/enterprise_reporting.mojom.h" | |
| 51 #include "components/policy/core/common/cloud/cloud_policy_constants.h" | 53 #include "components/policy/core/common/cloud/cloud_policy_constants.h" |
| 52 #include "components/policy/proto/device_management_backend.pb.h" | 54 #include "components/policy/proto/device_management_backend.pb.h" |
| 53 #include "components/prefs/pref_registry_simple.h" | 55 #include "components/prefs/pref_registry_simple.h" |
| 54 #include "components/prefs/pref_service.h" | 56 #include "components/prefs/pref_service.h" |
| 55 #include "components/prefs/scoped_user_pref_update.h" | 57 #include "components/prefs/scoped_user_pref_update.h" |
| 56 #include "components/user_manager/user.h" | 58 #include "components/user_manager/user.h" |
| 57 #include "components/user_manager/user_manager.h" | 59 #include "components/user_manager/user_manager.h" |
| 58 #include "components/user_manager/user_type.h" | 60 #include "components/user_manager/user_type.h" |
| 59 #include "components/version_info/version_info.h" | 61 #include "components/version_info/version_info.h" |
| 60 #include "content/public/browser/browser_thread.h" | 62 #include "content/public/browser/browser_thread.h" |
| (...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 331 | 333 |
| 332 // Queues an async callback to query CPU temperature information. | 334 // Queues an async callback to query CPU temperature information. |
| 333 void SampleCPUTempInfo( | 335 void SampleCPUTempInfo( |
| 334 const policy::DeviceStatusCollector::CPUTempFetcher& cpu_temp_fetcher) { | 336 const policy::DeviceStatusCollector::CPUTempFetcher& cpu_temp_fetcher) { |
| 335 // Call out to the blocking pool to sample CPU temp. | 337 // Call out to the blocking pool to sample CPU temp. |
| 336 base::PostTaskAndReplyWithResult( | 338 base::PostTaskAndReplyWithResult( |
| 337 content::BrowserThread::GetBlockingPool(), FROM_HERE, cpu_temp_fetcher, | 339 content::BrowserThread::GetBlockingPool(), FROM_HERE, cpu_temp_fetcher, |
| 338 base::Bind(&GetStatusState::OnCPUTempInfoReceived, this)); | 340 base::Bind(&GetStatusState::OnCPUTempInfoReceived, this)); |
| 339 } | 341 } |
| 340 | 342 |
| 343 bool SampleAndroidInfo( | |
| 344 const policy::DeviceStatusCollector::AndroidStatusFetcher& | |
| 345 android_status_fetcher) { | |
| 346 if (android_status_fetcher.is_null()) { | |
|
ljusten (tachyonic)
2016/10/04 08:56:45
A more elegant approach would be to make android_s
phweiss
2016/10/05 15:34:22
Done.
| |
| 347 arc::ArcBridgeService *arc_service = arc::ArcBridgeService::Get(); | |
| 348 if (arc_service == nullptr) return false; | |
| 349 arc::InstanceHolder<arc::mojom::EnterpriseReportingInstance> | |
| 350 *instance_holder = arc_service->enterprise_reporting(); | |
| 351 if (instance_holder == nullptr) return false; | |
| 352 arc::mojom::EnterpriseReportingInstance *instance = | |
| 353 instance_holder->GetInstanceForMethod("GetStatus", 1); | |
| 354 if (instance == nullptr) return false; | |
| 355 instance->GetStatus( | |
| 356 base::Bind(&GetStatusState::OnAndroidInfoReceived, this)); | |
| 357 return true; | |
| 358 } else { | |
| 359 base::PostTaskAndReplyWithResult( | |
| 360 content::BrowserThread::GetBlockingPool(), FROM_HERE, | |
| 361 android_status_fetcher, | |
| 362 base::Bind(&GetStatusState::OnAndroidInfoPairReceived, this)); | |
| 363 return true; | |
| 364 } | |
| 365 } | |
| 366 | |
| 341 private: | 367 private: |
| 342 friend class RefCountedThreadSafe<GetStatusState>; | 368 friend class RefCountedThreadSafe<GetStatusState>; |
| 343 | 369 |
| 344 // Posts the response on the UI thread. As long as there is an outstanding | 370 // Posts the response on the UI thread. As long as there is an outstanding |
| 345 // async query, the query holds a reference to us, so the destructor is | 371 // async query, the query holds a reference to us, so the destructor is |
| 346 // not called. | 372 // not called. |
| 347 ~GetStatusState() { | 373 ~GetStatusState() { |
| 348 task_runner_->PostTask(FROM_HERE, | 374 task_runner_->PostTask(FROM_HERE, |
| 349 base::Bind(response_, base::Passed(&device_status_), | 375 base::Bind(response_, base::Passed(&device_status_), |
| 350 base::Passed(&session_status_))); | 376 base::Passed(&session_status_))); |
| 351 } | 377 } |
| 352 | 378 |
| 353 void OnVolumeInfoReceived(const std::vector<em::VolumeInfo>& volume_info) { | 379 void OnVolumeInfoReceived(const std::vector<em::VolumeInfo>& volume_info) { |
| 354 device_status_->clear_volume_info(); | 380 device_status_->clear_volume_info(); |
| 355 for (const em::VolumeInfo& info : volume_info) | 381 for (const em::VolumeInfo& info : volume_info) |
| 356 *device_status_->add_volume_info() = info; | 382 *device_status_->add_volume_info() = info; |
| 357 } | 383 } |
| 358 | 384 |
| 359 void OnCPUTempInfoReceived( | 385 void OnCPUTempInfoReceived( |
| 360 const std::vector<em::CPUTempInfo>& cpu_temp_info) { | 386 const std::vector<em::CPUTempInfo>& cpu_temp_info) { |
| 361 if (cpu_temp_info.empty()) | 387 if (cpu_temp_info.empty()) |
| 362 DLOG(WARNING) << "Unable to read CPU temp information."; | 388 DLOG(WARNING) << "Unable to read CPU temp information."; |
| 363 | 389 |
| 364 device_status_->clear_cpu_temp_info(); | 390 device_status_->clear_cpu_temp_info(); |
| 365 for (const em::CPUTempInfo& info : cpu_temp_info) | 391 for (const em::CPUTempInfo& info : cpu_temp_info) |
| 366 *device_status_->add_cpu_temp_info() = info; | 392 *device_status_->add_cpu_temp_info() = info; |
| 367 } | 393 } |
| 368 | 394 |
| 395 void OnAndroidInfoPairReceived(std::pair<mojo::String, mojo::String> status) { | |
|
ljusten (tachyonic)
2016/10/04 08:56:45
Nit: Is it possible to change the signature of moj
phweiss
2016/10/05 15:34:22
No, mojo can connect C++ and Java, so their interf
| |
| 396 OnAndroidInfoReceived(status.first, status.second); | |
| 397 } | |
| 398 | |
| 399 void OnAndroidInfoReceived(mojo::String status, | |
| 400 mojo::String droid_guard_info) { | |
| 401 em::AndroidStatus *android_status = | |
| 402 session_status_->mutable_android_status(); | |
| 403 android_status->set_status_payload(status); | |
| 404 android_status->set_droid_guard_info(droid_guard_info); | |
| 405 } | |
| 406 | |
| 369 const scoped_refptr<base::SequencedTaskRunner> task_runner_; | 407 const scoped_refptr<base::SequencedTaskRunner> task_runner_; |
| 370 policy::DeviceStatusCollector::StatusCallback response_; | 408 policy::DeviceStatusCollector::StatusCallback response_; |
| 371 std::unique_ptr<em::DeviceStatusReportRequest> device_status_ = | 409 std::unique_ptr<em::DeviceStatusReportRequest> device_status_ = |
| 372 base::MakeUnique<em::DeviceStatusReportRequest>(); | 410 base::MakeUnique<em::DeviceStatusReportRequest>(); |
| 373 std::unique_ptr<em::SessionStatusReportRequest> session_status_ = | 411 std::unique_ptr<em::SessionStatusReportRequest> session_status_ = |
| 374 base::MakeUnique<em::SessionStatusReportRequest>(); | 412 base::MakeUnique<em::SessionStatusReportRequest>(); |
| 375 }; | 413 }; |
| 376 | 414 |
| 377 DeviceStatusCollector::DeviceStatusCollector( | 415 DeviceStatusCollector::DeviceStatusCollector( |
| 378 PrefService* local_state, | 416 PrefService* local_state, |
| 379 chromeos::system::StatisticsProvider* provider, | 417 chromeos::system::StatisticsProvider* provider, |
| 380 const VolumeInfoFetcher& volume_info_fetcher, | 418 const VolumeInfoFetcher& volume_info_fetcher, |
| 381 const CPUStatisticsFetcher& cpu_statistics_fetcher, | 419 const CPUStatisticsFetcher& cpu_statistics_fetcher, |
| 382 const CPUTempFetcher& cpu_temp_fetcher) | 420 const CPUTempFetcher& cpu_temp_fetcher, |
| 421 const AndroidStatusFetcher& android_status_fetcher) | |
| 383 : max_stored_past_activity_days_(kMaxStoredPastActivityDays), | 422 : max_stored_past_activity_days_(kMaxStoredPastActivityDays), |
| 384 max_stored_future_activity_days_(kMaxStoredFutureActivityDays), | 423 max_stored_future_activity_days_(kMaxStoredFutureActivityDays), |
| 385 local_state_(local_state), | 424 local_state_(local_state), |
| 386 last_idle_check_(Time()), | 425 last_idle_check_(Time()), |
| 387 volume_info_fetcher_(volume_info_fetcher), | 426 volume_info_fetcher_(volume_info_fetcher), |
| 388 cpu_statistics_fetcher_(cpu_statistics_fetcher), | 427 cpu_statistics_fetcher_(cpu_statistics_fetcher), |
| 389 cpu_temp_fetcher_(cpu_temp_fetcher), | 428 cpu_temp_fetcher_(cpu_temp_fetcher), |
| 429 android_status_fetcher_(android_status_fetcher), | |
| 390 statistics_provider_(provider), | 430 statistics_provider_(provider), |
| 391 cros_settings_(chromeos::CrosSettings::Get()), | 431 cros_settings_(chromeos::CrosSettings::Get()), |
| 392 task_runner_(nullptr), | 432 task_runner_(nullptr), |
| 393 weak_factory_(this) { | 433 weak_factory_(this) { |
| 394 // Get the task runner of the current thread, so we can queue status responses | 434 // Get the task runner of the current thread, so we can queue status responses |
| 395 // on this thread. | 435 // on this thread. |
| 396 CHECK(base::SequencedTaskRunnerHandle::IsSet()); | 436 CHECK(base::SequencedTaskRunnerHandle::IsSet()); |
| 397 task_runner_ = base::SequencedTaskRunnerHandle::Get(); | 437 task_runner_ = base::SequencedTaskRunnerHandle::Get(); |
| 398 | 438 |
| 399 if (volume_info_fetcher_.is_null()) | 439 if (volume_info_fetcher_.is_null()) |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 508 if (!cros_settings_->GetBoolean( | 548 if (!cros_settings_->GetBoolean( |
| 509 chromeos::kReportDeviceHardwareStatus, &report_hardware_status_)) { | 549 chromeos::kReportDeviceHardwareStatus, &report_hardware_status_)) { |
| 510 report_hardware_status_ = true; | 550 report_hardware_status_ = true; |
| 511 } | 551 } |
| 512 | 552 |
| 513 if (!cros_settings_->GetBoolean( | 553 if (!cros_settings_->GetBoolean( |
| 514 chromeos::kReportDeviceSessionStatus, &report_session_status_)) { | 554 chromeos::kReportDeviceSessionStatus, &report_session_status_)) { |
| 515 report_session_status_ = true; | 555 report_session_status_ = true; |
| 516 } | 556 } |
| 517 | 557 |
| 558 // TODO(phweiss): Create policy to control this, and turn it on by default. | |
| 559 report_android_status_ = false; | |
| 560 | |
| 518 if (!report_hardware_status_) { | 561 if (!report_hardware_status_) { |
| 519 ClearCachedResourceUsage(); | 562 ClearCachedResourceUsage(); |
| 520 } else if (!already_reporting_hardware_status) { | 563 } else if (!already_reporting_hardware_status) { |
| 521 // Turning on hardware status reporting - fetch an initial sample | 564 // Turning on hardware status reporting - fetch an initial sample |
| 522 // immediately instead of waiting for the sampling timer to fire. | 565 // immediately instead of waiting for the sampling timer to fire. |
| 523 SampleResourceUsage(); | 566 SampleResourceUsage(); |
| 524 } | 567 } |
| 525 | 568 |
| 526 // Os update status and running kiosk app reporting are disabled by default. | 569 // Os update status and running kiosk app reporting are disabled by default. |
| 527 if (!cros_settings_->GetBoolean(chromeos::kReportOsUpdateStatus, | 570 if (!cros_settings_->GetBoolean(chromeos::kReportOsUpdateStatus, |
| (...skipping 550 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1078 // Wipe pointer if we didn't actually add any data. | 1121 // Wipe pointer if we didn't actually add any data. |
| 1079 if (!anything_reported) | 1122 if (!anything_reported) |
| 1080 state->ResetDeviceStatus(); | 1123 state->ResetDeviceStatus(); |
| 1081 } | 1124 } |
| 1082 | 1125 |
| 1083 void DeviceStatusCollector::GetSessionStatus( | 1126 void DeviceStatusCollector::GetSessionStatus( |
| 1084 scoped_refptr<GetStatusState> state) { | 1127 scoped_refptr<GetStatusState> state) { |
| 1085 em::SessionStatusReportRequest* status = state->session_status(); | 1128 em::SessionStatusReportRequest* status = state->session_status(); |
| 1086 bool anything_reported = false; | 1129 bool anything_reported = false; |
| 1087 | 1130 |
| 1088 if (report_session_status_) | 1131 if (report_session_status_) { |
| 1089 anything_reported |= GetAccountStatus(status); | 1132 anything_reported |= GetAccountStatus(status); |
| 1133 if (report_android_status_) | |
| 1134 anything_reported |= GetAndroidStatus(status, state); | |
| 1135 } | |
| 1090 | 1136 |
| 1091 // Wipe pointer if we didn't actually add any data. | 1137 // Wipe pointer if we didn't actually add any data. |
| 1092 if (!anything_reported) | 1138 if (!anything_reported) |
| 1093 state->ResetSessionStatus(); | 1139 state->ResetSessionStatus(); |
| 1094 } | 1140 } |
| 1095 | 1141 |
| 1096 bool DeviceStatusCollector::GetAccountStatus( | 1142 bool DeviceStatusCollector::GetAccountStatus( |
| 1097 em::SessionStatusReportRequest* status) { | 1143 em::SessionStatusReportRequest* status) { |
| 1098 std::unique_ptr<const DeviceLocalAccount> account = | 1144 std::unique_ptr<const DeviceLocalAccount> account = |
| 1099 GetAutoLaunchedKioskSessionInfo(); | 1145 GetAutoLaunchedKioskSessionInfo(); |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 1110 if (app_version.empty()) { | 1156 if (app_version.empty()) { |
| 1111 DLOG(ERROR) << "Unable to get version for extension: " | 1157 DLOG(ERROR) << "Unable to get version for extension: " |
| 1112 << account->kiosk_app_id; | 1158 << account->kiosk_app_id; |
| 1113 } else { | 1159 } else { |
| 1114 app_status->set_extension_version(app_version); | 1160 app_status->set_extension_version(app_version); |
| 1115 } | 1161 } |
| 1116 | 1162 |
| 1117 return true; | 1163 return true; |
| 1118 } | 1164 } |
| 1119 | 1165 |
| 1166 bool DeviceStatusCollector::GetAndroidStatus( | |
| 1167 em::SessionStatusReportRequest* status, | |
| 1168 scoped_refptr<GetStatusState> state) { | |
| 1169 return state->SampleAndroidInfo(android_status_fetcher_); | |
| 1170 } | |
| 1171 | |
| 1120 std::string DeviceStatusCollector::GetAppVersion( | 1172 std::string DeviceStatusCollector::GetAppVersion( |
| 1121 const std::string& kiosk_app_id) { | 1173 const std::string& kiosk_app_id) { |
| 1122 Profile* const profile = | 1174 Profile* const profile = |
| 1123 chromeos::ProfileHelper::Get()->GetProfileByUser( | 1175 chromeos::ProfileHelper::Get()->GetProfileByUser( |
| 1124 user_manager::UserManager::Get()->GetActiveUser()); | 1176 user_manager::UserManager::Get()->GetActiveUser()); |
| 1125 const extensions::ExtensionRegistry* const registry = | 1177 const extensions::ExtensionRegistry* const registry = |
| 1126 extensions::ExtensionRegistry::Get(profile); | 1178 extensions::ExtensionRegistry::Get(profile); |
| 1127 const extensions::Extension* const extension = registry->GetExtensionById( | 1179 const extensions::Extension* const extension = registry->GetExtensionById( |
| 1128 kiosk_app_id, extensions::ExtensionRegistry::EVERYTHING); | 1180 kiosk_app_id, extensions::ExtensionRegistry::EVERYTHING); |
| 1129 if (!extension) | 1181 if (!extension) |
| 1130 return std::string(); | 1182 return std::string(); |
| 1131 return extension->VersionString(); | 1183 return extension->VersionString(); |
| 1132 } | 1184 } |
| 1133 | 1185 |
| 1134 void DeviceStatusCollector::OnSubmittedSuccessfully() { | 1186 void DeviceStatusCollector::OnSubmittedSuccessfully() { |
| 1135 TrimStoredActivityPeriods(last_reported_day_, duration_for_last_reported_day_, | 1187 TrimStoredActivityPeriods(last_reported_day_, duration_for_last_reported_day_, |
| 1136 std::numeric_limits<int64_t>::max()); | 1188 std::numeric_limits<int64_t>::max()); |
| 1137 } | 1189 } |
| 1138 | 1190 |
| 1139 void DeviceStatusCollector::OnOSVersion(const std::string& version) { | 1191 void DeviceStatusCollector::OnOSVersion(const std::string& version) { |
| 1140 os_version_ = version; | 1192 os_version_ = version; |
| 1141 } | 1193 } |
| 1142 | 1194 |
| 1143 void DeviceStatusCollector::OnOSFirmware(const std::string& version) { | 1195 void DeviceStatusCollector::OnOSFirmware(const std::string& version) { |
| 1144 firmware_version_ = version; | 1196 firmware_version_ = version; |
| 1145 } | 1197 } |
| 1146 | 1198 |
| 1147 } // namespace policy | 1199 } // namespace policy |
| OLD | NEW |