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 #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/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
9 #include "base/location.h" | 9 #include "base/location.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
262 return; | 262 return; |
263 | 263 |
264 Time now = GetCurrentTime(); | 264 Time now = GetCurrentTime(); |
265 | 265 |
266 if (state == IDLE_STATE_ACTIVE) { | 266 if (state == IDLE_STATE_ACTIVE) { |
267 // If it's been too long since the last report, or if the activity is | 267 // If it's been too long since the last report, or if the activity is |
268 // negative (which can happen when the clock changes), assume a single | 268 // negative (which can happen when the clock changes), assume a single |
269 // interval of activity. | 269 // interval of activity. |
270 int active_seconds = (now - last_idle_check_).InSeconds(); | 270 int active_seconds = (now - last_idle_check_).InSeconds(); |
271 if (active_seconds < 0 || | 271 if (active_seconds < 0 || |
272 active_seconds >= static_cast<int>((2 * kIdlePollIntervalSeconds))) | 272 active_seconds >= static_cast<int>((2 * kIdlePollIntervalSeconds))) { |
273 AddActivePeriod(now - TimeDelta::FromSeconds(kIdlePollIntervalSeconds), | 273 AddActivePeriod(now - TimeDelta::FromSeconds(kIdlePollIntervalSeconds), |
274 now); | 274 now); |
275 else | 275 } else { |
276 AddActivePeriod(last_idle_check_, now); | 276 AddActivePeriod(last_idle_check_, now); |
| 277 } |
277 | 278 |
278 PruneStoredActivityPeriods(now); | 279 PruneStoredActivityPeriods(now); |
279 } | 280 } |
280 last_idle_check_ = now; | 281 last_idle_check_ = now; |
281 } | 282 } |
282 | 283 |
283 void DeviceStatusCollector::GetActivityTimes( | 284 void DeviceStatusCollector::GetActivityTimes( |
284 em::DeviceStatusReportRequest* request) { | 285 em::DeviceStatusReportRequest* request) { |
285 DictionaryPrefUpdate update(local_state_, prefs::kDeviceActivityTimes); | 286 DictionaryPrefUpdate update(local_state_, prefs::kDeviceActivityTimes); |
286 base::DictionaryValue* activity_times = update.Get(); | 287 base::DictionaryValue* activity_times = update.Get(); |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
383 UpdateReportingSettings(); | 384 UpdateReportingSettings(); |
384 else | 385 else |
385 NOTREACHED(); | 386 NOTREACHED(); |
386 } | 387 } |
387 | 388 |
388 void DeviceStatusCollector::ScheduleGeolocationUpdateRequest() { | 389 void DeviceStatusCollector::ScheduleGeolocationUpdateRequest() { |
389 if (geolocation_update_timer_.IsRunning() || geolocation_update_in_progress_) | 390 if (geolocation_update_timer_.IsRunning() || geolocation_update_in_progress_) |
390 return; | 391 return; |
391 | 392 |
392 if (position_.Validate()) { | 393 if (position_.Validate()) { |
393 TimeDelta elapsed = Time::Now() - position_.timestamp; | 394 TimeDelta elapsed = GetCurrentTime() - position_.timestamp; |
394 TimeDelta interval = | 395 TimeDelta interval = |
395 TimeDelta::FromSeconds(kGeolocationPollIntervalSeconds); | 396 TimeDelta::FromSeconds(kGeolocationPollIntervalSeconds); |
396 if (elapsed > interval) { | 397 if (elapsed > interval) { |
397 geolocation_update_in_progress_ = true; | 398 geolocation_update_in_progress_ = true; |
398 location_update_requester_(base::Bind( | 399 location_update_requester_(base::Bind( |
399 &DeviceStatusCollector::ReceiveGeolocationUpdate, | 400 &DeviceStatusCollector::ReceiveGeolocationUpdate, |
400 weak_factory_.GetWeakPtr())); | 401 weak_factory_.GetWeakPtr())); |
401 } else { | 402 } else { |
402 geolocation_update_timer_.Start( | 403 geolocation_update_timer_.Start( |
403 FROM_HERE, | 404 FROM_HERE, |
(...skipping 30 matching lines...) Expand all Loading... |
434 location.SetDouble(kSpeed, position.speed); | 435 location.SetDouble(kSpeed, position.speed); |
435 location.SetString(kTimestamp, | 436 location.SetString(kTimestamp, |
436 base::Int64ToString(position.timestamp.ToInternalValue())); | 437 base::Int64ToString(position.timestamp.ToInternalValue())); |
437 local_state_->Set(prefs::kDeviceLocation, location); | 438 local_state_->Set(prefs::kDeviceLocation, location); |
438 } | 439 } |
439 | 440 |
440 ScheduleGeolocationUpdateRequest(); | 441 ScheduleGeolocationUpdateRequest(); |
441 } | 442 } |
442 | 443 |
443 } // namespace policy | 444 } // namespace policy |
OLD | NEW |