Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(348)

Side by Side Diff: chrome/browser/policy/device_status_collector.cc

Issue 11271024: Fix DeviceStatusCollectorTest.MaxStoredPeriods. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 8 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 max_stored_future_activity_days_(kMaxStoredFutureActivityDays), 86 max_stored_future_activity_days_(kMaxStoredFutureActivityDays),
87 local_state_(local_state), 87 local_state_(local_state),
88 last_idle_check_(Time()), 88 last_idle_check_(Time()),
89 geolocation_update_in_progress_(false), 89 geolocation_update_in_progress_(false),
90 statistics_provider_(provider), 90 statistics_provider_(provider),
91 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)), 91 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)),
92 location_update_requester_(location_update_requester), 92 location_update_requester_(location_update_requester),
93 report_version_info_(false), 93 report_version_info_(false),
94 report_activity_times_(false), 94 report_activity_times_(false),
95 report_boot_mode_(false), 95 report_boot_mode_(false),
96 report_location_(false) { 96 report_location_(false) {}
97
98 DeviceStatusCollector::~DeviceStatusCollector() {
99 cros_settings_->RemoveSettingsObserver(chromeos::kReportDeviceVersionInfo,
100 this);
101 cros_settings_->RemoveSettingsObserver(chromeos::kReportDeviceActivityTimes,
102 this);
103 cros_settings_->RemoveSettingsObserver(chromeos::kReportDeviceBootMode, this);
104 cros_settings_->RemoveSettingsObserver(chromeos::kReportDeviceLocation, this);
105 }
106
107 void DeviceStatusCollector::Init() {
97 if (!location_update_requester_) 108 if (!location_update_requester_)
98 location_update_requester_ = &content::RequestLocationUpdate; 109 location_update_requester_ = &content::RequestLocationUpdate;
99 idle_poll_timer_.Start(FROM_HERE, 110 idle_poll_timer_.Start(FROM_HERE,
100 TimeDelta::FromSeconds(kIdlePollIntervalSeconds), 111 TimeDelta::FromSeconds(kIdlePollIntervalSeconds),
101 this, &DeviceStatusCollector::CheckIdleState); 112 this, &DeviceStatusCollector::CheckIdleState);
102 113
103 cros_settings_ = chromeos::CrosSettings::Get(); 114 cros_settings_ = chromeos::CrosSettings::Get();
104 115
105 // Watch for changes to the individual policies that control what the status 116 // Watch for changes to the individual policies that control what the status
106 // reports contain. 117 // reports contain.
(...skipping 30 matching lines...) Expand all
137 // Get the the OS and firmware version info. 148 // Get the the OS and firmware version info.
138 version_loader_.GetVersion( 149 version_loader_.GetVersion(
139 VersionLoader::VERSION_FULL, 150 VersionLoader::VERSION_FULL,
140 base::Bind(&DeviceStatusCollector::OnOSVersion, base::Unretained(this)), 151 base::Bind(&DeviceStatusCollector::OnOSVersion, base::Unretained(this)),
141 &tracker_); 152 &tracker_);
142 version_loader_.GetFirmware( 153 version_loader_.GetFirmware(
143 base::Bind(&DeviceStatusCollector::OnOSFirmware, base::Unretained(this)), 154 base::Bind(&DeviceStatusCollector::OnOSFirmware, base::Unretained(this)),
144 &tracker_); 155 &tracker_);
145 } 156 }
146 157
147 DeviceStatusCollector::~DeviceStatusCollector() {
148 cros_settings_->RemoveSettingsObserver(chromeos::kReportDeviceVersionInfo,
149 this);
150 cros_settings_->RemoveSettingsObserver(chromeos::kReportDeviceActivityTimes,
151 this);
152 cros_settings_->RemoveSettingsObserver(chromeos::kReportDeviceBootMode, this);
153 cros_settings_->RemoveSettingsObserver(chromeos::kReportDeviceLocation, this);
154 }
155
156 // static 158 // static
157 void DeviceStatusCollector::RegisterPrefs(PrefService* local_state) { 159 void DeviceStatusCollector::RegisterPrefs(PrefService* local_state) {
158 local_state->RegisterDictionaryPref(prefs::kDeviceActivityTimes, 160 local_state->RegisterDictionaryPref(prefs::kDeviceActivityTimes,
159 new base::DictionaryValue); 161 new base::DictionaryValue);
160 local_state->RegisterDictionaryPref(prefs::kDeviceLocation, 162 local_state->RegisterDictionaryPref(prefs::kDeviceLocation,
161 new base::DictionaryValue); 163 new base::DictionaryValue);
162 } 164 }
163 165
164 void DeviceStatusCollector::CheckIdleState() { 166 void DeviceStatusCollector::CheckIdleState() {
165 CalculateIdleState(kIdleStateThresholdSeconds, 167 CalculateIdleState(kIdleStateThresholdSeconds,
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
262 return; 264 return;
263 265
264 Time now = GetCurrentTime(); 266 Time now = GetCurrentTime();
265 267
266 if (state == IDLE_STATE_ACTIVE) { 268 if (state == IDLE_STATE_ACTIVE) {
267 // If it's been too long since the last report, or if the activity is 269 // 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 270 // negative (which can happen when the clock changes), assume a single
269 // interval of activity. 271 // interval of activity.
270 int active_seconds = (now - last_idle_check_).InSeconds(); 272 int active_seconds = (now - last_idle_check_).InSeconds();
271 if (active_seconds < 0 || 273 if (active_seconds < 0 ||
272 active_seconds >= static_cast<int>((2 * kIdlePollIntervalSeconds))) 274 active_seconds >= static_cast<int>((2 * kIdlePollIntervalSeconds))) {
273 AddActivePeriod(now - TimeDelta::FromSeconds(kIdlePollIntervalSeconds), 275 AddActivePeriod(now - TimeDelta::FromSeconds(kIdlePollIntervalSeconds),
274 now); 276 now);
275 else 277 } else {
276 AddActivePeriod(last_idle_check_, now); 278 AddActivePeriod(last_idle_check_, now);
279 }
277 280
278 PruneStoredActivityPeriods(now); 281 PruneStoredActivityPeriods(now);
279 } 282 }
280 last_idle_check_ = now; 283 last_idle_check_ = now;
281 } 284 }
282 285
283 void DeviceStatusCollector::GetActivityTimes( 286 void DeviceStatusCollector::GetActivityTimes(
284 em::DeviceStatusReportRequest* request) { 287 em::DeviceStatusReportRequest* request) {
285 DictionaryPrefUpdate update(local_state_, prefs::kDeviceActivityTimes); 288 DictionaryPrefUpdate update(local_state_, prefs::kDeviceActivityTimes);
286 base::DictionaryValue* activity_times = update.Get(); 289 base::DictionaryValue* activity_times = update.Get();
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
383 UpdateReportingSettings(); 386 UpdateReportingSettings();
384 else 387 else
385 NOTREACHED(); 388 NOTREACHED();
386 } 389 }
387 390
388 void DeviceStatusCollector::ScheduleGeolocationUpdateRequest() { 391 void DeviceStatusCollector::ScheduleGeolocationUpdateRequest() {
389 if (geolocation_update_timer_.IsRunning() || geolocation_update_in_progress_) 392 if (geolocation_update_timer_.IsRunning() || geolocation_update_in_progress_)
390 return; 393 return;
391 394
392 if (position_.Validate()) { 395 if (position_.Validate()) {
393 TimeDelta elapsed = Time::Now() - position_.timestamp; 396 TimeDelta elapsed = GetCurrentTime() - position_.timestamp;
jar (doing other things) 2012/11/16 20:29:23 The old code used Time::Now(), which is not a mono
Ryan Sleevi 2012/11/16 22:20:48 I have to agree with Jim here. I think conflating
Joao da Silva 2012/11/20 09:10:52 It's the same; GetCurrentTime() is a virtual that
394 TimeDelta interval = 397 TimeDelta interval =
395 TimeDelta::FromSeconds(kGeolocationPollIntervalSeconds); 398 TimeDelta::FromSeconds(kGeolocationPollIntervalSeconds);
396 if (elapsed > interval) { 399 if (elapsed > interval) {
397 geolocation_update_in_progress_ = true; 400 geolocation_update_in_progress_ = true;
398 location_update_requester_(base::Bind( 401 location_update_requester_(base::Bind(
399 &DeviceStatusCollector::ReceiveGeolocationUpdate, 402 &DeviceStatusCollector::ReceiveGeolocationUpdate,
400 weak_factory_.GetWeakPtr())); 403 weak_factory_.GetWeakPtr()));
401 } else { 404 } else {
402 geolocation_update_timer_.Start( 405 geolocation_update_timer_.Start(
403 FROM_HERE, 406 FROM_HERE,
(...skipping 30 matching lines...) Expand all
434 location.SetDouble(kSpeed, position.speed); 437 location.SetDouble(kSpeed, position.speed);
435 location.SetString(kTimestamp, 438 location.SetString(kTimestamp,
436 base::Int64ToString(position.timestamp.ToInternalValue())); 439 base::Int64ToString(position.timestamp.ToInternalValue()));
437 local_state_->Set(prefs::kDeviceLocation, location); 440 local_state_->Set(prefs::kDeviceLocation, location);
438 } 441 }
439 442
440 ScheduleGeolocationUpdateRequest(); 443 ScheduleGeolocationUpdateRequest();
441 } 444 }
442 445
443 } // namespace policy 446 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698