15821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Copyright (c) 2012 The Chromium Authors. All rights reserved. 25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be 35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// found in the LICENSE file. 45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 52a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "chrome/browser/chromeos/policy/device_status_collector.h" 62a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 72a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include <limits> 85821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 95821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/bind.h" 105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/bind_helpers.h" 11f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)#include "base/command_line.h" 125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/location.h" 135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/logging.h" 145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/memory/scoped_ptr.h" 152a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "base/prefs/pref_registry_simple.h" 162a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "base/prefs/pref_service.h" 171e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#include "base/prefs/scoped_user_pref_update.h" 182a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "base/strings/string_number_conversions.h" 195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/values.h" 201e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#include "chrome/browser/browser_process.h" 211e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#include "chrome/browser/chromeos/login/user.h" 221e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#include "chrome/browser/chromeos/login/user_manager.h" 235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/chromeos/settings/cros_settings.h" 241e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#include "chrome/browser/policy/browser_policy_connector.h" 255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/common/chrome_version_info.h" 265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/common/pref_names.h" 27f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)#include "chromeos/chromeos_switches.h" 287dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch#include "chromeos/network/device_state.h" 297dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch#include "chromeos/network/network_handler.h" 307dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch#include "chromeos/network/network_state_handler.h" 314e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)#include "chromeos/settings/cros_settings_names.h" 324e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)#include "chromeos/system/statistics_provider.h" 33a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)#include "components/policy/core/common/cloud/cloud_policy_constants.h" 34b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)#include "content/public/browser/browser_thread.h" 35a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)#include "policy/proto/device_management_backend.pb.h" 367dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch#include "third_party/cros_system_api/dbus/service_constants.h" 375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)using base::Time; 395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)using base::TimeDelta; 405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)using chromeos::VersionLoader; 415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace em = enterprise_management; 435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace { 455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// How many seconds of inactivity triggers the idle state. 462a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)const int kIdleStateThresholdSeconds = 300; 475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// How many days in the past to store active periods for. 495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)const unsigned int kMaxStoredPastActivityDays = 30; 505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// How many days in the future to store active periods for. 525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)const unsigned int kMaxStoredFutureActivityDays = 2; 535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// How often, in seconds, to update the device location. 555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)const unsigned int kGeolocationPollIntervalSeconds = 30 * 60; 565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)const int64 kMillisecondsPerDay = Time::kMicrosecondsPerDay / 1000; 585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 597dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch// Keys for the geolocation status dictionary in local state. 605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)const char kLatitude[] = "latitude"; 615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)const char kLongitude[] = "longitude"; 625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)const char kAltitude[] = "altitude"; 635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)const char kAccuracy[] = "accuracy"; 645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)const char kAltitudeAccuracy[] = "altitude_accuracy"; 655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)const char kHeading[] = "heading"; 665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)const char kSpeed[] = "speed"; 675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)const char kTimestamp[] = "timestamp"; 685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 692a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// Determine the day key (milliseconds since epoch for corresponding day in UTC) 702a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// for a given |timestamp|. 712a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)int64 TimestampToDayKey(Time timestamp) { 722a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) Time::Exploded exploded; 732a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) timestamp.LocalMidnight().LocalExplode(&exploded); 742a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) return (Time::FromUTCExploded(exploded) - Time::UnixEpoch()).InMilliseconds(); 755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 771e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)// Maximum number of users to report. 781e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)const int kMaxUserCount = 5; 791e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} // namespace 815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace policy { 835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 84b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)DeviceStatusCollector::Context::Context() { 85b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)} 86b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) 87b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)DeviceStatusCollector::Context::~Context() { 88b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)} 89b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) 90b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)void DeviceStatusCollector::Context::GetLocationUpdate( 91b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) const content::GeolocationProvider::LocationUpdateCallback& callback) { 92b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) owner_callback_ = callback; 93b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) content::BrowserThread::PostTask( 94b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) content::BrowserThread::IO, 95b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) FROM_HERE, 96b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) base::Bind(&DeviceStatusCollector::Context::GetLocationUpdateInternal, 97b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) this)); 98b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)} 99b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) 100b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)void DeviceStatusCollector::Context::GetLocationUpdateInternal() { 101b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) our_callback_ = base::Bind( 102b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) &DeviceStatusCollector::Context::OnLocationUpdate, this); 103b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) content::GeolocationProvider::GetInstance()->AddLocationUpdateCallback( 104b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) our_callback_, true); 105b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)} 106b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) 107b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)void DeviceStatusCollector::Context::OnLocationUpdate( 108b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) const content::Geoposition& geoposition) { 109b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) content::GeolocationProvider::GetInstance()->RemoveLocationUpdateCallback( 110b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) our_callback_); 111b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) our_callback_.Reset(); 112b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) content::BrowserThread::PostTask( 113b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) content::BrowserThread::UI, 114b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) FROM_HERE, 115b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) base::Bind(&DeviceStatusCollector::Context::CallCollector, 116b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) this, geoposition)); 117b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)} 118b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) 119b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)void DeviceStatusCollector::Context::CallCollector( 120b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) const content::Geoposition& geoposition) { 121b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) owner_callback_.Run(geoposition); 122b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) owner_callback_.Reset(); 123b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)} 124b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) 1255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)DeviceStatusCollector::DeviceStatusCollector( 1265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) PrefService* local_state, 1275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) chromeos::system::StatisticsProvider* provider, 128b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) LocationUpdateRequester* location_update_requester) 1295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) : max_stored_past_activity_days_(kMaxStoredPastActivityDays), 1305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) max_stored_future_activity_days_(kMaxStoredFutureActivityDays), 1315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) local_state_(local_state), 1325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) last_idle_check_(Time()), 1332a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) last_reported_day_(0), 1342a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) duration_for_last_reported_day_(0), 1355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) geolocation_update_in_progress_(false), 1365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) statistics_provider_(provider), 137c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) weak_factory_(this), 1385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) report_version_info_(false), 1395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) report_activity_times_(false), 1405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) report_boot_mode_(false), 141b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) report_location_(false), 1427dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch report_network_interfaces_(false), 1431e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) report_users_(false), 144b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) context_(new Context()) { 145b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) if (location_update_requester) { 146b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) location_update_requester_ = *location_update_requester; 147b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) } else { 148b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) location_update_requester_ = 149b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) base::Bind(&Context::GetLocationUpdate, context_.get()); 150b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) } 1515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) idle_poll_timer_.Start(FROM_HERE, 1525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) TimeDelta::FromSeconds(kIdlePollIntervalSeconds), 1535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) this, &DeviceStatusCollector::CheckIdleState); 1545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) cros_settings_ = chromeos::CrosSettings::Get(); 1565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Watch for changes to the individual policies that control what the status 1585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // reports contain. 15968043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) base::Closure callback = 16068043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) base::Bind(&DeviceStatusCollector::UpdateReportingSettings, 16168043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) base::Unretained(this)); 16268043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) version_info_subscription_ = cros_settings_->AddSettingsObserver( 16368043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) chromeos::kReportDeviceVersionInfo, callback); 16468043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) activity_times_subscription_ = cros_settings_->AddSettingsObserver( 16568043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) chromeos::kReportDeviceActivityTimes, callback); 16668043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) boot_mode_subscription_ = cros_settings_->AddSettingsObserver( 16768043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) chromeos::kReportDeviceBootMode, callback); 16868043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) location_subscription_ = cros_settings_->AddSettingsObserver( 16968043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) chromeos::kReportDeviceLocation, callback); 17068043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) network_interfaces_subscription_ = cros_settings_->AddSettingsObserver( 17168043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) chromeos::kReportDeviceNetworkInterfaces, callback); 1721e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) users_subscription_ = cros_settings_->AddSettingsObserver( 1731e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) chromeos::kReportDeviceUsers, callback); 1745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // The last known location is persisted in local state. This makes location 1765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // information available immediately upon startup and avoids the need to 1775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // reacquire the location on every user session change or browser crash. 1785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) content::Geoposition position; 1795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) std::string timestamp_str; 1805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int64 timestamp; 1815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const base::DictionaryValue* location = 1825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) local_state_->GetDictionary(prefs::kDeviceLocation); 1835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (location->GetDouble(kLatitude, &position.latitude) && 1845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) location->GetDouble(kLongitude, &position.longitude) && 1855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) location->GetDouble(kAltitude, &position.altitude) && 1865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) location->GetDouble(kAccuracy, &position.accuracy) && 1875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) location->GetDouble(kAltitudeAccuracy, &position.altitude_accuracy) && 1885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) location->GetDouble(kHeading, &position.heading) && 1895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) location->GetDouble(kSpeed, &position.speed) && 1905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) location->GetString(kTimestamp, ×tamp_str) && 1915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) base::StringToInt64(timestamp_str, ×tamp)) { 1925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) position.timestamp = Time::FromInternalValue(timestamp); 1935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) position_ = position; 1945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 1955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Fetch the current values of the policies. 1975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) UpdateReportingSettings(); 1985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Get the the OS and firmware version info. 2002a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) version_loader_.GetVersion( 2012a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) VersionLoader::VERSION_FULL, 2022a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) base::Bind(&DeviceStatusCollector::OnOSVersion, base::Unretained(this)), 2032a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) &tracker_); 2042a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) version_loader_.GetFirmware( 2052a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) base::Bind(&DeviceStatusCollector::OnOSFirmware, base::Unretained(this)), 2062a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) &tracker_); 2075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 2085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)DeviceStatusCollector::~DeviceStatusCollector() { 2105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 2115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// static 2132a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)void DeviceStatusCollector::RegisterPrefs(PrefRegistrySimple* registry) { 2142a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) registry->RegisterDictionaryPref(prefs::kDeviceActivityTimes, 2152a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) new base::DictionaryValue); 2162a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) registry->RegisterDictionaryPref(prefs::kDeviceLocation, 2172a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) new base::DictionaryValue); 2185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 2195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void DeviceStatusCollector::CheckIdleState() { 2215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) CalculateIdleState(kIdleStateThresholdSeconds, 2225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) base::Bind(&DeviceStatusCollector::IdleStateCallback, 2235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) base::Unretained(this))); 2245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 2255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void DeviceStatusCollector::UpdateReportingSettings() { 2275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Attempt to fetch the current value of the reporting settings. 2285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // If trusted values are not available, register this function to be called 2295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // back when they are available. 2305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (chromeos::CrosSettingsProvider::TRUSTED != 2315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) cros_settings_->PrepareTrustedValues( 2325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) base::Bind(&DeviceStatusCollector::UpdateReportingSettings, 2335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) weak_factory_.GetWeakPtr()))) { 2345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return; 2355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 2365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) cros_settings_->GetBoolean( 2375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) chromeos::kReportDeviceVersionInfo, &report_version_info_); 2385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) cros_settings_->GetBoolean( 2395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) chromeos::kReportDeviceActivityTimes, &report_activity_times_); 2405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) cros_settings_->GetBoolean( 2415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) chromeos::kReportDeviceBootMode, &report_boot_mode_); 2425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) cros_settings_->GetBoolean( 2435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) chromeos::kReportDeviceLocation, &report_location_); 2447dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch cros_settings_->GetBoolean( 2457dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch chromeos::kReportDeviceNetworkInterfaces, &report_network_interfaces_); 2461e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) cros_settings_->GetBoolean( 2471e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) chromeos::kReportDeviceUsers, &report_users_); 2485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (report_location_) { 2505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ScheduleGeolocationUpdateRequest(); 2515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } else { 2525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) geolocation_update_timer_.Stop(); 2535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) position_ = content::Geoposition(); 2545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) local_state_->ClearPref(prefs::kDeviceLocation); 2555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 2565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 2575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)Time DeviceStatusCollector::GetCurrentTime() { 2595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return Time::Now(); 2605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 2615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Remove all out-of-range activity times from the local store. 2635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void DeviceStatusCollector::PruneStoredActivityPeriods(Time base_time) { 2645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) Time min_time = 2655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) base_time - TimeDelta::FromDays(max_stored_past_activity_days_); 2665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) Time max_time = 2675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) base_time + TimeDelta::FromDays(max_stored_future_activity_days_); 2682a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) TrimStoredActivityPeriods(TimestampToDayKey(min_time), 0, 2692a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) TimestampToDayKey(max_time)); 2702a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 2712a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 2722a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)void DeviceStatusCollector::TrimStoredActivityPeriods(int64 min_day_key, 2732a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) int min_day_trim_duration, 2742a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) int64 max_day_key) { 2752a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const base::DictionaryValue* activity_times = 2762a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) local_state_->GetDictionary(prefs::kDeviceActivityTimes); 2775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) scoped_ptr<base::DictionaryValue> copy(activity_times->DeepCopy()); 279c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) for (base::DictionaryValue::Iterator it(*activity_times); !it.IsAtEnd(); 2802a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) it.Advance()) { 2815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int64 timestamp; 2822a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) if (base::StringToInt64(it.key(), ×tamp)) { 2835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Remove data that is too old, or too far in the future. 2842a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) if (timestamp >= min_day_key && timestamp < max_day_key) { 2852a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) if (timestamp == min_day_key) { 2862a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) int new_activity_duration = 0; 2872a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) if (it.value().GetAsInteger(&new_activity_duration)) { 2882a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) new_activity_duration = 2892a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) std::max(new_activity_duration - min_day_trim_duration, 0); 2902a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } 2912a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) copy->SetInteger(it.key(), new_activity_duration); 2922a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } 2935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) continue; 2942a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } 2955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 2965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // The entry is out of range or couldn't be parsed. Remove it. 2972a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) copy->Remove(it.key(), NULL); 2985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 2995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) local_state_->Set(prefs::kDeviceActivityTimes, *copy); 3005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 3015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void DeviceStatusCollector::AddActivePeriod(Time start, Time end) { 3035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) DCHECK(start < end); 3045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Maintain the list of active periods in a local_state pref. 3065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) DictionaryPrefUpdate update(local_state_, prefs::kDeviceActivityTimes); 3075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) base::DictionaryValue* activity_times = update.Get(); 3085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3092a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Assign the period to day buckets in local time. 3102a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) Time midnight = start.LocalMidnight(); 3112a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) while (midnight < end) { 3122a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) midnight += TimeDelta::FromDays(1); 3132a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) int64 activity = (std::min(end, midnight) - start).InMilliseconds(); 3142a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) std::string day_key = base::Int64ToString(TimestampToDayKey(start)); 3152a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) int previous_activity = 0; 3162a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) activity_times->GetInteger(day_key, &previous_activity); 3172a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) activity_times->SetInteger(day_key, previous_activity + activity); 3182a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) start = midnight; 3195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 3205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 3215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void DeviceStatusCollector::IdleStateCallback(IdleState state) { 3235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Do nothing if device activity reporting is disabled. 3245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (!report_activity_times_) 3255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return; 3265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) Time now = GetCurrentTime(); 3285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (state == IDLE_STATE_ACTIVE) { 3305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // If it's been too long since the last report, or if the activity is 3315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // negative (which can happen when the clock changes), assume a single 3325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // interval of activity. 3335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int active_seconds = (now - last_idle_check_).InSeconds(); 3345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (active_seconds < 0 || 3352a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) active_seconds >= static_cast<int>((2 * kIdlePollIntervalSeconds))) { 3365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) AddActivePeriod(now - TimeDelta::FromSeconds(kIdlePollIntervalSeconds), 3375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) now); 3382a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } else { 3395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) AddActivePeriod(last_idle_check_, now); 3402a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } 3415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) PruneStoredActivityPeriods(now); 3435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 3445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) last_idle_check_ = now; 3455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 3465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void DeviceStatusCollector::GetActivityTimes( 3485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) em::DeviceStatusReportRequest* request) { 3495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) DictionaryPrefUpdate update(local_state_, prefs::kDeviceActivityTimes); 3505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) base::DictionaryValue* activity_times = update.Get(); 3515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3522a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) for (base::DictionaryValue::Iterator it(*activity_times); !it.IsAtEnd(); 3532a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) it.Advance()) { 3545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int64 start_timestamp; 3555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int activity_milliseconds; 3562a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) if (base::StringToInt64(it.key(), &start_timestamp) && 3572a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) it.value().GetAsInteger(&activity_milliseconds)) { 3585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // This is correct even when there are leap seconds, because when a leap 3595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // second occurs, two consecutive seconds have the same timestamp. 3605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int64 end_timestamp = start_timestamp + kMillisecondsPerDay; 3615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) em::ActiveTimePeriod* active_period = request->add_active_period(); 3635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) em::TimePeriod* period = active_period->mutable_time_period(); 3645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) period->set_start_timestamp(start_timestamp); 3655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) period->set_end_timestamp(end_timestamp); 3665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) active_period->set_active_duration(activity_milliseconds); 3672a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) if (start_timestamp >= last_reported_day_) { 3682a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) last_reported_day_ = start_timestamp; 3692a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) duration_for_last_reported_day_ = activity_milliseconds; 3702a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } 3715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } else { 3725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) NOTREACHED(); 3735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 3745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 3755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 3765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void DeviceStatusCollector::GetVersionInfo( 3785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) em::DeviceStatusReportRequest* request) { 3795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) chrome::VersionInfo version_info; 3805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) request->set_browser_version(version_info.Version()); 3815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) request->set_os_version(os_version_); 3825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) request->set_firmware_version(firmware_version_); 3835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 3845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void DeviceStatusCollector::GetBootMode( 3865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) em::DeviceStatusReportRequest* request) { 3875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) std::string dev_switch_mode; 3885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (statistics_provider_->GetMachineStatistic( 389eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch chromeos::system::kDevSwitchBootMode, &dev_switch_mode)) { 3905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (dev_switch_mode == "1") 3915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) request->set_boot_mode("Dev"); 3925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) else if (dev_switch_mode == "0") 3935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) request->set_boot_mode("Verified"); 3945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 3955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 3965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void DeviceStatusCollector::GetLocation( 3985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) em::DeviceStatusReportRequest* request) { 3995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) em::DeviceLocation* location = request->mutable_device_location(); 4005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (!position_.Validate()) { 4015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) location->set_error_code( 4025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) em::DeviceLocation::ERROR_CODE_POSITION_UNAVAILABLE); 4035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) location->set_error_message(position_.error_message); 4045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } else { 4055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) location->set_latitude(position_.latitude); 4065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) location->set_longitude(position_.longitude); 4075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) location->set_accuracy(position_.accuracy); 4085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) location->set_timestamp( 4095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) (position_.timestamp - Time::UnixEpoch()).InMilliseconds()); 4105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Lowest point on land is at approximately -400 meters. 4115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (position_.altitude > -10000.) 4125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) location->set_altitude(position_.altitude); 4135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (position_.altitude_accuracy >= 0.) 4145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) location->set_altitude_accuracy(position_.altitude_accuracy); 4155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (position_.heading >= 0. && position_.heading <= 360) 4165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) location->set_heading(position_.heading); 4175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (position_.speed >= 0.) 4185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) location->set_speed(position_.speed); 4195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) location->set_error_code(em::DeviceLocation::ERROR_CODE_NONE); 4205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 4215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 4225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 4237dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdochvoid DeviceStatusCollector::GetNetworkInterfaces( 4247dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch em::DeviceStatusReportRequest* request) { 4257dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch // Maps flimflam device type strings to proto enum constants. 4267dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch static const struct { 4277dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch const char* type_string; 4287dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch em::NetworkInterface::NetworkDeviceType type_constant; 4297dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch } kDeviceTypeMap[] = { 43068043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) { shill::kTypeEthernet, em::NetworkInterface::TYPE_ETHERNET, }, 43168043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) { shill::kTypeWifi, em::NetworkInterface::TYPE_WIFI, }, 43268043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) { shill::kTypeWimax, em::NetworkInterface::TYPE_WIMAX, }, 43368043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) { shill::kTypeBluetooth, em::NetworkInterface::TYPE_BLUETOOTH, }, 43468043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) { shill::kTypeCellular, em::NetworkInterface::TYPE_CELLULAR, }, 4357dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch }; 4367dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch 4377dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch chromeos::NetworkStateHandler::DeviceStateList device_list; 4387dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch chromeos::NetworkHandler::Get()->network_state_handler()->GetDeviceList( 4397dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch &device_list); 4407dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch 4417dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch chromeos::NetworkStateHandler::DeviceStateList::const_iterator device; 4427dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch for (device = device_list.begin(); device != device_list.end(); ++device) { 4437dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch // Determine the type enum constant for |device|. 4447dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch size_t type_idx = 0; 4457dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch for (; type_idx < ARRAYSIZE_UNSAFE(kDeviceTypeMap); ++type_idx) { 4467dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch if ((*device)->type() == kDeviceTypeMap[type_idx].type_string) 4477dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch break; 4487dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch } 4497dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch 4507dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch // If the type isn't in |kDeviceTypeMap|, the interface is not relevant for 4517dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch // reporting. This filters out VPN devices. 4527dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch if (type_idx >= ARRAYSIZE_UNSAFE(kDeviceTypeMap)) 4537dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch continue; 4547dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch 4557dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch em::NetworkInterface* interface = request->add_network_interface(); 4567dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch interface->set_type(kDeviceTypeMap[type_idx].type_constant); 4577dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch if (!(*device)->mac_address().empty()) 4587dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch interface->set_mac_address((*device)->mac_address()); 4597dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch if (!(*device)->meid().empty()) 4607dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch interface->set_meid((*device)->meid()); 4617dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch if (!(*device)->imei().empty()) 4627dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch interface->set_imei((*device)->imei()); 4637dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch } 4647dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch} 4657dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch 4661e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)void DeviceStatusCollector::GetUsers(em::DeviceStatusReportRequest* request) { 4671e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) BrowserPolicyConnector* connector = 4681e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) g_browser_process->browser_policy_connector(); 4691e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) bool found_managed_user = false; 4701e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) const chromeos::UserList& users = chromeos::UserManager::Get()->GetUsers(); 4711e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) chromeos::UserList::const_iterator user; 4721e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) for (user = users.begin(); user != users.end(); ++user) { 473a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) // Only regular users are reported. 474a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) if ((*user)->GetType() != chromeos::User::USER_TYPE_REGULAR) 475a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) continue; 476a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) 4771e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) em::DeviceUser* device_user = request->add_user(); 4781e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) const std::string& email = (*user)->email(); 4791e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) if (connector->GetUserAffiliation(email) == USER_AFFILIATION_MANAGED) { 4801e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) device_user->set_type(em::DeviceUser::USER_TYPE_MANAGED); 4811e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) device_user->set_email(email); 4821e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) found_managed_user = true; 4831e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) } else { 4841e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) device_user->set_type(em::DeviceUser::USER_TYPE_UNMANAGED); 4851e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // Do not report the email address of unmanaged users. 4861e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) } 4871e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 4881e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // Add only kMaxUserCount entries, unless no managed users are found in the 4891e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // first kMaxUserCount users. In that case, continue until at least one 4901e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // managed user is found. 4911e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) if (request->user_size() >= kMaxUserCount && found_managed_user) 4921e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) break; 4931e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) } 4941e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)} 4951e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 4965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void DeviceStatusCollector::GetStatus(em::DeviceStatusReportRequest* request) { 4972a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // TODO(mnissler): Remove once the old cloud policy stack is retired. The old 4982a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // stack doesn't support reporting successful submissions back to here, so 4992a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // just assume whatever ends up in |request| gets submitted successfully. 5002a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) GetDeviceStatus(request); 5012a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) OnSubmittedSuccessfully(); 5022a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 5032a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 5042a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)bool DeviceStatusCollector::GetDeviceStatus( 5052a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) em::DeviceStatusReportRequest* status) { 5065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (report_activity_times_) 5072a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) GetActivityTimes(status); 5085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (report_version_info_) 5102a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) GetVersionInfo(status); 5115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (report_boot_mode_) 5132a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) GetBootMode(status); 5145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (report_location_) 5162a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) GetLocation(status); 5172a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 5187dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch if (report_network_interfaces_) 5197dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch GetNetworkInterfaces(status); 5207dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch 521f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) if (report_users_ && !CommandLine::ForCurrentProcess()->HasSwitch( 522f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) chromeos::switches::kDisableEnterpriseUserReporting)) { 5231e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) GetUsers(status); 524f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) } 5251e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 5262a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) return true; 5272a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 5282a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 5292a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)bool DeviceStatusCollector::GetSessionStatus( 5302a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) em::SessionStatusReportRequest* status) { 5312a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) return false; 5322a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 5332a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 5342a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)void DeviceStatusCollector::OnSubmittedSuccessfully() { 5352a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) TrimStoredActivityPeriods(last_reported_day_, duration_for_last_reported_day_, 5362a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) std::numeric_limits<int64>::max()); 5375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 5385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5392a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)void DeviceStatusCollector::OnOSVersion(const std::string& version) { 5405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) os_version_ = version; 5415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 5425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5432a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)void DeviceStatusCollector::OnOSFirmware(const std::string& version) { 5445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) firmware_version_ = version; 5455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 5465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void DeviceStatusCollector::ScheduleGeolocationUpdateRequest() { 5485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (geolocation_update_timer_.IsRunning() || geolocation_update_in_progress_) 5495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return; 5505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (position_.Validate()) { 5522a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) TimeDelta elapsed = GetCurrentTime() - position_.timestamp; 5535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) TimeDelta interval = 5545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) TimeDelta::FromSeconds(kGeolocationPollIntervalSeconds); 5555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (elapsed > interval) { 5565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) geolocation_update_in_progress_ = true; 557b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) location_update_requester_.Run(base::Bind( 5585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) &DeviceStatusCollector::ReceiveGeolocationUpdate, 5595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) weak_factory_.GetWeakPtr())); 5605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } else { 5615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) geolocation_update_timer_.Start( 5625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) FROM_HERE, 5635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) interval - elapsed, 5645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) this, 5655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) &DeviceStatusCollector::ScheduleGeolocationUpdateRequest); 5665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 5675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } else { 5685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) geolocation_update_in_progress_ = true; 569b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) location_update_requester_.Run(base::Bind( 5705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) &DeviceStatusCollector::ReceiveGeolocationUpdate, 5715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) weak_factory_.GetWeakPtr())); 5725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 5735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 5745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void DeviceStatusCollector::ReceiveGeolocationUpdate( 5765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const content::Geoposition& position) { 5775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) geolocation_update_in_progress_ = false; 5785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Ignore update if device location reporting has since been disabled. 5805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (!report_location_) 5815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return; 5825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (position.Validate()) { 5845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) position_ = position; 5855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) base::DictionaryValue location; 5865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) location.SetDouble(kLatitude, position.latitude); 5875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) location.SetDouble(kLongitude, position.longitude); 5885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) location.SetDouble(kAltitude, position.altitude); 5895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) location.SetDouble(kAccuracy, position.accuracy); 5905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) location.SetDouble(kAltitudeAccuracy, position.altitude_accuracy); 5915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) location.SetDouble(kHeading, position.heading); 5925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) location.SetDouble(kSpeed, position.speed); 5935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) location.SetString(kTimestamp, 5945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) base::Int64ToString(position.timestamp.ToInternalValue())); 5955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) local_state_->Set(prefs::kDeviceLocation, location); 5965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 5975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ScheduleGeolocationUpdateRequest(); 5995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 6005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 6015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} // namespace policy 602