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