Chromium Code Reviews| Index: chrome/browser/policy/device_status_collector.cc |
| diff --git a/chrome/browser/policy/device_status_collector.cc b/chrome/browser/policy/device_status_collector.cc |
| index 5a1be4a47e71c915d8cacb835f309389be5cc942..d3e5fe0c85bfac626bf1652a95cc90bd9d103a9f 100644 |
| --- a/chrome/browser/policy/device_status_collector.cc |
| +++ b/chrome/browser/policy/device_status_collector.cc |
| @@ -4,18 +4,30 @@ |
| #include "chrome/browser/policy/device_status_collector.h" |
| +#include <string> |
| + |
| #include "base/bind.h" |
| -#include "base/callback.h" |
| +#include "base/bind_helpers.h" |
| +#include "base/basictypes.h" |
| +#include "base/location.h" |
| +#include "base/logging.h" |
| +#include "base/memory/scoped_ptr.h" |
| #include "base/string_number_conversions.h" |
| +#include "base/values.h" |
| #include "chrome/browser/chromeos/cros_settings.h" |
| #include "chrome/browser/chromeos/cros_settings_names.h" |
| #include "chrome/browser/chromeos/system/statistics_provider.h" |
| +#include "chrome/browser/policy/device_status_location_helper.h" |
| #include "chrome/browser/policy/proto/device_management_backend.pb.h" |
| #include "chrome/browser/prefs/pref_service.h" |
| #include "chrome/browser/prefs/scoped_user_pref_update.h" |
| #include "chrome/common/chrome_notification_types.h" |
| #include "chrome/common/chrome_version_info.h" |
| #include "chrome/common/pref_names.h" |
| +#include "content/browser/geolocation/geolocation_provider.h" |
| +#include "content/common/geoposition.h" |
| +#include "content/public/browser/notification_details.h" |
| +#include "content/public/browser/notification_source.h" |
| using base::Time; |
| using base::TimeDelta; |
| @@ -61,9 +73,12 @@ DeviceStatusCollector::DeviceStatusCollector( |
| local_state_(local_state), |
| last_idle_check_(Time()), |
| statistics_provider_(provider), |
| + geolocation_provider_for_test_(NULL), |
| + location_helper_(NULL), |
| report_version_info_(false), |
| report_activity_times_(false), |
| - report_boot_mode_(false) { |
| + report_boot_mode_(false), |
| + report_location_(false) { |
| timer_.Start(FROM_HERE, |
| TimeDelta::FromSeconds(kPollIntervalSeconds), |
| this, &DeviceStatusCollector::CheckIdleState); |
| @@ -76,6 +91,7 @@ DeviceStatusCollector::DeviceStatusCollector( |
| cros_settings_->AddSettingsObserver(chromeos::kReportDeviceActivityTimes, |
| this); |
| cros_settings_->AddSettingsObserver(chromeos::kReportDeviceBootMode, this); |
| + cros_settings_->AddSettingsObserver(chromeos::kReportDeviceLocation, this); |
| // Fetch the current values of the policies. |
| UpdateReportingSettings(); |
| @@ -96,12 +112,17 @@ DeviceStatusCollector::~DeviceStatusCollector() { |
| cros_settings_->RemoveSettingsObserver(chromeos::kReportDeviceActivityTimes, |
| this); |
| cros_settings_->RemoveSettingsObserver(chromeos::kReportDeviceBootMode, this); |
| + cros_settings_->RemoveSettingsObserver(chromeos::kReportDeviceLocation, this); |
| + |
| + if (location_helper_) |
| + location_helper_->Destruct(); |
| } |
| // static |
| void DeviceStatusCollector::RegisterPrefs(PrefService* local_state) { |
| local_state->RegisterDictionaryPref(prefs::kDeviceActivityTimes, |
| new DictionaryValue); |
| + DeviceStatusLocationHelper::RegisterPrefs(local_state); |
| } |
| void DeviceStatusCollector::CheckIdleState() { |
| @@ -110,6 +131,13 @@ void DeviceStatusCollector::CheckIdleState() { |
| base::Unretained(this))); |
| } |
| +void DeviceStatusCollector::SetGeolocationProviderForTest( |
| + GeolocationProvider* provider) { |
| + geolocation_provider_for_test_ = provider; |
| + if (location_helper_) |
| + location_helper_->SetGeolocationProviderForTest(provider); |
| +} |
| + |
| void DeviceStatusCollector::UpdateReportingSettings() { |
| // Attempt to fetch the current value of the reporting settings. |
| // If trusted values are not available, register this function to be called |
| @@ -125,6 +153,24 @@ void DeviceStatusCollector::UpdateReportingSettings() { |
| chromeos::kReportDeviceActivityTimes, &report_activity_times_); |
| cros_settings_->GetBoolean( |
| chromeos::kReportDeviceBootMode, &report_boot_mode_); |
| + cros_settings_->GetBoolean( |
| + chromeos::kReportDeviceLocation, &report_location_); |
| + |
| + if (report_location_) { |
| + if (!location_helper_) { |
| + location_helper_ = new DeviceStatusLocationHelper(local_state_); |
| + if (geolocation_provider_for_test_) { |
| + location_helper_->SetGeolocationProviderForTest( |
| + geolocation_provider_for_test_); |
| + } |
| + } |
| + } else { |
| + if (location_helper_) { |
| + location_helper_->Destruct(); |
| + location_helper_ = NULL; |
| + } |
| + local_state_->ClearPref(prefs::kDeviceLocation); |
| + } |
| } |
| Time DeviceStatusCollector::GetCurrentTime() { |
| @@ -258,6 +304,37 @@ void DeviceStatusCollector::GetBootMode( |
| } |
| } |
| +void DeviceStatusCollector::GetLocation( |
| + em::DeviceStatusReportRequest* request) { |
|
Joao da Silva
2012/04/23 10:19:57
Nit: indent (4 spaces)
bartfab (slow)
2012/04/23 12:21:28
Done.
|
| + em::DeviceLocation* location = request->mutable_device_location(); |
| + if (!location_helper_) { |
| + location->set_error_code( |
| + em::DeviceLocation::ERROR_CODE_POSITION_UNAVAILABLE); |
| + } else { |
| + const Geoposition& position = location_helper_->GetPosition(); |
| + if (!position.IsValidFix()) { |
| + location->set_error_code( |
| + em::DeviceLocation::ERROR_CODE_POSITION_UNAVAILABLE); |
| + location->set_error_message(position.error_message); |
| + } else { |
| + location->set_latitude(position.latitude); |
| + location->set_longitude(position.longitude); |
| + location->set_accuracy(position.accuracy); |
| + location->set_timestamp( |
| + (position.timestamp - Time::UnixEpoch()).InMilliseconds()); |
| + if (position.is_valid_altitude()) |
| + location->set_altitude(position.altitude); |
| + if (position.is_valid_altitude_accuracy()) |
| + location->set_altitude_accuracy(position.altitude_accuracy); |
| + if (position.is_valid_heading()) |
| + location->set_heading(position.heading); |
| + if (position.is_valid_speed()) |
| + location->set_speed(position.speed); |
| + location->set_error_code(em::DeviceLocation::ERROR_CODE_NONE); |
| + } |
| + } |
| +} |
| + |
| void DeviceStatusCollector::GetStatus(em::DeviceStatusReportRequest* request) { |
| if (report_activity_times_) |
| GetActivityTimes(request); |
| @@ -267,6 +344,9 @@ void DeviceStatusCollector::GetStatus(em::DeviceStatusReportRequest* request) { |
| if (report_boot_mode_) |
| GetBootMode(request); |
| + |
| + if (report_location_) |
| + GetLocation(request); |
| } |
| void DeviceStatusCollector::OnOSVersion(VersionLoader::Handle handle, |