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 #include <sys/statvfs.h> | 9 #include <sys/statvfs.h> |
| 10 |
10 #include <cstdio> | 11 #include <cstdio> |
11 #include <limits> | 12 #include <limits> |
| 13 #include <memory> |
12 #include <sstream> | 14 #include <sstream> |
13 | 15 |
14 #include "base/bind.h" | 16 #include "base/bind.h" |
15 #include "base/bind_helpers.h" | 17 #include "base/bind_helpers.h" |
16 #include "base/files/file_enumerator.h" | 18 #include "base/files/file_enumerator.h" |
17 #include "base/files/file_util.h" | 19 #include "base/files/file_util.h" |
18 #include "base/format_macros.h" | 20 #include "base/format_macros.h" |
19 #include "base/location.h" | 21 #include "base/location.h" |
20 #include "base/logging.h" | 22 #include "base/logging.h" |
21 #include "base/macros.h" | 23 #include "base/macros.h" |
22 #include "base/memory/scoped_ptr.h" | 24 #include "base/memory/ptr_util.h" |
23 #include "base/posix/eintr_wrapper.h" | 25 #include "base/posix/eintr_wrapper.h" |
24 #include "base/strings/string_number_conversions.h" | 26 #include "base/strings/string_number_conversions.h" |
25 #include "base/strings/string_util.h" | 27 #include "base/strings/string_util.h" |
26 #include "base/sys_info.h" | 28 #include "base/sys_info.h" |
27 #include "base/task_runner_util.h" | 29 #include "base/task_runner_util.h" |
28 #include "base/values.h" | 30 #include "base/values.h" |
29 #include "chrome/browser/browser_process.h" | 31 #include "chrome/browser/browser_process.h" |
30 #include "chrome/browser/chromeos/app_mode/kiosk_app_manager.h" | 32 #include "chrome/browser/chromeos/app_mode/kiosk_app_manager.h" |
31 #include "chrome/browser/chromeos/login/users/chrome_user_manager.h" | 33 #include "chrome/browser/chromeos/login/users/chrome_user_manager.h" |
32 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h" | 34 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h" |
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
206 } | 208 } |
207 } | 209 } |
208 } | 210 } |
209 return contents; | 211 return contents; |
210 } | 212 } |
211 | 213 |
212 // Returns the DeviceLocalAccount associated with the current kiosk session. | 214 // Returns the DeviceLocalAccount associated with the current kiosk session. |
213 // Returns null if there is no active kiosk session, or if that kiosk | 215 // Returns null if there is no active kiosk session, or if that kiosk |
214 // session has been removed from policy since the session started, in which | 216 // session has been removed from policy since the session started, in which |
215 // case we won't report its status). | 217 // case we won't report its status). |
216 scoped_ptr<policy::DeviceLocalAccount> | 218 std::unique_ptr<policy::DeviceLocalAccount> GetCurrentKioskDeviceLocalAccount( |
217 GetCurrentKioskDeviceLocalAccount(chromeos::CrosSettings* settings) { | 219 chromeos::CrosSettings* settings) { |
218 if (!user_manager::UserManager::Get()->IsLoggedInAsKioskApp()) | 220 if (!user_manager::UserManager::Get()->IsLoggedInAsKioskApp()) |
219 return scoped_ptr<policy::DeviceLocalAccount>(); | 221 return std::unique_ptr<policy::DeviceLocalAccount>(); |
220 const user_manager::User* const user = | 222 const user_manager::User* const user = |
221 user_manager::UserManager::Get()->GetActiveUser(); | 223 user_manager::UserManager::Get()->GetActiveUser(); |
222 const std::vector<policy::DeviceLocalAccount> accounts = | 224 const std::vector<policy::DeviceLocalAccount> accounts = |
223 policy::GetDeviceLocalAccounts(settings); | 225 policy::GetDeviceLocalAccounts(settings); |
224 | 226 |
225 for (const auto& device_local_account : accounts) { | 227 for (const auto& device_local_account : accounts) { |
226 if (AccountId::FromUserEmail(device_local_account.user_id) == | 228 if (AccountId::FromUserEmail(device_local_account.user_id) == |
227 user->GetAccountId()) { | 229 user->GetAccountId()) { |
228 return make_scoped_ptr( | 230 return base::WrapUnique( |
229 new policy::DeviceLocalAccount(device_local_account)); | 231 new policy::DeviceLocalAccount(device_local_account)); |
230 } | 232 } |
231 } | 233 } |
232 LOG(WARNING) << "Kiosk app not found in list of device-local accounts"; | 234 LOG(WARNING) << "Kiosk app not found in list of device-local accounts"; |
233 return scoped_ptr<policy::DeviceLocalAccount>(); | 235 return std::unique_ptr<policy::DeviceLocalAccount>(); |
234 } | 236 } |
235 | 237 |
236 } // namespace | 238 } // namespace |
237 | 239 |
238 namespace policy { | 240 namespace policy { |
239 | 241 |
240 DeviceStatusCollector::DeviceStatusCollector( | 242 DeviceStatusCollector::DeviceStatusCollector( |
241 PrefService* local_state, | 243 PrefService* local_state, |
242 chromeos::system::StatisticsProvider* provider, | 244 chromeos::system::StatisticsProvider* provider, |
243 const LocationUpdateRequester& location_update_requester, | 245 const LocationUpdateRequester& location_update_requester, |
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
448 TrimStoredActivityPeriods(TimestampToDayKey(min_time), 0, | 450 TrimStoredActivityPeriods(TimestampToDayKey(min_time), 0, |
449 TimestampToDayKey(max_time)); | 451 TimestampToDayKey(max_time)); |
450 } | 452 } |
451 | 453 |
452 void DeviceStatusCollector::TrimStoredActivityPeriods(int64_t min_day_key, | 454 void DeviceStatusCollector::TrimStoredActivityPeriods(int64_t min_day_key, |
453 int min_day_trim_duration, | 455 int min_day_trim_duration, |
454 int64_t max_day_key) { | 456 int64_t max_day_key) { |
455 const base::DictionaryValue* activity_times = | 457 const base::DictionaryValue* activity_times = |
456 local_state_->GetDictionary(prefs::kDeviceActivityTimes); | 458 local_state_->GetDictionary(prefs::kDeviceActivityTimes); |
457 | 459 |
458 scoped_ptr<base::DictionaryValue> copy(activity_times->DeepCopy()); | 460 std::unique_ptr<base::DictionaryValue> copy(activity_times->DeepCopy()); |
459 for (base::DictionaryValue::Iterator it(*activity_times); !it.IsAtEnd(); | 461 for (base::DictionaryValue::Iterator it(*activity_times); !it.IsAtEnd(); |
460 it.Advance()) { | 462 it.Advance()) { |
461 int64_t timestamp; | 463 int64_t timestamp; |
462 if (base::StringToInt64(it.key(), ×tamp)) { | 464 if (base::StringToInt64(it.key(), ×tamp)) { |
463 // Remove data that is too old, or too far in the future. | 465 // Remove data that is too old, or too far in the future. |
464 if (timestamp >= min_day_key && timestamp < max_day_key) { | 466 if (timestamp >= min_day_key && timestamp < max_day_key) { |
465 if (timestamp == min_day_key) { | 467 if (timestamp == min_day_key) { |
466 int new_activity_duration = 0; | 468 int new_activity_duration = 0; |
467 if (it.value().GetAsInteger(&new_activity_duration)) { | 469 if (it.value().GetAsInteger(&new_activity_duration)) { |
468 new_activity_duration = | 470 new_activity_duration = |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
524 now); | 526 now); |
525 } else { | 527 } else { |
526 AddActivePeriod(last_idle_check_, now); | 528 AddActivePeriod(last_idle_check_, now); |
527 } | 529 } |
528 | 530 |
529 PruneStoredActivityPeriods(now); | 531 PruneStoredActivityPeriods(now); |
530 } | 532 } |
531 last_idle_check_ = now; | 533 last_idle_check_ = now; |
532 } | 534 } |
533 | 535 |
534 scoped_ptr<DeviceLocalAccount> | 536 std::unique_ptr<DeviceLocalAccount> |
535 DeviceStatusCollector::GetAutoLaunchedKioskSessionInfo() { | 537 DeviceStatusCollector::GetAutoLaunchedKioskSessionInfo() { |
536 scoped_ptr<DeviceLocalAccount> account = | 538 std::unique_ptr<DeviceLocalAccount> account = |
537 GetCurrentKioskDeviceLocalAccount(cros_settings_); | 539 GetCurrentKioskDeviceLocalAccount(cros_settings_); |
538 if (account) { | 540 if (account) { |
539 chromeos::KioskAppManager::App current_app; | 541 chromeos::KioskAppManager::App current_app; |
540 if (chromeos::KioskAppManager::Get()->GetApp(account->kiosk_app_id, | 542 if (chromeos::KioskAppManager::Get()->GetApp(account->kiosk_app_id, |
541 ¤t_app) && | 543 ¤t_app) && |
542 current_app.was_auto_launched_with_zero_delay) { | 544 current_app.was_auto_launched_with_zero_delay) { |
543 return account; | 545 return account; |
544 } | 546 } |
545 } | 547 } |
546 // No auto-launched kiosk session active. | 548 // No auto-launched kiosk session active. |
547 return scoped_ptr<DeviceLocalAccount>(); | 549 return std::unique_ptr<DeviceLocalAccount>(); |
548 } | 550 } |
549 | 551 |
550 void DeviceStatusCollector::SampleHardwareStatus() { | 552 void DeviceStatusCollector::SampleHardwareStatus() { |
551 // If hardware reporting has been disabled, do nothing here. | 553 // If hardware reporting has been disabled, do nothing here. |
552 if (!report_hardware_status_) | 554 if (!report_hardware_status_) |
553 return; | 555 return; |
554 | 556 |
555 // Create list of mounted disk volumes to query status. | 557 // Create list of mounted disk volumes to query status. |
556 std::vector<storage::MountPoints::MountPointInfo> external_mount_points; | 558 std::vector<storage::MountPoints::MountPointInfo> external_mount_points; |
557 storage::ExternalMountPoints::GetSystemInstance()->AddMountPointInfosTo( | 559 storage::ExternalMountPoints::GetSystemInstance()->AddMountPointInfosTo( |
(...skipping 376 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
934 report_hardware_status_); | 936 report_hardware_status_); |
935 } | 937 } |
936 | 938 |
937 bool DeviceStatusCollector::GetDeviceSessionStatus( | 939 bool DeviceStatusCollector::GetDeviceSessionStatus( |
938 em::SessionStatusReportRequest* status) { | 940 em::SessionStatusReportRequest* status) { |
939 // Only generate session status reports if session status reporting is | 941 // Only generate session status reports if session status reporting is |
940 // enabled. | 942 // enabled. |
941 if (!report_session_status_) | 943 if (!report_session_status_) |
942 return false; | 944 return false; |
943 | 945 |
944 scoped_ptr<const DeviceLocalAccount> account = | 946 std::unique_ptr<const DeviceLocalAccount> account = |
945 GetAutoLaunchedKioskSessionInfo(); | 947 GetAutoLaunchedKioskSessionInfo(); |
946 // Only generate session status reports if we are in an auto-launched kiosk | 948 // Only generate session status reports if we are in an auto-launched kiosk |
947 // session. | 949 // session. |
948 if (!account) | 950 if (!account) |
949 return false; | 951 return false; |
950 | 952 |
951 // Get the account ID associated with this user. | 953 // Get the account ID associated with this user. |
952 status->set_device_local_account_id(account->account_id); | 954 status->set_device_local_account_id(account->account_id); |
953 em::AppStatus* app_status = status->add_installed_apps(); | 955 em::AppStatus* app_status = status->add_installed_apps(); |
954 app_status->set_app_id(account->kiosk_app_id); | 956 app_status->set_app_id(account->kiosk_app_id); |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1049 ScheduleGeolocationUpdateRequest(); | 1051 ScheduleGeolocationUpdateRequest(); |
1050 } | 1052 } |
1051 | 1053 |
1052 void DeviceStatusCollector::ReceiveVolumeInfo( | 1054 void DeviceStatusCollector::ReceiveVolumeInfo( |
1053 const std::vector<em::VolumeInfo>& info) { | 1055 const std::vector<em::VolumeInfo>& info) { |
1054 if (report_hardware_status_) | 1056 if (report_hardware_status_) |
1055 volume_info_ = info; | 1057 volume_info_ = info; |
1056 } | 1058 } |
1057 | 1059 |
1058 } // namespace policy | 1060 } // namespace policy |
OLD | NEW |