| 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" | |
| 10 #include "base/string_number_conversions.h" | 9 #include "base/string_number_conversions.h" |
| 11 #include "base/task.h" | |
| 12 #include "base/time.h" | |
| 13 #include "chrome/browser/idle.h" | |
| 14 #include "chrome/browser/policy/proto/device_management_backend.pb.h" | 10 #include "chrome/browser/policy/proto/device_management_backend.pb.h" |
| 15 #include "chrome/browser/prefs/pref_service.h" | 11 #include "chrome/browser/prefs/pref_service.h" |
| 16 #include "chrome/browser/prefs/scoped_user_pref_update.h" | 12 #include "chrome/browser/prefs/scoped_user_pref_update.h" |
| 17 | 13 |
| 18 using base::Time; | 14 using base::Time; |
| 19 using base::TimeDelta; | 15 using base::TimeDelta; |
| 16 using chromeos::VersionLoader; |
| 20 | 17 |
| 21 namespace em = enterprise_management; | 18 namespace em = enterprise_management; |
| 22 | 19 |
| 23 namespace { | 20 namespace { |
| 24 // How many seconds of inactivity triggers the idle state. | 21 // How many seconds of inactivity triggers the idle state. |
| 25 const unsigned int kIdleStateThresholdSeconds = 300; | 22 const unsigned int kIdleStateThresholdSeconds = 300; |
| 26 | 23 |
| 27 // The maximum number of time periods stored in the local state. | 24 // The maximum number of time periods stored in the local state. |
| 28 const unsigned int kMaxStoredActivePeriods = 500; | 25 const unsigned int kMaxStoredActivePeriods = 500; |
| 29 | 26 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 46 | 43 |
| 47 DeviceStatusCollector::DeviceStatusCollector(PrefService* local_state) | 44 DeviceStatusCollector::DeviceStatusCollector(PrefService* local_state) |
| 48 : max_stored_active_periods_(kMaxStoredActivePeriods), | 45 : max_stored_active_periods_(kMaxStoredActivePeriods), |
| 49 local_state_(local_state), | 46 local_state_(local_state), |
| 50 last_idle_check_(Time()), | 47 last_idle_check_(Time()), |
| 51 last_idle_state_(IDLE_STATE_UNKNOWN) { | 48 last_idle_state_(IDLE_STATE_UNKNOWN) { |
| 52 timer_.Start(FROM_HERE, | 49 timer_.Start(FROM_HERE, |
| 53 TimeDelta::FromSeconds( | 50 TimeDelta::FromSeconds( |
| 54 DeviceStatusCollector::kPollIntervalSeconds), | 51 DeviceStatusCollector::kPollIntervalSeconds), |
| 55 this, &DeviceStatusCollector::CheckIdleState); | 52 this, &DeviceStatusCollector::CheckIdleState); |
| 53 |
| 54 // Get the the OS and firmware version info. |
| 55 version_loader_.GetVersion(&consumer_, |
| 56 base::Bind(&DeviceStatusCollector::OnOSVersion, |
| 57 base::Unretained(this)), |
| 58 VersionLoader::VERSION_FULL); |
| 59 version_loader_.GetFirmware(&consumer_, |
| 60 base::Bind(&DeviceStatusCollector::OnOSFirmware, |
| 61 base::Unretained(this))); |
| 56 } | 62 } |
| 57 | 63 |
| 58 DeviceStatusCollector::~DeviceStatusCollector() { | 64 DeviceStatusCollector::~DeviceStatusCollector() { |
| 59 } | 65 } |
| 60 | 66 |
| 61 // static | 67 // static |
| 62 void DeviceStatusCollector::RegisterPrefs(PrefService* local_state) { | 68 void DeviceStatusCollector::RegisterPrefs(PrefService* local_state) { |
| 63 local_state->RegisterInt64Pref(kPrefBaselineTime, Time::Now().ToTimeT()); | 69 local_state->RegisterInt64Pref(kPrefBaselineTime, Time::Now().ToTimeT()); |
| 64 local_state->RegisterListPref(kPrefDeviceActivePeriods, new ListValue); | 70 local_state->RegisterListPref(kPrefDeviceActivePeriods, new ListValue); |
| 65 } | 71 } |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 140 // Something is amiss -- bail out. | 146 // Something is amiss -- bail out. |
| 141 NOTREACHED(); | 147 NOTREACHED(); |
| 142 break; | 148 break; |
| 143 } | 149 } |
| 144 time_period = request->add_active_time(); | 150 time_period = request->add_active_time(); |
| 145 time_period->set_start_timestamp(start); | 151 time_period->set_start_timestamp(start); |
| 146 time_period->set_end_timestamp(end); | 152 time_period->set_end_timestamp(end); |
| 147 } | 153 } |
| 148 ListPrefUpdate update(local_state_, kPrefDeviceActivePeriods); | 154 ListPrefUpdate update(local_state_, kPrefDeviceActivePeriods); |
| 149 update.Get()->Clear(); | 155 update.Get()->Clear(); |
| 156 |
| 157 request->set_os_version(os_version_); |
| 158 request->set_firmware_version(firmware_version_); |
| 159 } |
| 160 |
| 161 void DeviceStatusCollector::OnOSVersion(VersionLoader::Handle handle, |
| 162 std::string version) { |
| 163 os_version_ = version; |
| 164 } |
| 165 |
| 166 void DeviceStatusCollector::OnOSFirmware(VersionLoader::Handle handle, |
| 167 std::string version) { |
| 168 firmware_version_ = version; |
| 150 } | 169 } |
| 151 | 170 |
| 152 } // namespace policy | 171 } // namespace policy |
| OLD | NEW |