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