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 <stdint.h> | 7 #include <stdint.h> |
8 #include <limits> | 8 #include <limits> |
9 #include <sys/statvfs.h> | 9 #include <sys/statvfs.h> |
10 | 10 |
11 #include "base/bind.h" | 11 #include "base/bind.h" |
12 #include "base/bind_helpers.h" | 12 #include "base/bind_helpers.h" |
13 #include "base/location.h" | 13 #include "base/location.h" |
14 #include "base/logging.h" | 14 #include "base/logging.h" |
15 #include "base/memory/scoped_ptr.h" | 15 #include "base/memory/scoped_ptr.h" |
16 #include "base/posix/eintr_wrapper.h" | 16 #include "base/posix/eintr_wrapper.h" |
17 #include "base/prefs/pref_registry_simple.h" | 17 #include "base/prefs/pref_registry_simple.h" |
18 #include "base/prefs/pref_service.h" | 18 #include "base/prefs/pref_service.h" |
19 #include "base/prefs/scoped_user_pref_update.h" | 19 #include "base/prefs/scoped_user_pref_update.h" |
20 #include "base/process/process.h" | 20 #include "base/process/process.h" |
21 #include "base/process/process_iterator.h" | 21 #include "base/process/process_iterator.h" |
22 #include "base/process/process_metrics.h" | 22 #include "base/process/process_metrics.h" |
23 #include "base/strings/string_number_conversions.h" | 23 #include "base/strings/string_number_conversions.h" |
24 #include "base/sys_info.h" | 24 #include "base/sys_info.h" |
25 #include "base/task_runner_util.h" | 25 #include "base/task_runner_util.h" |
26 #include "base/values.h" | 26 #include "base/values.h" |
27 #include "chrome/browser/browser_process.h" | 27 #include "chrome/browser/browser_process.h" |
| 28 #include "chrome/browser/chromeos/app_mode/kiosk_app_manager.h" |
28 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h" | 29 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h" |
| 30 #include "chrome/browser/chromeos/policy/device_local_account.h" |
| 31 #include "chrome/browser/chromeos/profiles/profile_helper.h" |
29 #include "chrome/browser/chromeos/settings/cros_settings.h" | 32 #include "chrome/browser/chromeos/settings/cros_settings.h" |
30 #include "chrome/common/chrome_version_info.h" | 33 #include "chrome/common/chrome_version_info.h" |
31 #include "chrome/common/pref_names.h" | 34 #include "chrome/common/pref_names.h" |
32 #include "chromeos/disks/disk_mount_manager.h" | 35 #include "chromeos/disks/disk_mount_manager.h" |
33 #include "chromeos/network/device_state.h" | 36 #include "chromeos/network/device_state.h" |
34 #include "chromeos/network/network_handler.h" | 37 #include "chromeos/network/network_handler.h" |
35 #include "chromeos/network/network_state.h" | 38 #include "chromeos/network/network_state.h" |
36 #include "chromeos/network/network_state_handler.h" | 39 #include "chromeos/network/network_state_handler.h" |
37 #include "chromeos/settings/cros_settings_names.h" | 40 #include "chromeos/settings/cros_settings_names.h" |
38 #include "chromeos/system/statistics_provider.h" | 41 #include "chromeos/system/statistics_provider.h" |
39 #include "components/policy/core/common/cloud/cloud_policy_constants.h" | 42 #include "components/policy/core/common/cloud/cloud_policy_constants.h" |
| 43 #include "components/user_manager/user.h" |
40 #include "components/user_manager/user_manager.h" | 44 #include "components/user_manager/user_manager.h" |
41 #include "components/user_manager/user_type.h" | 45 #include "components/user_manager/user_type.h" |
42 #include "content/public/browser/browser_thread.h" | 46 #include "content/public/browser/browser_thread.h" |
| 47 #include "extensions/browser/extension_registry.h" |
| 48 #include "extensions/common/extension.h" |
43 #include "policy/proto/device_management_backend.pb.h" | 49 #include "policy/proto/device_management_backend.pb.h" |
44 #include "third_party/cros_system_api/dbus/service_constants.h" | 50 #include "third_party/cros_system_api/dbus/service_constants.h" |
45 | 51 |
46 using base::Time; | 52 using base::Time; |
47 using base::TimeDelta; | 53 using base::TimeDelta; |
48 | 54 |
49 namespace em = enterprise_management; | 55 namespace em = enterprise_management; |
50 | 56 |
51 namespace { | 57 namespace { |
52 // How many seconds of inactivity triggers the idle state. | 58 // How many seconds of inactivity triggers the idle state. |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
99 info.set_storage_free(static_cast<uint64_t>(stat.f_bavail) * | 105 info.set_storage_free(static_cast<uint64_t>(stat.f_bavail) * |
100 stat.f_frsize); | 106 stat.f_frsize); |
101 result.push_back(info); | 107 result.push_back(info); |
102 } else { | 108 } else { |
103 LOG(ERROR) << "Unable to get volume status for " << mount_point; | 109 LOG(ERROR) << "Unable to get volume status for " << mount_point; |
104 } | 110 } |
105 } | 111 } |
106 return result; | 112 return result; |
107 } | 113 } |
108 | 114 |
| 115 // Returns the DeviceLocalAccount associated with the current kiosk session. |
| 116 // Returns null if there is no active kiosk session, or if that kiosk |
| 117 // session has been removed from policy since the session started, in which |
| 118 // case we won't report its status). |
| 119 scoped_ptr<policy::DeviceLocalAccount> |
| 120 GetCurrentKioskDeviceLocalAccount(chromeos::CrosSettings* settings) { |
| 121 if (!user_manager::UserManager::Get()->IsLoggedInAsKioskApp()) |
| 122 return scoped_ptr<policy::DeviceLocalAccount>(); |
| 123 const user_manager::User* const user = |
| 124 user_manager::UserManager::Get()->GetActiveUser(); |
| 125 const std::string user_id = user->GetUserID(); |
| 126 const std::vector<policy::DeviceLocalAccount> accounts = |
| 127 policy::GetDeviceLocalAccounts(settings); |
| 128 |
| 129 for (const auto& device_local_account : accounts) { |
| 130 if (device_local_account.user_id == user_id) { |
| 131 return make_scoped_ptr( |
| 132 new policy::DeviceLocalAccount(device_local_account)).Pass(); |
| 133 } |
| 134 } |
| 135 LOG(WARNING) << "Kiosk app not found in list of device-local accounts"; |
| 136 return scoped_ptr<policy::DeviceLocalAccount>(); |
| 137 } |
| 138 |
109 } // namespace | 139 } // namespace |
110 | 140 |
111 namespace policy { | 141 namespace policy { |
112 | 142 |
113 DeviceStatusCollector::DeviceStatusCollector( | 143 DeviceStatusCollector::DeviceStatusCollector( |
114 PrefService* local_state, | 144 PrefService* local_state, |
115 chromeos::system::StatisticsProvider* provider, | 145 chromeos::system::StatisticsProvider* provider, |
116 const LocationUpdateRequester& location_update_requester, | 146 const LocationUpdateRequester& location_update_requester, |
117 const VolumeInfoFetcher& volume_info_fetcher) | 147 const VolumeInfoFetcher& volume_info_fetcher) |
118 : max_stored_past_activity_days_(kMaxStoredPastActivityDays), | 148 : max_stored_past_activity_days_(kMaxStoredPastActivityDays), |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
233 // back when they are available. | 263 // back when they are available. |
234 if (chromeos::CrosSettingsProvider::TRUSTED != | 264 if (chromeos::CrosSettingsProvider::TRUSTED != |
235 cros_settings_->PrepareTrustedValues( | 265 cros_settings_->PrepareTrustedValues( |
236 base::Bind(&DeviceStatusCollector::UpdateReportingSettings, | 266 base::Bind(&DeviceStatusCollector::UpdateReportingSettings, |
237 weak_factory_.GetWeakPtr()))) { | 267 weak_factory_.GetWeakPtr()))) { |
238 return; | 268 return; |
239 } | 269 } |
240 | 270 |
241 // All reporting settings default to 'enabled'. | 271 // All reporting settings default to 'enabled'. |
242 if (!cros_settings_->GetBoolean( | 272 if (!cros_settings_->GetBoolean( |
243 chromeos::kReportDeviceVersionInfo, &report_version_info_)) { | 273 chromeos::kReportDeviceVersionInfo, &report_version_info_)) { |
244 report_version_info_ = true; | 274 report_version_info_ = true; |
245 } | 275 } |
246 if (!cros_settings_->GetBoolean( | 276 if (!cros_settings_->GetBoolean( |
247 chromeos::kReportDeviceActivityTimes, &report_activity_times_)) { | 277 chromeos::kReportDeviceActivityTimes, &report_activity_times_)) { |
248 report_activity_times_ = true; | 278 report_activity_times_ = true; |
249 } | 279 } |
250 if (!cros_settings_->GetBoolean( | 280 if (!cros_settings_->GetBoolean( |
251 chromeos::kReportDeviceBootMode, &report_boot_mode_)) { | 281 chromeos::kReportDeviceBootMode, &report_boot_mode_)) { |
252 report_boot_mode_ = true; | 282 report_boot_mode_ = true; |
253 } | 283 } |
254 if (!cros_settings_->GetBoolean( | 284 if (!cros_settings_->GetBoolean( |
255 chromeos::kReportDeviceNetworkInterfaces, &report_network_interfaces_)) { | 285 chromeos::kReportDeviceNetworkInterfaces, |
| 286 &report_network_interfaces_)) { |
256 report_network_interfaces_ = true; | 287 report_network_interfaces_ = true; |
257 } | 288 } |
258 if (!cros_settings_->GetBoolean( | 289 if (!cros_settings_->GetBoolean( |
259 chromeos::kReportDeviceUsers, &report_users_)) { | 290 chromeos::kReportDeviceUsers, &report_users_)) { |
260 report_users_ = true; | 291 report_users_ = true; |
261 } | 292 } |
262 | 293 |
263 const bool already_reporting_hardware_status = report_hardware_status_; | 294 const bool already_reporting_hardware_status = report_hardware_status_; |
264 if (!cros_settings_->GetBoolean( | 295 if (!cros_settings_->GetBoolean( |
265 chromeos::kReportDeviceHardwareStatus, &report_hardware_status_)) { | 296 chromeos::kReportDeviceHardwareStatus, &report_hardware_status_)) { |
266 report_hardware_status_ = true; | 297 report_hardware_status_ = true; |
267 } | 298 } |
268 | 299 |
269 if (!cros_settings_->GetBoolean( | 300 if (!cros_settings_->GetBoolean( |
270 chromeos::kReportDeviceSessionStatus, &report_session_status_)) { | 301 chromeos::kReportDeviceSessionStatus, &report_session_status_)) { |
271 report_session_status_ = true; | 302 report_session_status_ = true; |
272 } | 303 } |
273 | 304 |
274 // Device location reporting is disabled by default because it is | 305 // Device location reporting is disabled by default because it is |
275 // not launched yet. | 306 // not launched yet. |
276 if (!cros_settings_->GetBoolean( | 307 if (!cros_settings_->GetBoolean( |
277 chromeos::kReportDeviceLocation, &report_location_)) { | 308 chromeos::kReportDeviceLocation, &report_location_)) { |
278 report_location_ = false; | 309 report_location_ = false; |
279 } | 310 } |
280 | 311 |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
382 now); | 413 now); |
383 } else { | 414 } else { |
384 AddActivePeriod(last_idle_check_, now); | 415 AddActivePeriod(last_idle_check_, now); |
385 } | 416 } |
386 | 417 |
387 PruneStoredActivityPeriods(now); | 418 PruneStoredActivityPeriods(now); |
388 } | 419 } |
389 last_idle_check_ = now; | 420 last_idle_check_ = now; |
390 } | 421 } |
391 | 422 |
392 bool DeviceStatusCollector::IsAutoLaunchedKioskSession() { | 423 scoped_ptr<DeviceLocalAccount> |
393 // TODO(atwilson): Determine if the currently active session is an | 424 DeviceStatusCollector::GetAutoLaunchedKioskSessionInfo() { |
394 // autolaunched kiosk session (http://crbug.com/452968). | 425 scoped_ptr<DeviceLocalAccount> account = |
395 return false; | 426 GetCurrentKioskDeviceLocalAccount(cros_settings_); |
| 427 if (account) { |
| 428 chromeos::KioskAppManager::App current_app; |
| 429 if (chromeos::KioskAppManager::Get()->GetApp(account->kiosk_app_id, |
| 430 ¤t_app) && |
| 431 current_app.was_auto_launched_with_zero_delay) { |
| 432 return account.Pass(); |
| 433 } |
| 434 } |
| 435 // No auto-launched kiosk session active. |
| 436 return scoped_ptr<DeviceLocalAccount>(); |
396 } | 437 } |
397 | 438 |
398 void DeviceStatusCollector::SampleHardwareStatus() { | 439 void DeviceStatusCollector::SampleHardwareStatus() { |
399 // If hardware reporting has been disabled, do nothing here. | 440 // If hardware reporting has been disabled, do nothing here. |
400 if (!report_hardware_status_) | 441 if (!report_hardware_status_) |
401 return; | 442 return; |
402 | 443 |
403 // Create list of mounted disk volumes to query status. | 444 // Create list of mounted disk volumes to query status. |
404 std::vector<std::string> mount_points; | 445 std::vector<std::string> mount_points; |
405 for (const auto& mount_info : | 446 for (const auto& mount_info : |
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
598 interface->set_mac_address((*device)->mac_address()); | 639 interface->set_mac_address((*device)->mac_address()); |
599 if (!(*device)->meid().empty()) | 640 if (!(*device)->meid().empty()) |
600 interface->set_meid((*device)->meid()); | 641 interface->set_meid((*device)->meid()); |
601 if (!(*device)->imei().empty()) | 642 if (!(*device)->imei().empty()) |
602 interface->set_imei((*device)->imei()); | 643 interface->set_imei((*device)->imei()); |
603 if (!(*device)->path().empty()) | 644 if (!(*device)->path().empty()) |
604 interface->set_device_path((*device)->path()); | 645 interface->set_device_path((*device)->path()); |
605 } | 646 } |
606 | 647 |
607 // Don't write any network state if we aren't in a kiosk session. | 648 // Don't write any network state if we aren't in a kiosk session. |
608 if (!IsAutoLaunchedKioskSession()) | 649 if (!GetAutoLaunchedKioskSessionInfo()) |
609 return; | 650 return; |
610 | 651 |
611 // Walk the various networks and store their state in the status report. | 652 // Walk the various networks and store their state in the status report. |
612 chromeos::NetworkStateHandler::NetworkStateList state_list; | 653 chromeos::NetworkStateHandler::NetworkStateList state_list; |
613 network_state_handler->GetNetworkListByType( | 654 network_state_handler->GetNetworkListByType( |
614 chromeos::NetworkTypePattern::Default(), | 655 chromeos::NetworkTypePattern::Default(), |
615 true, // configured_only | 656 true, // configured_only |
616 false, // visible_only, | 657 false, // visible_only, |
617 0, // no limit to number of results | 658 0, // no limit to number of results |
618 &state_list); | 659 &state_list); |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
694 | 735 |
695 if (report_boot_mode_) | 736 if (report_boot_mode_) |
696 GetBootMode(status); | 737 GetBootMode(status); |
697 | 738 |
698 if (report_location_) | 739 if (report_location_) |
699 GetLocation(status); | 740 GetLocation(status); |
700 | 741 |
701 if (report_network_interfaces_) | 742 if (report_network_interfaces_) |
702 GetNetworkInterfaces(status); | 743 GetNetworkInterfaces(status); |
703 | 744 |
704 if (report_users_) { | 745 if (report_users_) |
705 GetUsers(status); | 746 GetUsers(status); |
706 } | |
707 | 747 |
708 if (report_hardware_status_) | 748 if (report_hardware_status_) |
709 GetHardwareStatus(status); | 749 GetHardwareStatus(status); |
710 | 750 |
711 return (report_activity_times_ || | 751 return (report_activity_times_ || |
712 report_version_info_ || | 752 report_version_info_ || |
713 report_boot_mode_ || | 753 report_boot_mode_ || |
714 report_location_ || | 754 report_location_ || |
715 report_network_interfaces_ || | 755 report_network_interfaces_ || |
716 report_users_ || | 756 report_users_ || |
717 report_hardware_status_); | 757 report_hardware_status_); |
718 } | 758 } |
719 | 759 |
720 bool DeviceStatusCollector::GetDeviceSessionStatus( | 760 bool DeviceStatusCollector::GetDeviceSessionStatus( |
721 em::SessionStatusReportRequest* status) { | 761 em::SessionStatusReportRequest* status) { |
722 return false; | 762 // Only generate session status reports if session status reporting is |
| 763 // enabled. |
| 764 if (!report_session_status_) |
| 765 return false; |
| 766 |
| 767 scoped_ptr<const DeviceLocalAccount> account = |
| 768 GetAutoLaunchedKioskSessionInfo(); |
| 769 // Only generate session status reports if we are in an auto-launched kiosk |
| 770 // session. |
| 771 if (!account) |
| 772 return false; |
| 773 |
| 774 // Get the account ID associated with this user. |
| 775 status->set_device_local_account_id(account->account_id); |
| 776 em::AppStatus* app_status = status->add_installed_apps(); |
| 777 app_status->set_app_id(account->kiosk_app_id); |
| 778 |
| 779 // Look up the app and get the version. |
| 780 const std::string app_version = GetAppVersion(account->kiosk_app_id); |
| 781 if (app_version.empty()) { |
| 782 DLOG(ERROR) << "Unable to get version for extension: " |
| 783 << account->kiosk_app_id; |
| 784 } else { |
| 785 app_status->set_extension_version(app_version); |
| 786 } |
| 787 return true; |
| 788 } |
| 789 |
| 790 std::string DeviceStatusCollector::GetAppVersion( |
| 791 const std::string& kiosk_app_id) { |
| 792 Profile* const profile = |
| 793 chromeos::ProfileHelper::Get()->GetProfileByUser( |
| 794 user_manager::UserManager::Get()->GetActiveUser()); |
| 795 const extensions::ExtensionRegistry* const registry = |
| 796 extensions::ExtensionRegistry::Get(profile); |
| 797 const extensions::Extension* const extension = registry->GetExtensionById( |
| 798 kiosk_app_id, extensions::ExtensionRegistry::EVERYTHING); |
| 799 if (!extension) |
| 800 return std::string(); |
| 801 return extension->VersionString(); |
723 } | 802 } |
724 | 803 |
725 void DeviceStatusCollector::OnSubmittedSuccessfully() { | 804 void DeviceStatusCollector::OnSubmittedSuccessfully() { |
726 TrimStoredActivityPeriods(last_reported_day_, duration_for_last_reported_day_, | 805 TrimStoredActivityPeriods(last_reported_day_, duration_for_last_reported_day_, |
727 std::numeric_limits<int64>::max()); | 806 std::numeric_limits<int64>::max()); |
728 } | 807 } |
729 | 808 |
730 void DeviceStatusCollector::OnOSVersion(const std::string& version) { | 809 void DeviceStatusCollector::OnOSVersion(const std::string& version) { |
731 os_version_ = version; | 810 os_version_ = version; |
732 } | 811 } |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
793 ScheduleGeolocationUpdateRequest(); | 872 ScheduleGeolocationUpdateRequest(); |
794 } | 873 } |
795 | 874 |
796 void DeviceStatusCollector::ReceiveVolumeInfo( | 875 void DeviceStatusCollector::ReceiveVolumeInfo( |
797 const std::vector<em::VolumeInfo>& info) { | 876 const std::vector<em::VolumeInfo>& info) { |
798 if (report_hardware_status_) | 877 if (report_hardware_status_) |
799 volume_info_ = info; | 878 volume_info_ = info; |
800 } | 879 } |
801 | 880 |
802 } // namespace policy | 881 } // namespace policy |
OLD | NEW |