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 #ifndef CHROME_BROWSER_POLICY_DEVICE_STATUS_COLLECTOR_H_ | 5 #ifndef CHROME_BROWSER_POLICY_DEVICE_STATUS_COLLECTOR_H_ |
6 #define CHROME_BROWSER_POLICY_DEVICE_STATUS_COLLECTOR_H_ | 6 #define CHROME_BROWSER_POLICY_DEVICE_STATUS_COLLECTOR_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include "base/time.h" | 9 #include "base/time.h" |
10 #include "base/timer.h" | 10 #include "base/timer.h" |
11 #include "chrome/browser/chromeos/version_loader.h" | 11 #include "chrome/browser/chromeos/version_loader.h" |
12 #include "chrome/browser/idle.h" | 12 #include "chrome/browser/idle.h" |
13 #include "content/public/browser/notification_observer.h" | 13 #include "content/public/browser/notification_observer.h" |
14 | 14 |
15 namespace chromeos { | 15 namespace chromeos { |
16 class CrosSettings; | 16 class CrosSettings; |
17 namespace system { | 17 namespace system { |
18 class StatisticsProvider; | 18 class StatisticsProvider; |
19 } | 19 } |
20 } | 20 } |
21 | 21 |
22 namespace enterprise_management { | 22 namespace enterprise_management { |
23 class DeviceStatusReportRequest; | 23 class DeviceStatusReportRequest; |
24 } | 24 } |
25 | 25 |
| 26 class GeolocationProvider; |
26 class PrefService; | 27 class PrefService; |
27 | 28 |
28 namespace policy { | 29 namespace policy { |
29 | 30 |
| 31 class DeviceStatusLocationHelper; |
| 32 |
30 // Collects and summarizes the status of an enterprised-managed ChromeOS device. | 33 // Collects and summarizes the status of an enterprised-managed ChromeOS device. |
31 class DeviceStatusCollector : public content::NotificationObserver { | 34 class DeviceStatusCollector : public content::NotificationObserver { |
32 public: | 35 public: |
33 DeviceStatusCollector(PrefService* local_state, | 36 DeviceStatusCollector(PrefService* local_state, |
34 chromeos::system::StatisticsProvider* provider); | 37 chromeos::system::StatisticsProvider* provider); |
35 virtual ~DeviceStatusCollector(); | 38 virtual ~DeviceStatusCollector(); |
36 | 39 |
37 void GetStatus(enterprise_management::DeviceStatusReportRequest* request); | 40 void GetStatus(enterprise_management::DeviceStatusReportRequest* request); |
38 | 41 |
39 static void RegisterPrefs(PrefService* local_state); | 42 static void RegisterPrefs(PrefService* local_state); |
40 | 43 |
41 // How often, in seconds, to poll to see if the user is idle. | 44 // How often, in seconds, to poll to see if the user is idle. |
42 static const unsigned int kPollIntervalSeconds = 30; | 45 static const unsigned int kPollIntervalSeconds = 30; |
43 | 46 |
44 protected: | 47 protected: |
45 // Check whether the user has been idle for a certain period of time. | 48 // Check whether the user has been idle for a certain period of time. |
46 virtual void CheckIdleState(); | 49 virtual void CheckIdleState(); |
47 | 50 |
48 // Used instead of base::Time::Now(), to make testing possible. | 51 // Used instead of base::Time::Now(), to make testing possible. |
49 virtual base::Time GetCurrentTime(); | 52 virtual base::Time GetCurrentTime(); |
50 | 53 |
51 // Callback which receives the results of the idle state check. | 54 // Callback which receives the results of the idle state check. |
52 void IdleStateCallback(IdleState state); | 55 void IdleStateCallback(IdleState state); |
53 | 56 |
| 57 void SetGeolocationProviderForTest(GeolocationProvider* provider); |
| 58 |
54 // The number of days in the past to store device activity. | 59 // The number of days in the past to store device activity. |
55 // This is kept in case device status uploads fail for a number of days. | 60 // This is kept in case device status uploads fail for a number of days. |
56 unsigned int max_stored_past_activity_days_; | 61 unsigned int max_stored_past_activity_days_; |
57 | 62 |
58 // The number of days in the future to store device activity. | 63 // The number of days in the future to store device activity. |
59 // When changing the system time and/or timezones, it's possible to record | 64 // When changing the system time and/or timezones, it's possible to record |
60 // activity time that is slightly in the future. | 65 // activity time that is slightly in the future. |
61 unsigned int max_stored_future_activity_days_; | 66 unsigned int max_stored_future_activity_days_; |
62 | 67 |
63 private: | 68 private: |
64 // Prevents the local store of activity periods from growing too large by | 69 // Prevents the local store of activity periods from growing too large by |
65 // removing entries that are outside the reporting window. | 70 // removing entries that are outside the reporting window. |
66 void PruneStoredActivityPeriods(base::Time base_time); | 71 void PruneStoredActivityPeriods(base::Time base_time); |
67 | 72 |
68 void AddActivePeriod(base::Time start, base::Time end); | 73 void AddActivePeriod(base::Time start, base::Time end); |
69 | 74 |
70 // Callbacks from chromeos::VersionLoader. | 75 // Callbacks from chromeos::VersionLoader. |
71 void OnOSVersion(chromeos::VersionLoader::Handle handle, | 76 void OnOSVersion(chromeos::VersionLoader::Handle handle, |
72 std::string version); | 77 std::string version); |
73 void OnOSFirmware(chromeos::VersionLoader::Handle handle, | 78 void OnOSFirmware(chromeos::VersionLoader::Handle handle, |
74 std::string version); | 79 std::string version); |
75 | 80 |
76 // Helpers for the various portions of the status. | 81 // Helpers for the various portions of the status. |
77 void GetActivityTimes( | 82 void GetActivityTimes( |
78 enterprise_management::DeviceStatusReportRequest* request); | 83 enterprise_management::DeviceStatusReportRequest* request); |
79 void GetVersionInfo( | 84 void GetVersionInfo( |
80 enterprise_management::DeviceStatusReportRequest* request); | 85 enterprise_management::DeviceStatusReportRequest* request); |
81 void GetBootMode( | 86 void GetBootMode( |
82 enterprise_management::DeviceStatusReportRequest* request); | 87 enterprise_management::DeviceStatusReportRequest* request); |
| 88 void GetLocation( |
| 89 enterprise_management::DeviceStatusReportRequest* request); |
83 | 90 |
84 // Update the cached values of the reporting settings. | 91 // Update the cached values of the reporting settings. |
85 void UpdateReportingSettings(); | 92 void UpdateReportingSettings(); |
86 | 93 |
87 // content::NotificationObserver interface. | 94 // content::NotificationObserver interface. |
88 virtual void Observe( | 95 virtual void Observe( |
89 int type, | 96 int type, |
90 const content::NotificationSource& source, | 97 const content::NotificationSource& source, |
91 const content::NotificationDetails& details) OVERRIDE; | 98 const content::NotificationDetails& details) OVERRIDE; |
92 | 99 |
93 // How often to poll to see if the user is idle. | 100 // How often to poll to see if the user is idle. |
94 int poll_interval_seconds_; | 101 int poll_interval_seconds_; |
95 | 102 |
96 PrefService* local_state_; | 103 PrefService* local_state_; |
97 | 104 |
98 // The last time an idle state check was performed. | 105 // The last time an idle state check was performed. |
99 base::Time last_idle_check_; | 106 base::Time last_idle_check_; |
100 | 107 |
101 base::RepeatingTimer<DeviceStatusCollector> timer_; | 108 base::RepeatingTimer<DeviceStatusCollector> timer_; |
102 | 109 |
103 chromeos::VersionLoader version_loader_; | 110 chromeos::VersionLoader version_loader_; |
104 CancelableRequestConsumer consumer_; | 111 CancelableRequestConsumer consumer_; |
105 | 112 |
106 std::string os_version_; | 113 std::string os_version_; |
107 std::string firmware_version_; | 114 std::string firmware_version_; |
108 | 115 |
109 chromeos::system::StatisticsProvider* statistics_provider_; | 116 chromeos::system::StatisticsProvider* statistics_provider_; |
110 | 117 |
| 118 GeolocationProvider* geolocation_provider_for_test_; |
| 119 DeviceStatusLocationHelper* location_helper_; |
| 120 |
111 chromeos::CrosSettings* cros_settings_; | 121 chromeos::CrosSettings* cros_settings_; |
112 | 122 |
113 // Cached values of the reporting settings from the device policy. | 123 // Cached values of the reporting settings from the device policy. |
114 bool report_version_info_; | 124 bool report_version_info_; |
115 bool report_activity_times_; | 125 bool report_activity_times_; |
116 bool report_boot_mode_; | 126 bool report_boot_mode_; |
| 127 bool report_location_; |
117 | 128 |
118 DISALLOW_COPY_AND_ASSIGN(DeviceStatusCollector); | 129 DISALLOW_COPY_AND_ASSIGN(DeviceStatusCollector); |
119 }; | 130 }; |
120 | 131 |
121 } // namespace policy | 132 } // namespace policy |
122 | 133 |
123 #endif // CHROME_BROWSER_POLICY_DEVICE_STATUS_COLLECTOR_H_ | 134 #endif // CHROME_BROWSER_POLICY_DEVICE_STATUS_COLLECTOR_H_ |
OLD | NEW |