1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232
|
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_CHROMEOS_POLICY_DEVICE_STATUS_COLLECTOR_H_
#define CHROME_BROWSER_CHROMEOS_POLICY_DEVICE_STATUS_COLLECTOR_H_
#include <string>
#include <vector>
#include "base/basictypes.h"
#include "base/callback_forward.h"
#include "base/callback_list.h"
#include "base/compiler_specific.h"
#include "base/memory/ref_counted.h"
#include "base/memory/scoped_ptr.h"
#include "base/memory/weak_ptr.h"
#include "base/task/cancelable_task_tracker.h"
#include "base/time/time.h"
#include "base/timer/timer.h"
#include "chrome/browser/chromeos/settings/cros_settings.h"
#include "chrome/browser/idle.h"
#include "chromeos/system/version_loader.h"
#include "components/policy/core/common/cloud/cloud_policy_client.h"
#include "content/public/browser/geolocation_provider.h"
#include "content/public/common/geoposition.h"
#include "policy/proto/device_management_backend.pb.h"
namespace chromeos {
class CrosSettings;
namespace system {
class StatisticsProvider;
}
}
namespace content {
class NotificationDetails;
class NotificationSource;
}
class PrefRegistrySimple;
class PrefService;
namespace policy {
// Collects and summarizes the status of an enterprised-managed ChromeOS device.
class DeviceStatusCollector : public CloudPolicyClient::StatusProvider {
public:
// TODO(bartfab): Remove this once crbug.com/125931 is addressed and a proper
// way to mock geolocation exists.
typedef base::Callback<void(
const content::GeolocationProvider::LocationUpdateCallback& callback)>
LocationUpdateRequester;
DeviceStatusCollector(
PrefService* local_state,
chromeos::system::StatisticsProvider* provider,
LocationUpdateRequester* location_update_requester);
virtual ~DeviceStatusCollector();
// CloudPolicyClient::StatusProvider:
virtual bool GetDeviceStatus(
enterprise_management::DeviceStatusReportRequest* status) override;
virtual bool GetSessionStatus(
enterprise_management::SessionStatusReportRequest* status) override;
virtual void OnSubmittedSuccessfully() override;
static void RegisterPrefs(PrefRegistrySimple* registry);
// How often, in seconds, to poll to see if the user is idle.
static const unsigned int kIdlePollIntervalSeconds = 30;
using VolumeInfoFetcher = base::Callback<
std::vector<enterprise_management::VolumeInfo>(
const std::vector<std::string>& mount_points)>;
// Used by tests to return mock VolumeInfo.
void SetVolumeInfoFetcherForTest(VolumeInfoFetcher fetcher);
protected:
// Check whether the user has been idle for a certain period of time.
virtual void CheckIdleState();
// Used instead of base::Time::Now(), to make testing possible.
virtual base::Time GetCurrentTime();
// Callback which receives the results of the idle state check.
void IdleStateCallback(IdleState state);
// Returns true if the currently active session is an auto-launched
// kiosk session (this enables functionality such as network reporting).
// Virtual to allow mocking.
virtual bool IsAutoLaunchedKioskSession();
// The number of days in the past to store device activity.
// This is kept in case device status uploads fail for a number of days.
unsigned int max_stored_past_activity_days_;
// The number of days in the future to store device activity.
// When changing the system time and/or timezones, it's possible to record
// activity time that is slightly in the future.
unsigned int max_stored_future_activity_days_;
private:
// Prevents the local store of activity periods from growing too large by
// removing entries that are outside the reporting window.
void PruneStoredActivityPeriods(base::Time base_time);
// Trims the store activity periods to only retain data within the
// [|min_day_key|, |max_day_key|). The record for |min_day_key| will be
// adjusted by subtracting |min_day_trim_duration|.
void TrimStoredActivityPeriods(int64 min_day_key,
int min_day_trim_duration,
int64 max_day_key);
void AddActivePeriod(base::Time start, base::Time end);
// Samples the current hardware status to be sent up with the next device
// status update.
void SampleHardwareStatus();
// Clears the cached hardware status.
void ClearCachedHardwareStatus();
// Callbacks from chromeos::VersionLoader.
void OnOSVersion(const std::string& version);
void OnOSFirmware(const std::string& version);
// Helpers for the various portions of the status.
void GetActivityTimes(
enterprise_management::DeviceStatusReportRequest* request);
void GetVersionInfo(
enterprise_management::DeviceStatusReportRequest* request);
void GetBootMode(
enterprise_management::DeviceStatusReportRequest* request);
void GetLocation(
enterprise_management::DeviceStatusReportRequest* request);
void GetNetworkInterfaces(
enterprise_management::DeviceStatusReportRequest* request);
void GetUsers(
enterprise_management::DeviceStatusReportRequest* request);
void GetHardwareStatus(
enterprise_management::DeviceStatusReportRequest* request);
// Update the cached values of the reporting settings.
void UpdateReportingSettings();
void ScheduleGeolocationUpdateRequest();
// content::GeolocationUpdateCallback implementation.
void ReceiveGeolocationUpdate(const content::Geoposition&);
// Callback invoked to update our cached disk information.
void ReceiveVolumeInfo(
const std::vector<enterprise_management::VolumeInfo>& info);
// How often to poll to see if the user is idle.
int poll_interval_seconds_;
PrefService* local_state_;
// The last time an idle state check was performed.
base::Time last_idle_check_;
// The maximum key that went into the last report generated by
// GetDeviceStatus(), and the duration for it. This is used to trim the
// stored data in OnSubmittedSuccessfully(). Trimming is delayed so
// unsuccessful uploads don't result in dropped data.
int64 last_reported_day_;
int duration_for_last_reported_day_;
// Whether a geolocation update is currently in progress.
bool geolocation_update_in_progress_;
base::RepeatingTimer<DeviceStatusCollector> idle_poll_timer_;
base::RepeatingTimer<DeviceStatusCollector> hardware_status_sampling_timer_;
base::OneShotTimer<DeviceStatusCollector> geolocation_update_timer_;
std::string os_version_;
std::string firmware_version_;
content::Geoposition position_;
// Cached disk volume information.
std::vector<enterprise_management::VolumeInfo> volume_info_;
// Callback invoked to fetch information about the mounted disk volumes.
VolumeInfoFetcher volume_info_fetcher_;
chromeos::system::StatisticsProvider* statistics_provider_;
chromeos::CrosSettings* cros_settings_;
// TODO(bartfab): Remove this once crbug.com/125931 is addressed and a proper
// way to mock geolocation exists.
LocationUpdateRequester location_update_requester_;
scoped_ptr<content::GeolocationProvider::Subscription>
geolocation_subscription_;
// Cached values of the reporting settings from the device policy.
bool report_version_info_;
bool report_activity_times_;
bool report_boot_mode_;
bool report_location_;
bool report_network_interfaces_;
bool report_users_;
bool report_hardware_status_;
scoped_ptr<chromeos::CrosSettings::ObserverSubscription>
version_info_subscription_;
scoped_ptr<chromeos::CrosSettings::ObserverSubscription>
activity_times_subscription_;
scoped_ptr<chromeos::CrosSettings::ObserverSubscription>
boot_mode_subscription_;
scoped_ptr<chromeos::CrosSettings::ObserverSubscription>
location_subscription_;
scoped_ptr<chromeos::CrosSettings::ObserverSubscription>
network_interfaces_subscription_;
scoped_ptr<chromeos::CrosSettings::ObserverSubscription>
users_subscription_;
scoped_ptr<chromeos::CrosSettings::ObserverSubscription>
hardware_status_subscription_;
base::WeakPtrFactory<DeviceStatusCollector> weak_factory_;
DISALLOW_COPY_AND_ASSIGN(DeviceStatusCollector);
};
} // namespace policy
#endif // CHROME_BROWSER_CHROMEOS_POLICY_DEVICE_STATUS_COLLECTOR_H_
|