| 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/policy/device_status_collector.h" | 5 #include "chrome/browser/policy/device_status_collector.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
| 9 #include "base/location.h" | 9 #include "base/location.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 86 max_stored_future_activity_days_(kMaxStoredFutureActivityDays), | 86 max_stored_future_activity_days_(kMaxStoredFutureActivityDays), |
| 87 local_state_(local_state), | 87 local_state_(local_state), |
| 88 last_idle_check_(Time()), | 88 last_idle_check_(Time()), |
| 89 geolocation_update_in_progress_(false), | 89 geolocation_update_in_progress_(false), |
| 90 statistics_provider_(provider), | 90 statistics_provider_(provider), |
| 91 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)), | 91 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)), |
| 92 location_update_requester_(location_update_requester), | 92 location_update_requester_(location_update_requester), |
| 93 report_version_info_(false), | 93 report_version_info_(false), |
| 94 report_activity_times_(false), | 94 report_activity_times_(false), |
| 95 report_boot_mode_(false), | 95 report_boot_mode_(false), |
| 96 report_location_(false) { | 96 report_location_(false) {} |
| 97 |
| 98 DeviceStatusCollector::~DeviceStatusCollector() { |
| 99 cros_settings_->RemoveSettingsObserver(chromeos::kReportDeviceVersionInfo, |
| 100 this); |
| 101 cros_settings_->RemoveSettingsObserver(chromeos::kReportDeviceActivityTimes, |
| 102 this); |
| 103 cros_settings_->RemoveSettingsObserver(chromeos::kReportDeviceBootMode, this); |
| 104 cros_settings_->RemoveSettingsObserver(chromeos::kReportDeviceLocation, this); |
| 105 } |
| 106 |
| 107 void DeviceStatusCollector::Init() { |
| 97 if (!location_update_requester_) | 108 if (!location_update_requester_) |
| 98 location_update_requester_ = &content::RequestLocationUpdate; | 109 location_update_requester_ = &content::RequestLocationUpdate; |
| 99 idle_poll_timer_.Start(FROM_HERE, | 110 idle_poll_timer_.Start(FROM_HERE, |
| 100 TimeDelta::FromSeconds(kIdlePollIntervalSeconds), | 111 TimeDelta::FromSeconds(kIdlePollIntervalSeconds), |
| 101 this, &DeviceStatusCollector::CheckIdleState); | 112 this, &DeviceStatusCollector::CheckIdleState); |
| 102 | 113 |
| 103 cros_settings_ = chromeos::CrosSettings::Get(); | 114 cros_settings_ = chromeos::CrosSettings::Get(); |
| 104 | 115 |
| 105 // Watch for changes to the individual policies that control what the status | 116 // Watch for changes to the individual policies that control what the status |
| 106 // reports contain. | 117 // reports contain. |
| (...skipping 30 matching lines...) Expand all Loading... |
| 137 // Get the the OS and firmware version info. | 148 // Get the the OS and firmware version info. |
| 138 version_loader_.GetVersion(&consumer_, | 149 version_loader_.GetVersion(&consumer_, |
| 139 base::Bind(&DeviceStatusCollector::OnOSVersion, | 150 base::Bind(&DeviceStatusCollector::OnOSVersion, |
| 140 base::Unretained(this)), | 151 base::Unretained(this)), |
| 141 VersionLoader::VERSION_FULL); | 152 VersionLoader::VERSION_FULL); |
| 142 version_loader_.GetFirmware(&consumer_, | 153 version_loader_.GetFirmware(&consumer_, |
| 143 base::Bind(&DeviceStatusCollector::OnOSFirmware, | 154 base::Bind(&DeviceStatusCollector::OnOSFirmware, |
| 144 base::Unretained(this))); | 155 base::Unretained(this))); |
| 145 } | 156 } |
| 146 | 157 |
| 147 DeviceStatusCollector::~DeviceStatusCollector() { | |
| 148 cros_settings_->RemoveSettingsObserver(chromeos::kReportDeviceVersionInfo, | |
| 149 this); | |
| 150 cros_settings_->RemoveSettingsObserver(chromeos::kReportDeviceActivityTimes, | |
| 151 this); | |
| 152 cros_settings_->RemoveSettingsObserver(chromeos::kReportDeviceBootMode, this); | |
| 153 cros_settings_->RemoveSettingsObserver(chromeos::kReportDeviceLocation, this); | |
| 154 } | |
| 155 | |
| 156 // static | 158 // static |
| 157 void DeviceStatusCollector::RegisterPrefs(PrefService* local_state) { | 159 void DeviceStatusCollector::RegisterPrefs(PrefService* local_state) { |
| 158 local_state->RegisterDictionaryPref(prefs::kDeviceActivityTimes, | 160 local_state->RegisterDictionaryPref(prefs::kDeviceActivityTimes, |
| 159 new base::DictionaryValue); | 161 new base::DictionaryValue); |
| 160 local_state->RegisterDictionaryPref(prefs::kDeviceLocation, | 162 local_state->RegisterDictionaryPref(prefs::kDeviceLocation, |
| 161 new base::DictionaryValue); | 163 new base::DictionaryValue); |
| 162 } | 164 } |
| 163 | 165 |
| 164 void DeviceStatusCollector::CheckIdleState() { | 166 void DeviceStatusCollector::CheckIdleState() { |
| 165 CalculateIdleState(kIdleStateThresholdSeconds, | 167 CalculateIdleState(kIdleStateThresholdSeconds, |
| (...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 385 UpdateReportingSettings(); | 387 UpdateReportingSettings(); |
| 386 else | 388 else |
| 387 NOTREACHED(); | 389 NOTREACHED(); |
| 388 } | 390 } |
| 389 | 391 |
| 390 void DeviceStatusCollector::ScheduleGeolocationUpdateRequest() { | 392 void DeviceStatusCollector::ScheduleGeolocationUpdateRequest() { |
| 391 if (geolocation_update_timer_.IsRunning() || geolocation_update_in_progress_) | 393 if (geolocation_update_timer_.IsRunning() || geolocation_update_in_progress_) |
| 392 return; | 394 return; |
| 393 | 395 |
| 394 if (position_.Validate()) { | 396 if (position_.Validate()) { |
| 395 TimeDelta elapsed = Time::Now() - position_.timestamp; | 397 TimeDelta elapsed = GetCurrentTime() - position_.timestamp; |
| 396 TimeDelta interval = | 398 TimeDelta interval = |
| 397 TimeDelta::FromSeconds(kGeolocationPollIntervalSeconds); | 399 TimeDelta::FromSeconds(kGeolocationPollIntervalSeconds); |
| 398 if (elapsed > interval) { | 400 if (elapsed > interval) { |
| 399 geolocation_update_in_progress_ = true; | 401 geolocation_update_in_progress_ = true; |
| 400 location_update_requester_(base::Bind( | 402 location_update_requester_(base::Bind( |
| 401 &DeviceStatusCollector::ReceiveGeolocationUpdate, | 403 &DeviceStatusCollector::ReceiveGeolocationUpdate, |
| 402 weak_factory_.GetWeakPtr())); | 404 weak_factory_.GetWeakPtr())); |
| 403 } else { | 405 } else { |
| 404 geolocation_update_timer_.Start( | 406 geolocation_update_timer_.Start( |
| 405 FROM_HERE, | 407 FROM_HERE, |
| (...skipping 30 matching lines...) Expand all Loading... |
| 436 location.SetDouble(kSpeed, position.speed); | 438 location.SetDouble(kSpeed, position.speed); |
| 437 location.SetString(kTimestamp, | 439 location.SetString(kTimestamp, |
| 438 base::Int64ToString(position.timestamp.ToInternalValue())); | 440 base::Int64ToString(position.timestamp.ToInternalValue())); |
| 439 local_state_->Set(prefs::kDeviceLocation, location); | 441 local_state_->Set(prefs::kDeviceLocation, location); |
| 440 } | 442 } |
| 441 | 443 |
| 442 ScheduleGeolocationUpdateRequest(); | 444 ScheduleGeolocationUpdateRequest(); |
| 443 } | 445 } |
| 444 | 446 |
| 445 } // namespace policy | 447 } // namespace policy |
| OLD | NEW |