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