| 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> |
| 11 #include <cstdio> | 11 #include <cstdio> |
| 12 #include <limits> | 12 #include <limits> |
| 13 #include <memory> | 13 #include <memory> |
| 14 #include <sstream> | 14 #include <sstream> |
| 15 | 15 |
| 16 #include "base/bind.h" | 16 #include "base/bind.h" |
| 17 #include "base/bind_helpers.h" | 17 #include "base/bind_helpers.h" |
| 18 #include "base/files/file_enumerator.h" | 18 #include "base/files/file_enumerator.h" |
| 19 #include "base/files/file_util.h" | 19 #include "base/files/file_util.h" |
| 20 #include "base/format_macros.h" | 20 #include "base/format_macros.h" |
| 21 #include "base/logging.h" | 21 #include "base/logging.h" |
| 22 #include "base/macros.h" | 22 #include "base/macros.h" |
| 23 #include "base/memory/ptr_util.h" | 23 #include "base/memory/ptr_util.h" |
| 24 #include "base/memory/ref_counted.h" | |
| 25 #include "base/posix/eintr_wrapper.h" | 24 #include "base/posix/eintr_wrapper.h" |
| 26 #include "base/strings/string_number_conversions.h" | 25 #include "base/strings/string_number_conversions.h" |
| 27 #include "base/strings/string_util.h" | 26 #include "base/strings/string_util.h" |
| 28 #include "base/strings/stringprintf.h" | 27 #include "base/strings/stringprintf.h" |
| 29 #include "base/sys_info.h" | 28 #include "base/sys_info.h" |
| 30 #include "base/task_runner_util.h" | 29 #include "base/task_runner_util.h" |
| 31 #include "base/threading/sequenced_task_runner_handle.h" | 30 #include "base/threading/sequenced_task_runner_handle.h" |
| 32 #include "base/values.h" | 31 #include "base/values.h" |
| 33 #include "base/version.h" | 32 #include "base/version.h" |
| 34 #include "chrome/browser/browser_process.h" | 33 #include "chrome/browser/browser_process.h" |
| 35 #include "chrome/browser/chromeos/app_mode/kiosk_app_manager.h" | 34 #include "chrome/browser/chromeos/app_mode/kiosk_app_manager.h" |
| 36 #include "chrome/browser/chromeos/login/users/chrome_user_manager.h" | 35 #include "chrome/browser/chromeos/login/users/chrome_user_manager.h" |
| 37 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h" | 36 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h" |
| 38 #include "chrome/browser/chromeos/policy/device_local_account.h" | 37 #include "chrome/browser/chromeos/policy/device_local_account.h" |
| 39 #include "chrome/browser/chromeos/profiles/profile_helper.h" | 38 #include "chrome/browser/chromeos/profiles/profile_helper.h" |
| 40 #include "chrome/browser/chromeos/settings/cros_settings.h" | 39 #include "chrome/browser/chromeos/settings/cros_settings.h" |
| 41 #include "chrome/common/pref_names.h" | 40 #include "chrome/common/pref_names.h" |
| 42 #include "chromeos/dbus/dbus_thread_manager.h" | 41 #include "chromeos/dbus/dbus_thread_manager.h" |
| 43 #include "chromeos/dbus/update_engine_client.h" | 42 #include "chromeos/dbus/update_engine_client.h" |
| 44 #include "chromeos/disks/disk_mount_manager.h" | 43 #include "chromeos/disks/disk_mount_manager.h" |
| 45 #include "chromeos/network/device_state.h" | 44 #include "chromeos/network/device_state.h" |
| 46 #include "chromeos/network/network_handler.h" | 45 #include "chromeos/network/network_handler.h" |
| 47 #include "chromeos/network/network_state.h" | 46 #include "chromeos/network/network_state.h" |
| 48 #include "chromeos/network/network_state_handler.h" | 47 #include "chromeos/network/network_state_handler.h" |
| 49 #include "chromeos/settings/cros_settings_names.h" | 48 #include "chromeos/settings/cros_settings_names.h" |
| 50 #include "chromeos/system/statistics_provider.h" | 49 #include "chromeos/system/statistics_provider.h" |
| 50 #include "components/arc/arc_bridge_service.h" |
| 51 #include "components/arc/common/enterprise_reporting.mojom.h" |
| 51 #include "components/policy/core/common/cloud/cloud_policy_constants.h" | 52 #include "components/policy/core/common/cloud/cloud_policy_constants.h" |
| 52 #include "components/policy/proto/device_management_backend.pb.h" | 53 #include "components/policy/proto/device_management_backend.pb.h" |
| 53 #include "components/prefs/pref_registry_simple.h" | 54 #include "components/prefs/pref_registry_simple.h" |
| 54 #include "components/prefs/pref_service.h" | 55 #include "components/prefs/pref_service.h" |
| 55 #include "components/prefs/scoped_user_pref_update.h" | 56 #include "components/prefs/scoped_user_pref_update.h" |
| 56 #include "components/user_manager/user.h" | 57 #include "components/user_manager/user.h" |
| 57 #include "components/user_manager/user_manager.h" | 58 #include "components/user_manager/user_manager.h" |
| 58 #include "components/user_manager/user_type.h" | 59 #include "components/user_manager/user_type.h" |
| 59 #include "components/version_info/version_info.h" | 60 #include "components/version_info/version_info.h" |
| 60 #include "content/public/browser/browser_thread.h" | 61 #include "content/public/browser/browser_thread.h" |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 209 contents.push_back(info); | 210 contents.push_back(info); |
| 210 } else { | 211 } else { |
| 211 LOG(WARNING) << "Unable to read CPU temp from " | 212 LOG(WARNING) << "Unable to read CPU temp from " |
| 212 << temperature_path.MaybeAsASCII(); | 213 << temperature_path.MaybeAsASCII(); |
| 213 } | 214 } |
| 214 } | 215 } |
| 215 } | 216 } |
| 216 return contents; | 217 return contents; |
| 217 } | 218 } |
| 218 | 219 |
| 220 bool ReadAndroidStatus( |
| 221 const policy::DeviceStatusCollector::AndroidStatusReceiver& receiver) { |
| 222 auto* const arc_service = arc::ArcBridgeService::Get(); |
| 223 if (!arc_service) |
| 224 return false; |
| 225 auto* const instance_holder = arc_service->enterprise_reporting(); |
| 226 if (!instance_holder) |
| 227 return false; |
| 228 auto* const instance = instance_holder->GetInstanceForMethod("GetStatus", 1); |
| 229 if (!instance) |
| 230 return false; |
| 231 instance->GetStatus(receiver); |
| 232 return true; |
| 233 } |
| 234 |
| 219 // Returns the DeviceLocalAccount associated with the current kiosk session. | 235 // Returns the DeviceLocalAccount associated with the current kiosk session. |
| 220 // Returns null if there is no active kiosk session, or if that kiosk | 236 // Returns null if there is no active kiosk session, or if that kiosk |
| 221 // session has been removed from policy since the session started, in which | 237 // session has been removed from policy since the session started, in which |
| 222 // case we won't report its status). | 238 // case we won't report its status). |
| 223 std::unique_ptr<policy::DeviceLocalAccount> GetCurrentKioskDeviceLocalAccount( | 239 std::unique_ptr<policy::DeviceLocalAccount> GetCurrentKioskDeviceLocalAccount( |
| 224 chromeos::CrosSettings* settings) { | 240 chromeos::CrosSettings* settings) { |
| 225 if (!user_manager::UserManager::Get()->IsLoggedInAsKioskApp()) | 241 if (!user_manager::UserManager::Get()->IsLoggedInAsKioskApp()) |
| 226 return std::unique_ptr<policy::DeviceLocalAccount>(); | 242 return std::unique_ptr<policy::DeviceLocalAccount>(); |
| 227 const user_manager::User* const user = | 243 const user_manager::User* const user = |
| 228 user_manager::UserManager::Get()->GetActiveUser(); | 244 user_manager::UserManager::Get()->GetActiveUser(); |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 331 | 347 |
| 332 // Queues an async callback to query CPU temperature information. | 348 // Queues an async callback to query CPU temperature information. |
| 333 void SampleCPUTempInfo( | 349 void SampleCPUTempInfo( |
| 334 const policy::DeviceStatusCollector::CPUTempFetcher& cpu_temp_fetcher) { | 350 const policy::DeviceStatusCollector::CPUTempFetcher& cpu_temp_fetcher) { |
| 335 // Call out to the blocking pool to sample CPU temp. | 351 // Call out to the blocking pool to sample CPU temp. |
| 336 base::PostTaskAndReplyWithResult( | 352 base::PostTaskAndReplyWithResult( |
| 337 content::BrowserThread::GetBlockingPool(), FROM_HERE, cpu_temp_fetcher, | 353 content::BrowserThread::GetBlockingPool(), FROM_HERE, cpu_temp_fetcher, |
| 338 base::Bind(&GetStatusState::OnCPUTempInfoReceived, this)); | 354 base::Bind(&GetStatusState::OnCPUTempInfoReceived, this)); |
| 339 } | 355 } |
| 340 | 356 |
| 357 bool FetchAndroidStatus( |
| 358 const policy::DeviceStatusCollector::AndroidStatusFetcher& |
| 359 android_status_fetcher) { |
| 360 return android_status_fetcher.Run( |
| 361 base::Bind(&GetStatusState::OnAndroidInfoReceived, this)); |
| 362 } |
| 363 |
| 341 private: | 364 private: |
| 342 friend class RefCountedThreadSafe<GetStatusState>; | 365 friend class RefCountedThreadSafe<GetStatusState>; |
| 343 | 366 |
| 344 // Posts the response on the UI thread. As long as there is an outstanding | 367 // 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 | 368 // async query, the query holds a reference to us, so the destructor is |
| 346 // not called. | 369 // not called. |
| 347 ~GetStatusState() { | 370 ~GetStatusState() { |
| 348 task_runner_->PostTask(FROM_HERE, | 371 task_runner_->PostTask(FROM_HERE, |
| 349 base::Bind(response_, base::Passed(&device_status_), | 372 base::Bind(response_, base::Passed(&device_status_), |
| 350 base::Passed(&session_status_))); | 373 base::Passed(&session_status_))); |
| 351 } | 374 } |
| 352 | 375 |
| 353 void OnVolumeInfoReceived(const std::vector<em::VolumeInfo>& volume_info) { | 376 void OnVolumeInfoReceived(const std::vector<em::VolumeInfo>& volume_info) { |
| 354 device_status_->clear_volume_info(); | 377 device_status_->clear_volume_info(); |
| 355 for (const em::VolumeInfo& info : volume_info) | 378 for (const em::VolumeInfo& info : volume_info) |
| 356 *device_status_->add_volume_info() = info; | 379 *device_status_->add_volume_info() = info; |
| 357 } | 380 } |
| 358 | 381 |
| 359 void OnCPUTempInfoReceived( | 382 void OnCPUTempInfoReceived( |
| 360 const std::vector<em::CPUTempInfo>& cpu_temp_info) { | 383 const std::vector<em::CPUTempInfo>& cpu_temp_info) { |
| 361 if (cpu_temp_info.empty()) | 384 if (cpu_temp_info.empty()) |
| 362 DLOG(WARNING) << "Unable to read CPU temp information."; | 385 DLOG(WARNING) << "Unable to read CPU temp information."; |
| 363 | 386 |
| 364 device_status_->clear_cpu_temp_info(); | 387 device_status_->clear_cpu_temp_info(); |
| 365 for (const em::CPUTempInfo& info : cpu_temp_info) | 388 for (const em::CPUTempInfo& info : cpu_temp_info) |
| 366 *device_status_->add_cpu_temp_info() = info; | 389 *device_status_->add_cpu_temp_info() = info; |
| 367 } | 390 } |
| 368 | 391 |
| 392 void OnAndroidInfoReceived(mojo::String status, |
| 393 mojo::String droid_guard_info) { |
| 394 em::AndroidStatus* const android_status = |
| 395 session_status_->mutable_android_status(); |
| 396 android_status->set_status_payload(status); |
| 397 android_status->set_droid_guard_info(droid_guard_info); |
| 398 } |
| 399 |
| 369 const scoped_refptr<base::SequencedTaskRunner> task_runner_; | 400 const scoped_refptr<base::SequencedTaskRunner> task_runner_; |
| 370 policy::DeviceStatusCollector::StatusCallback response_; | 401 policy::DeviceStatusCollector::StatusCallback response_; |
| 371 std::unique_ptr<em::DeviceStatusReportRequest> device_status_ = | 402 std::unique_ptr<em::DeviceStatusReportRequest> device_status_ = |
| 372 base::MakeUnique<em::DeviceStatusReportRequest>(); | 403 base::MakeUnique<em::DeviceStatusReportRequest>(); |
| 373 std::unique_ptr<em::SessionStatusReportRequest> session_status_ = | 404 std::unique_ptr<em::SessionStatusReportRequest> session_status_ = |
| 374 base::MakeUnique<em::SessionStatusReportRequest>(); | 405 base::MakeUnique<em::SessionStatusReportRequest>(); |
| 375 }; | 406 }; |
| 376 | 407 |
| 377 DeviceStatusCollector::DeviceStatusCollector( | 408 DeviceStatusCollector::DeviceStatusCollector( |
| 378 PrefService* local_state, | 409 PrefService* local_state, |
| 379 chromeos::system::StatisticsProvider* provider, | 410 chromeos::system::StatisticsProvider* provider, |
| 380 const VolumeInfoFetcher& volume_info_fetcher, | 411 const VolumeInfoFetcher& volume_info_fetcher, |
| 381 const CPUStatisticsFetcher& cpu_statistics_fetcher, | 412 const CPUStatisticsFetcher& cpu_statistics_fetcher, |
| 382 const CPUTempFetcher& cpu_temp_fetcher) | 413 const CPUTempFetcher& cpu_temp_fetcher, |
| 414 const AndroidStatusFetcher& android_status_fetcher) |
| 383 : max_stored_past_activity_days_(kMaxStoredPastActivityDays), | 415 : max_stored_past_activity_days_(kMaxStoredPastActivityDays), |
| 384 max_stored_future_activity_days_(kMaxStoredFutureActivityDays), | 416 max_stored_future_activity_days_(kMaxStoredFutureActivityDays), |
| 385 local_state_(local_state), | 417 local_state_(local_state), |
| 386 last_idle_check_(Time()), | 418 last_idle_check_(Time()), |
| 387 volume_info_fetcher_(volume_info_fetcher), | 419 volume_info_fetcher_(volume_info_fetcher), |
| 388 cpu_statistics_fetcher_(cpu_statistics_fetcher), | 420 cpu_statistics_fetcher_(cpu_statistics_fetcher), |
| 389 cpu_temp_fetcher_(cpu_temp_fetcher), | 421 cpu_temp_fetcher_(cpu_temp_fetcher), |
| 422 android_status_fetcher_(android_status_fetcher), |
| 390 statistics_provider_(provider), | 423 statistics_provider_(provider), |
| 391 cros_settings_(chromeos::CrosSettings::Get()), | 424 cros_settings_(chromeos::CrosSettings::Get()), |
| 392 task_runner_(nullptr), | 425 task_runner_(nullptr), |
| 393 weak_factory_(this) { | 426 weak_factory_(this) { |
| 394 // Get the task runner of the current thread, so we can queue status responses | 427 // Get the task runner of the current thread, so we can queue status responses |
| 395 // on this thread. | 428 // on this thread. |
| 396 CHECK(base::SequencedTaskRunnerHandle::IsSet()); | 429 CHECK(base::SequencedTaskRunnerHandle::IsSet()); |
| 397 task_runner_ = base::SequencedTaskRunnerHandle::Get(); | 430 task_runner_ = base::SequencedTaskRunnerHandle::Get(); |
| 398 | 431 |
| 399 if (volume_info_fetcher_.is_null()) | 432 if (volume_info_fetcher_.is_null()) |
| 400 volume_info_fetcher_ = base::Bind(&GetVolumeInfo); | 433 volume_info_fetcher_ = base::Bind(&GetVolumeInfo); |
| 401 | 434 |
| 402 if (cpu_statistics_fetcher_.is_null()) | 435 if (cpu_statistics_fetcher_.is_null()) |
| 403 cpu_statistics_fetcher_ = base::Bind(&ReadCPUStatistics); | 436 cpu_statistics_fetcher_ = base::Bind(&ReadCPUStatistics); |
| 404 | 437 |
| 405 if (cpu_temp_fetcher_.is_null()) | 438 if (cpu_temp_fetcher_.is_null()) |
| 406 cpu_temp_fetcher_ = base::Bind(&ReadCPUTempInfo); | 439 cpu_temp_fetcher_ = base::Bind(&ReadCPUTempInfo); |
| 407 | 440 |
| 441 if (android_status_fetcher_.is_null()) |
| 442 android_status_fetcher_ = base::Bind(&ReadAndroidStatus); |
| 443 |
| 408 idle_poll_timer_.Start(FROM_HERE, | 444 idle_poll_timer_.Start(FROM_HERE, |
| 409 TimeDelta::FromSeconds(kIdlePollIntervalSeconds), | 445 TimeDelta::FromSeconds(kIdlePollIntervalSeconds), |
| 410 this, &DeviceStatusCollector::CheckIdleState); | 446 this, &DeviceStatusCollector::CheckIdleState); |
| 411 resource_usage_sampling_timer_.Start( | 447 resource_usage_sampling_timer_.Start( |
| 412 FROM_HERE, TimeDelta::FromSeconds(kResourceUsageSampleIntervalSeconds), | 448 FROM_HERE, TimeDelta::FromSeconds(kResourceUsageSampleIntervalSeconds), |
| 413 this, &DeviceStatusCollector::SampleResourceUsage); | 449 this, &DeviceStatusCollector::SampleResourceUsage); |
| 414 | 450 |
| 415 // Watch for changes to the individual policies that control what the status | 451 // Watch for changes to the individual policies that control what the status |
| 416 // reports contain. | 452 // reports contain. |
| 417 base::Closure callback = | 453 base::Closure callback = |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 503 chromeos::kReportDeviceUsers, &report_users_)) { | 539 chromeos::kReportDeviceUsers, &report_users_)) { |
| 504 report_users_ = true; | 540 report_users_ = true; |
| 505 } | 541 } |
| 506 | 542 |
| 507 const bool already_reporting_hardware_status = report_hardware_status_; | 543 const bool already_reporting_hardware_status = report_hardware_status_; |
| 508 if (!cros_settings_->GetBoolean( | 544 if (!cros_settings_->GetBoolean( |
| 509 chromeos::kReportDeviceHardwareStatus, &report_hardware_status_)) { | 545 chromeos::kReportDeviceHardwareStatus, &report_hardware_status_)) { |
| 510 report_hardware_status_ = true; | 546 report_hardware_status_ = true; |
| 511 } | 547 } |
| 512 | 548 |
| 513 if (!cros_settings_->GetBoolean( | 549 if (!cros_settings_->GetBoolean(chromeos::kReportDeviceSessionStatus, |
| 514 chromeos::kReportDeviceSessionStatus, &report_session_status_)) { | 550 &report_kiosk_session_status_)) { |
| 515 report_session_status_ = true; | 551 report_kiosk_session_status_ = true; |
| 516 } | 552 } |
| 517 | 553 |
| 554 // TODO(phweiss): Create policy to control this, and turn it on by default. |
| 555 report_android_status_ = false; |
| 556 |
| 518 if (!report_hardware_status_) { | 557 if (!report_hardware_status_) { |
| 519 ClearCachedResourceUsage(); | 558 ClearCachedResourceUsage(); |
| 520 } else if (!already_reporting_hardware_status) { | 559 } else if (!already_reporting_hardware_status) { |
| 521 // Turning on hardware status reporting - fetch an initial sample | 560 // Turning on hardware status reporting - fetch an initial sample |
| 522 // immediately instead of waiting for the sampling timer to fire. | 561 // immediately instead of waiting for the sampling timer to fire. |
| 523 SampleResourceUsage(); | 562 SampleResourceUsage(); |
| 524 } | 563 } |
| 525 | 564 |
| 526 // Os update status and running kiosk app reporting are disabled by default. | 565 // Os update status and running kiosk app reporting are disabled by default. |
| 527 if (!cros_settings_->GetBoolean(chromeos::kReportOsUpdateStatus, | 566 if (!cros_settings_->GetBoolean(chromeos::kReportOsUpdateStatus, |
| (...skipping 502 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1030 DCHECK(thread_checker_.CalledOnValidThread()); | 1069 DCHECK(thread_checker_.CalledOnValidThread()); |
| 1031 | 1070 |
| 1032 // Some of the data we're collecting is gathered in background threads. | 1071 // Some of the data we're collecting is gathered in background threads. |
| 1033 // This object keeps track of the state of each async request. | 1072 // This object keeps track of the state of each async request. |
| 1034 scoped_refptr<GetStatusState> state( | 1073 scoped_refptr<GetStatusState> state( |
| 1035 new GetStatusState(task_runner_, response)); | 1074 new GetStatusState(task_runner_, response)); |
| 1036 | 1075 |
| 1037 // Gather device status (might queue some async queries) | 1076 // Gather device status (might queue some async queries) |
| 1038 GetDeviceStatus(state); | 1077 GetDeviceStatus(state); |
| 1039 | 1078 |
| 1040 // Gather device status (might queue some async queries) | 1079 // Gather session status (might queue some async queries) |
| 1041 GetSessionStatus(state); | 1080 GetSessionStatus(state); |
| 1042 | 1081 |
| 1043 // If there are no outstanding async queries, e.g. from GetHardwareStatus(), | 1082 // If there are no outstanding async queries, e.g. from GetHardwareStatus(), |
| 1044 // the destructor of |state| calls |response|. If there are async queries, the | 1083 // the destructor of |state| calls |response|. If there are async queries, the |
| 1045 // queries hold references to |state|, so that |state| is only destroyed when | 1084 // queries hold references to |state|, so that |state| is only destroyed when |
| 1046 // the last async query has finished. | 1085 // the last async query has finished. |
| 1047 } | 1086 } |
| 1048 | 1087 |
| 1049 void DeviceStatusCollector::GetDeviceStatus( | 1088 void DeviceStatusCollector::GetDeviceStatus( |
| 1050 scoped_refptr<GetStatusState> state) { | 1089 scoped_refptr<GetStatusState> state) { |
| (...skipping 27 matching lines...) Expand all Loading... |
| 1078 // Wipe pointer if we didn't actually add any data. | 1117 // Wipe pointer if we didn't actually add any data. |
| 1079 if (!anything_reported) | 1118 if (!anything_reported) |
| 1080 state->ResetDeviceStatus(); | 1119 state->ResetDeviceStatus(); |
| 1081 } | 1120 } |
| 1082 | 1121 |
| 1083 void DeviceStatusCollector::GetSessionStatus( | 1122 void DeviceStatusCollector::GetSessionStatus( |
| 1084 scoped_refptr<GetStatusState> state) { | 1123 scoped_refptr<GetStatusState> state) { |
| 1085 em::SessionStatusReportRequest* status = state->session_status(); | 1124 em::SessionStatusReportRequest* status = state->session_status(); |
| 1086 bool anything_reported = false; | 1125 bool anything_reported = false; |
| 1087 | 1126 |
| 1088 if (report_session_status_) | 1127 if (report_kiosk_session_status_) |
| 1089 anything_reported |= GetAccountStatus(status); | 1128 anything_reported |= GetKioskSessionStatus(status); |
| 1129 if (report_android_status_) |
| 1130 anything_reported |= GetAndroidStatus(status, state); |
| 1090 | 1131 |
| 1091 // Wipe pointer if we didn't actually add any data. | 1132 // Wipe pointer if we didn't actually add any data. |
| 1092 if (!anything_reported) | 1133 if (!anything_reported) |
| 1093 state->ResetSessionStatus(); | 1134 state->ResetSessionStatus(); |
| 1094 } | 1135 } |
| 1095 | 1136 |
| 1096 bool DeviceStatusCollector::GetAccountStatus( | 1137 bool DeviceStatusCollector::GetKioskSessionStatus( |
| 1097 em::SessionStatusReportRequest* status) { | 1138 em::SessionStatusReportRequest* status) { |
| 1098 std::unique_ptr<const DeviceLocalAccount> account = | 1139 std::unique_ptr<const DeviceLocalAccount> account = |
| 1099 GetAutoLaunchedKioskSessionInfo(); | 1140 GetAutoLaunchedKioskSessionInfo(); |
| 1100 if (!account) | 1141 if (!account) |
| 1101 return false; | 1142 return false; |
| 1102 | 1143 |
| 1103 // Get the account ID associated with this user. | 1144 // Get the account ID associated with this user. |
| 1104 status->set_device_local_account_id(account->account_id); | 1145 status->set_device_local_account_id(account->account_id); |
| 1105 em::AppStatus* app_status = status->add_installed_apps(); | 1146 em::AppStatus* app_status = status->add_installed_apps(); |
| 1106 app_status->set_app_id(account->kiosk_app_id); | 1147 app_status->set_app_id(account->kiosk_app_id); |
| 1107 | 1148 |
| 1108 // Look up the app and get the version. | 1149 // Look up the app and get the version. |
| 1109 const std::string app_version = GetAppVersion(account->kiosk_app_id); | 1150 const std::string app_version = GetAppVersion(account->kiosk_app_id); |
| 1110 if (app_version.empty()) { | 1151 if (app_version.empty()) { |
| 1111 DLOG(ERROR) << "Unable to get version for extension: " | 1152 DLOG(ERROR) << "Unable to get version for extension: " |
| 1112 << account->kiosk_app_id; | 1153 << account->kiosk_app_id; |
| 1113 } else { | 1154 } else { |
| 1114 app_status->set_extension_version(app_version); | 1155 app_status->set_extension_version(app_version); |
| 1115 } | 1156 } |
| 1116 | 1157 |
| 1117 return true; | 1158 return true; |
| 1118 } | 1159 } |
| 1119 | 1160 |
| 1161 bool DeviceStatusCollector::GetAndroidStatus( |
| 1162 em::SessionStatusReportRequest* status, |
| 1163 const scoped_refptr<GetStatusState>& state) { |
| 1164 return state->FetchAndroidStatus(android_status_fetcher_); |
| 1165 } |
| 1166 |
| 1120 std::string DeviceStatusCollector::GetAppVersion( | 1167 std::string DeviceStatusCollector::GetAppVersion( |
| 1121 const std::string& kiosk_app_id) { | 1168 const std::string& kiosk_app_id) { |
| 1122 Profile* const profile = | 1169 Profile* const profile = |
| 1123 chromeos::ProfileHelper::Get()->GetProfileByUser( | 1170 chromeos::ProfileHelper::Get()->GetProfileByUser( |
| 1124 user_manager::UserManager::Get()->GetActiveUser()); | 1171 user_manager::UserManager::Get()->GetActiveUser()); |
| 1125 const extensions::ExtensionRegistry* const registry = | 1172 const extensions::ExtensionRegistry* const registry = |
| 1126 extensions::ExtensionRegistry::Get(profile); | 1173 extensions::ExtensionRegistry::Get(profile); |
| 1127 const extensions::Extension* const extension = registry->GetExtensionById( | 1174 const extensions::Extension* const extension = registry->GetExtensionById( |
| 1128 kiosk_app_id, extensions::ExtensionRegistry::EVERYTHING); | 1175 kiosk_app_id, extensions::ExtensionRegistry::EVERYTHING); |
| 1129 if (!extension) | 1176 if (!extension) |
| 1130 return std::string(); | 1177 return std::string(); |
| 1131 return extension->VersionString(); | 1178 return extension->VersionString(); |
| 1132 } | 1179 } |
| 1133 | 1180 |
| 1134 void DeviceStatusCollector::OnSubmittedSuccessfully() { | 1181 void DeviceStatusCollector::OnSubmittedSuccessfully() { |
| 1135 TrimStoredActivityPeriods(last_reported_day_, duration_for_last_reported_day_, | 1182 TrimStoredActivityPeriods(last_reported_day_, duration_for_last_reported_day_, |
| 1136 std::numeric_limits<int64_t>::max()); | 1183 std::numeric_limits<int64_t>::max()); |
| 1137 } | 1184 } |
| 1138 | 1185 |
| 1139 void DeviceStatusCollector::OnOSVersion(const std::string& version) { | 1186 void DeviceStatusCollector::OnOSVersion(const std::string& version) { |
| 1140 os_version_ = version; | 1187 os_version_ = version; |
| 1141 } | 1188 } |
| 1142 | 1189 |
| 1143 void DeviceStatusCollector::OnOSFirmware(const std::string& version) { | 1190 void DeviceStatusCollector::OnOSFirmware(const std::string& version) { |
| 1144 firmware_version_ = version; | 1191 firmware_version_ = version; |
| 1145 } | 1192 } |
| 1146 | 1193 |
| 1147 } // namespace policy | 1194 } // namespace policy |
| OLD | NEW |