Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #include "chrome/browser/policy/device_status_collector.h" | 5 #include "chrome/browser/policy/device_status_collector.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/callback.h" | 8 #include "base/callback.h" |
| 9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
|
Joao da Silva
2011/12/12 14:23:04
Nit: not needed
Patrick Dubroy
2011/12/12 15:18:01
Done.
| |
| 10 #include "base/string_number_conversions.h" | 10 #include "base/string_number_conversions.h" |
| 11 #include "base/task.h" | 11 #include "base/task.h" |
|
Joao da Silva
2011/12/12 14:23:04
Nit: not needed
Patrick Dubroy
2011/12/12 15:18:01
Good catch. These were used in an older version of
| |
| 12 #include "base/time.h" | 12 #include "base/time.h" |
| 13 #include "chrome/browser/chromeos/version_loader.h" | |
| 13 #include "chrome/browser/idle.h" | 14 #include "chrome/browser/idle.h" |
|
Joao da Silva
2011/12/12 14:23:04
Nit: these 3 are already included in .h, not neede
Patrick Dubroy
2011/12/12 15:18:01
Ok, I've never been quite sure what the recommende
| |
| 14 #include "chrome/browser/policy/proto/device_management_backend.pb.h" | 15 #include "chrome/browser/policy/proto/device_management_backend.pb.h" |
| 15 #include "chrome/browser/prefs/pref_service.h" | 16 #include "chrome/browser/prefs/pref_service.h" |
| 16 #include "chrome/browser/prefs/scoped_user_pref_update.h" | 17 #include "chrome/browser/prefs/scoped_user_pref_update.h" |
| 17 | 18 |
| 18 using base::Time; | 19 using base::Time; |
| 19 using base::TimeDelta; | 20 using base::TimeDelta; |
| 21 using chromeos::VersionLoader; | |
| 20 | 22 |
| 21 namespace em = enterprise_management; | 23 namespace em = enterprise_management; |
| 22 | 24 |
| 23 namespace { | 25 namespace { |
| 24 // How many seconds of inactivity triggers the idle state. | 26 // How many seconds of inactivity triggers the idle state. |
| 25 const unsigned int kIdleStateThresholdSeconds = 300; | 27 const unsigned int kIdleStateThresholdSeconds = 300; |
| 26 | 28 |
| 27 // The maximum number of time periods stored in the local state. | 29 // The maximum number of time periods stored in the local state. |
| 28 const unsigned int kMaxStoredActivePeriods = 500; | 30 const unsigned int kMaxStoredActivePeriods = 500; |
| 29 | 31 |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 46 | 48 |
| 47 DeviceStatusCollector::DeviceStatusCollector(PrefService* local_state) | 49 DeviceStatusCollector::DeviceStatusCollector(PrefService* local_state) |
| 48 : max_stored_active_periods_(kMaxStoredActivePeriods), | 50 : max_stored_active_periods_(kMaxStoredActivePeriods), |
| 49 local_state_(local_state), | 51 local_state_(local_state), |
| 50 last_idle_check_(Time()), | 52 last_idle_check_(Time()), |
| 51 last_idle_state_(IDLE_STATE_UNKNOWN) { | 53 last_idle_state_(IDLE_STATE_UNKNOWN) { |
| 52 timer_.Start(FROM_HERE, | 54 timer_.Start(FROM_HERE, |
| 53 TimeDelta::FromSeconds( | 55 TimeDelta::FromSeconds( |
| 54 DeviceStatusCollector::kPollIntervalSeconds), | 56 DeviceStatusCollector::kPollIntervalSeconds), |
| 55 this, &DeviceStatusCollector::CheckIdleState); | 57 this, &DeviceStatusCollector::CheckIdleState); |
| 58 | |
| 59 // Get the the OS and firmware version info. | |
| 60 version_loader_.GetVersion(&consumer_, | |
| 61 base::Bind(&DeviceStatusCollector::OnOSVersion, | |
| 62 base::Unretained(this)), | |
| 63 VersionLoader::VERSION_FULL); | |
| 64 version_loader_.GetFirmware(&consumer_, | |
| 65 base::Bind(&DeviceStatusCollector::OnOSFirmware, | |
| 66 base::Unretained(this))); | |
| 56 } | 67 } |
| 57 | 68 |
| 58 DeviceStatusCollector::~DeviceStatusCollector() { | 69 DeviceStatusCollector::~DeviceStatusCollector() { |
| 59 } | 70 } |
| 60 | 71 |
| 61 // static | 72 // static |
| 62 void DeviceStatusCollector::RegisterPrefs(PrefService* local_state) { | 73 void DeviceStatusCollector::RegisterPrefs(PrefService* local_state) { |
| 63 local_state->RegisterInt64Pref(kPrefBaselineTime, Time::Now().ToTimeT()); | 74 local_state->RegisterInt64Pref(kPrefBaselineTime, Time::Now().ToTimeT()); |
| 64 local_state->RegisterListPref(kPrefDeviceActivePeriods, new ListValue); | 75 local_state->RegisterListPref(kPrefDeviceActivePeriods, new ListValue); |
| 65 } | 76 } |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 140 // Something is amiss -- bail out. | 151 // Something is amiss -- bail out. |
| 141 NOTREACHED(); | 152 NOTREACHED(); |
| 142 break; | 153 break; |
| 143 } | 154 } |
| 144 time_period = request->add_active_time(); | 155 time_period = request->add_active_time(); |
| 145 time_period->set_start_timestamp(start); | 156 time_period->set_start_timestamp(start); |
| 146 time_period->set_end_timestamp(end); | 157 time_period->set_end_timestamp(end); |
| 147 } | 158 } |
| 148 ListPrefUpdate update(local_state_, kPrefDeviceActivePeriods); | 159 ListPrefUpdate update(local_state_, kPrefDeviceActivePeriods); |
| 149 update.Get()->Clear(); | 160 update.Get()->Clear(); |
| 161 | |
| 162 request->set_os_version(os_version_); | |
| 163 request->set_firmware_version(firmware_version_); | |
| 164 } | |
| 165 | |
| 166 void DeviceStatusCollector::OnOSVersion(VersionLoader::Handle handle, | |
| 167 std::string version) { | |
| 168 os_version_ = version; | |
| 169 } | |
| 170 | |
| 171 void DeviceStatusCollector::OnOSFirmware(VersionLoader::Handle handle, | |
| 172 std::string version) { | |
| 173 firmware_version_ = version; | |
| 150 } | 174 } |
| 151 | 175 |
| 152 } // namespace policy | 176 } // namespace policy |
| OLD | NEW |