Index: chrome/browser/policy/device_status_collector.h |
diff --git a/chrome/browser/policy/device_status_collector.h b/chrome/browser/policy/device_status_collector.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..7db78a1e7953e2f9be7073ab728dad59fdf4520c |
--- /dev/null |
+++ b/chrome/browser/policy/device_status_collector.h |
@@ -0,0 +1,77 @@ |
+// Copyright (c) 2011 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_POLICY_DEVICE_STATUS_COLLECTOR_H_ |
+#define CHROME_BROWSER_POLICY_DEVICE_STATUS_COLLECTOR_H_ |
+#pragma once |
+ |
+#include "base/time.h" |
+#include "base/timer.h" |
+#include "chrome/browser/idle.h" |
+ |
+using base::Time; |
+ |
+namespace enterprise_management { |
+class DeviceStatusReportRequest; |
+} |
+ |
+class PrefService; |
+ |
+namespace policy { |
+ |
+// Collects and reports the status of an enterprised-managed ChromeOS device. |
Mattias Nissler (ping if slow)
2011/11/30 12:44:29
doesn't actually do the reporting.
Patrick Dubroy
2011/12/06 14:30:36
Done.
|
+class DeviceStatusCollector { |
+ public: |
+ explicit DeviceStatusCollector(PrefService* local_state); |
+ |
+ void GetStatus(enterprise_management::DeviceStatusReportRequest* request); |
+ |
+ static void RegisterPrefs(PrefService* local_state); |
+ |
+ // Returns the max number active periods timestamps to be stored in the |
+ // local state. Virtual for testing purposes. |
+ virtual unsigned int max_stored_active_periods() const; |
Mattias Nissler (ping if slow)
2011/11/30 12:44:29
would a local variable and a setter that tests can
Patrick Dubroy
2011/12/06 14:30:36
Good idea -- done.
|
+ |
+ // How often, in seconds, to poll to see if the user is idle. |
+ static const unsigned int kPollIntervalSeconds = 30; |
+ |
+ protected: |
+ // Check whether the user has been idle for a certain period of time. |
+ virtual void CheckIdleState(); |
+ |
+ // Used instead of Time::Now(), to make testing possible. |
+ virtual Time GetCurrentTime(); |
+ |
+ // Callback which receives the results of the idle state check. |
+ void IdleStateCallback(IdleState state); |
+ |
+ private: |
+ void AddActivePeriod(base::Time start, base::Time end); |
+ |
+ // Since ListValue does not support int64 members, timestamps for active |
+ // periods are stored as integer offsets from a reference time, which is |
+ // a time_t value representing seconds since Jan 1, 1970 UTC. |
+ // These methods convert to and from the offset representation. |
+ bool ToInternalTime(const base::Time& time, int& out_val); |
+ Time FromInternalTime(int offset); |
+ |
+ // 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. |
+ Time last_idle_check_; |
+ |
+ // The idle state the last time it was checked. |
+ IdleState last_idle_state_; |
+ |
+ base::RepeatingTimer<DeviceStatusCollector> timer_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(DeviceStatusCollector); |
+}; |
+ |
+} // namespace policy |
+ |
+#endif // CHROME_BROWSER_POLICY_DEVICE_STATUS_COLLECTOR_H_ |