buffet: Allow configurable polling period
While here, switch to using a repeating timer, which is cleaner.
BUG=brillo:564,brillo:522
TEST=buffet_Registration passes. Can touch the polling period config
flag and see that polling period changes.
Change-Id: I8d0cca5d38e8ba91dad1a97311cc20603e300654
Reviewed-on: https://chromium-review.googlesource.com/260920
Tested-by: Christopher Wiley <wiley@chromium.org>
Reviewed-by: Alex Vakulenko <avakulenko@chromium.org>
Reviewed-by: Vitaly Buka <vitalybuka@chromium.org>
Commit-Queue: Christopher Wiley <wiley@chromium.org>
diff --git a/buffet/device_registration_info.cc b/buffet/device_registration_info.cc
index 3f7e17c..b16e626 100644
--- a/buffet/device_registration_info.cc
+++ b/buffet/device_registration_info.cc
@@ -569,14 +569,6 @@
FROM_HERE, base::Bind(cb, base::Owned(value.release())));
}
-void PostRepeatingTask(const tracked_objects::Location& from_here,
- base::Closure task,
- base::TimeDelta delay) {
- task.Run();
- base::MessageLoop::current()->PostDelayedTask(
- from_here, base::Bind(&PostRepeatingTask, from_here, task, delay), delay);
-}
-
using ResponsePtr = scoped_ptr<chromeos::http::Response>;
void SendRequestWithRetries(
@@ -840,23 +832,22 @@
void DeviceRegistrationInfo::PeriodicallyPollCommands() {
VLOG(1) << "Poll commands";
- PostRepeatingTask(
+ command_poll_timer_.Start(
FROM_HERE,
- base::Bind(
- &DeviceRegistrationInfo::FetchCommands,
- base::Unretained(this),
- base::Bind(&DeviceRegistrationInfo::PublishCommands,
- base::Unretained(this)),
- base::Bind(&IgnoreCloudError)),
- base::TimeDelta::FromSeconds(7));
+ base::TimeDelta::FromMilliseconds(config_->polling_period_ms()),
+ base::Bind(&DeviceRegistrationInfo::FetchCommands,
+ base::Unretained(this),
+ base::Bind(&DeviceRegistrationInfo::PublishCommands,
+ base::Unretained(this)),
+ base::Bind(&IgnoreCloudError)));
// TODO(antonm): Use better trigger: when StateManager registers new updates,
// it should call closure which will post a task, probably with some
// throttling, to publish state updates.
- PostRepeatingTask(
+ state_push_timer_.Start(
FROM_HERE,
+ base::TimeDelta::FromMilliseconds(config_->polling_period_ms()),
base::Bind(&DeviceRegistrationInfo::PublishStateUpdates,
- base::Unretained(this)),
- base::TimeDelta::FromSeconds(7));
+ base::Unretained(this)));
}
void DeviceRegistrationInfo::PublishCommands(const base::ListValue& commands) {