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 <limits> | 7 #include <limits> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
| 11 #include "base/location.h" | 11 #include "base/location.h" |
| 12 #include "base/logging.h" | 12 #include "base/logging.h" |
| 13 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
| 14 #include "base/prefs/pref_registry_simple.h" | 14 #include "base/prefs/pref_registry_simple.h" |
| 15 #include "base/prefs/pref_service.h" | 15 #include "base/prefs/pref_service.h" |
| 16 #include "base/strings/string_number_conversions.h" | 16 #include "base/strings/string_number_conversions.h" |
| 17 #include "base/values.h" | 17 #include "base/values.h" |
| 18 #include "chrome/browser/chrome_notification_types.h" | 18 #include "chrome/browser/chrome_notification_types.h" |
| 19 #include "chrome/browser/chromeos/settings/cros_settings.h" | 19 #include "chrome/browser/chromeos/settings/cros_settings.h" |
| 20 #include "chrome/browser/chromeos/settings/cros_settings_names.h" | 20 #include "chrome/browser/chromeos/settings/cros_settings_names.h" |
| 21 #include "chrome/browser/chromeos/system/statistics_provider.h" | 21 #include "chrome/browser/chromeos/system/statistics_provider.h" |
| 22 #include "chrome/browser/policy/proto/cloud/device_management_backend.pb.h" | 22 #include "chrome/browser/policy/proto/cloud/device_management_backend.pb.h" |
| 23 #include "chrome/browser/prefs/scoped_user_pref_update.h" | 23 #include "chrome/browser/prefs/scoped_user_pref_update.h" |
| 24 #include "chrome/common/chrome_version_info.h" | 24 #include "chrome/common/chrome_version_info.h" |
| 25 #include "chrome/common/pref_names.h" | 25 #include "chrome/common/pref_names.h" |
| 26 #include "chromeos/network/device_state.h" | 26 #include "chromeos/network/device_state.h" |
| 27 #include "chromeos/network/network_handler.h" | 27 #include "chromeos/network/network_handler.h" |
| 28 #include "chromeos/network/network_state_handler.h" | 28 #include "chromeos/network/network_state_handler.h" |
| 29 #include "content/public/browser/browser_thread.h" | 29 #include "content/public/browser/browser_thread.h" |
| 30 #include "content/public/browser/notification_details.h" | 30 #include "content/public/browser/notification_details.h" |
|
Lei Zhang
2013/09/18 05:00:53
Remove
| |
| 31 #include "content/public/browser/notification_source.h" | 31 #include "content/public/browser/notification_source.h" |
| 32 #include "third_party/cros_system_api/dbus/service_constants.h" | 32 #include "third_party/cros_system_api/dbus/service_constants.h" |
| 33 | 33 |
| 34 using base::Time; | 34 using base::Time; |
| 35 using base::TimeDelta; | 35 using base::TimeDelta; |
| 36 using chromeos::VersionLoader; | 36 using chromeos::VersionLoader; |
| 37 | 37 |
| 38 namespace em = enterprise_management; | 38 namespace em = enterprise_management; |
| 39 | 39 |
| 40 namespace { | 40 namespace { |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 141 base::Bind(&Context::GetLocationUpdate, context_.get()); | 141 base::Bind(&Context::GetLocationUpdate, context_.get()); |
| 142 } | 142 } |
| 143 idle_poll_timer_.Start(FROM_HERE, | 143 idle_poll_timer_.Start(FROM_HERE, |
| 144 TimeDelta::FromSeconds(kIdlePollIntervalSeconds), | 144 TimeDelta::FromSeconds(kIdlePollIntervalSeconds), |
| 145 this, &DeviceStatusCollector::CheckIdleState); | 145 this, &DeviceStatusCollector::CheckIdleState); |
| 146 | 146 |
| 147 cros_settings_ = chromeos::CrosSettings::Get(); | 147 cros_settings_ = chromeos::CrosSettings::Get(); |
| 148 | 148 |
| 149 // Watch for changes to the individual policies that control what the status | 149 // Watch for changes to the individual policies that control what the status |
| 150 // reports contain. | 150 // reports contain. |
| 151 cros_settings_->AddSettingsObserver(chromeos::kReportDeviceVersionInfo, this); | 151 version_info_subscription_ = cros_settings_->AddSettingsObserver( |
| 152 cros_settings_->AddSettingsObserver(chromeos::kReportDeviceActivityTimes, | 152 chromeos::kReportDeviceVersionInfo, |
| 153 this); | 153 base::Bind(&DeviceStatusCollector::UpdateReportingSettings, |
|
Mattias Nissler (ping if slow)
2013/09/18 09:09:48
This can probably be made more readable by declari
Avi (use Gerrit)
2013/09/18 16:41:44
Done.
| |
| 154 cros_settings_->AddSettingsObserver(chromeos::kReportDeviceBootMode, this); | 154 base::Unretained(this))); |
| 155 cros_settings_->AddSettingsObserver(chromeos::kReportDeviceLocation, this); | 155 activity_times_subscription_ = cros_settings_->AddSettingsObserver( |
| 156 cros_settings_->AddSettingsObserver(chromeos::kReportDeviceNetworkInterfaces, | 156 chromeos::kReportDeviceActivityTimes, |
| 157 this); | 157 base::Bind(&DeviceStatusCollector::UpdateReportingSettings, |
| 158 base::Unretained(this))); | |
| 159 boot_mode_subscription_ = cros_settings_->AddSettingsObserver( | |
| 160 chromeos::kReportDeviceBootMode, | |
| 161 base::Bind(&DeviceStatusCollector::UpdateReportingSettings, | |
| 162 base::Unretained(this))); | |
| 163 location_subscription_ = cros_settings_->AddSettingsObserver( | |
| 164 chromeos::kReportDeviceLocation, | |
| 165 base::Bind(&DeviceStatusCollector::UpdateReportingSettings, | |
| 166 base::Unretained(this))); | |
| 167 network_interfaces_subscription_ = cros_settings_->AddSettingsObserver( | |
| 168 chromeos::kReportDeviceNetworkInterfaces, | |
| 169 base::Bind(&DeviceStatusCollector::UpdateReportingSettings, | |
| 170 base::Unretained(this))); | |
| 158 | 171 |
| 159 // The last known location is persisted in local state. This makes location | 172 // The last known location is persisted in local state. This makes location |
| 160 // information available immediately upon startup and avoids the need to | 173 // information available immediately upon startup and avoids the need to |
| 161 // reacquire the location on every user session change or browser crash. | 174 // reacquire the location on every user session change or browser crash. |
| 162 content::Geoposition position; | 175 content::Geoposition position; |
| 163 std::string timestamp_str; | 176 std::string timestamp_str; |
| 164 int64 timestamp; | 177 int64 timestamp; |
| 165 const base::DictionaryValue* location = | 178 const base::DictionaryValue* location = |
| 166 local_state_->GetDictionary(prefs::kDeviceLocation); | 179 local_state_->GetDictionary(prefs::kDeviceLocation); |
| 167 if (location->GetDouble(kLatitude, &position.latitude) && | 180 if (location->GetDouble(kLatitude, &position.latitude) && |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 184 version_loader_.GetVersion( | 197 version_loader_.GetVersion( |
| 185 VersionLoader::VERSION_FULL, | 198 VersionLoader::VERSION_FULL, |
| 186 base::Bind(&DeviceStatusCollector::OnOSVersion, base::Unretained(this)), | 199 base::Bind(&DeviceStatusCollector::OnOSVersion, base::Unretained(this)), |
| 187 &tracker_); | 200 &tracker_); |
| 188 version_loader_.GetFirmware( | 201 version_loader_.GetFirmware( |
| 189 base::Bind(&DeviceStatusCollector::OnOSFirmware, base::Unretained(this)), | 202 base::Bind(&DeviceStatusCollector::OnOSFirmware, base::Unretained(this)), |
| 190 &tracker_); | 203 &tracker_); |
| 191 } | 204 } |
| 192 | 205 |
| 193 DeviceStatusCollector::~DeviceStatusCollector() { | 206 DeviceStatusCollector::~DeviceStatusCollector() { |
| 194 cros_settings_->RemoveSettingsObserver(chromeos::kReportDeviceVersionInfo, | |
| 195 this); | |
| 196 cros_settings_->RemoveSettingsObserver(chromeos::kReportDeviceActivityTimes, | |
| 197 this); | |
| 198 cros_settings_->RemoveSettingsObserver(chromeos::kReportDeviceBootMode, this); | |
| 199 cros_settings_->RemoveSettingsObserver(chromeos::kReportDeviceLocation, this); | |
| 200 cros_settings_->RemoveSettingsObserver( | |
| 201 chromeos::kReportDeviceNetworkInterfaces, this); | |
| 202 } | 207 } |
| 203 | 208 |
| 204 // static | 209 // static |
| 205 void DeviceStatusCollector::RegisterPrefs(PrefRegistrySimple* registry) { | 210 void DeviceStatusCollector::RegisterPrefs(PrefRegistrySimple* registry) { |
| 206 registry->RegisterDictionaryPref(prefs::kDeviceActivityTimes, | 211 registry->RegisterDictionaryPref(prefs::kDeviceActivityTimes, |
| 207 new base::DictionaryValue); | 212 new base::DictionaryValue); |
| 208 registry->RegisterDictionaryPref(prefs::kDeviceLocation, | 213 registry->RegisterDictionaryPref(prefs::kDeviceLocation, |
| 209 new base::DictionaryValue); | 214 new base::DictionaryValue); |
| 210 } | 215 } |
| 211 | 216 |
| (...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 492 } | 497 } |
| 493 | 498 |
| 494 void DeviceStatusCollector::OnOSVersion(const std::string& version) { | 499 void DeviceStatusCollector::OnOSVersion(const std::string& version) { |
| 495 os_version_ = version; | 500 os_version_ = version; |
| 496 } | 501 } |
| 497 | 502 |
| 498 void DeviceStatusCollector::OnOSFirmware(const std::string& version) { | 503 void DeviceStatusCollector::OnOSFirmware(const std::string& version) { |
| 499 firmware_version_ = version; | 504 firmware_version_ = version; |
| 500 } | 505 } |
| 501 | 506 |
| 502 void DeviceStatusCollector::Observe( | |
| 503 int type, | |
| 504 const content::NotificationSource& source, | |
| 505 const content::NotificationDetails& details) { | |
| 506 if (type == chrome::NOTIFICATION_SYSTEM_SETTING_CHANGED) | |
| 507 UpdateReportingSettings(); | |
| 508 else | |
| 509 NOTREACHED(); | |
| 510 } | |
| 511 | |
| 512 void DeviceStatusCollector::ScheduleGeolocationUpdateRequest() { | 507 void DeviceStatusCollector::ScheduleGeolocationUpdateRequest() { |
| 513 if (geolocation_update_timer_.IsRunning() || geolocation_update_in_progress_) | 508 if (geolocation_update_timer_.IsRunning() || geolocation_update_in_progress_) |
| 514 return; | 509 return; |
| 515 | 510 |
| 516 if (position_.Validate()) { | 511 if (position_.Validate()) { |
| 517 TimeDelta elapsed = GetCurrentTime() - position_.timestamp; | 512 TimeDelta elapsed = GetCurrentTime() - position_.timestamp; |
| 518 TimeDelta interval = | 513 TimeDelta interval = |
| 519 TimeDelta::FromSeconds(kGeolocationPollIntervalSeconds); | 514 TimeDelta::FromSeconds(kGeolocationPollIntervalSeconds); |
| 520 if (elapsed > interval) { | 515 if (elapsed > interval) { |
| 521 geolocation_update_in_progress_ = true; | 516 geolocation_update_in_progress_ = true; |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 557 location.SetDouble(kSpeed, position.speed); | 552 location.SetDouble(kSpeed, position.speed); |
| 558 location.SetString(kTimestamp, | 553 location.SetString(kTimestamp, |
| 559 base::Int64ToString(position.timestamp.ToInternalValue())); | 554 base::Int64ToString(position.timestamp.ToInternalValue())); |
| 560 local_state_->Set(prefs::kDeviceLocation, location); | 555 local_state_->Set(prefs::kDeviceLocation, location); |
| 561 } | 556 } |
| 562 | 557 |
| 563 ScheduleGeolocationUpdateRequest(); | 558 ScheduleGeolocationUpdateRequest(); |
| 564 } | 559 } |
| 565 | 560 |
| 566 } // namespace policy | 561 } // namespace policy |
| OLD | NEW |