Make sure waiting period in memory and persisted file are always in sync.
Sometimes the waiting period is 0 and there's no wall-clock-wait-period
prefs file created even though scattering is enabled. It happens because
the existing code doesn't maintain the invariants properly. So when a
user-initiated update check happens, the wall-clock-wait-period prefs
file is deleted but the in-memory variable
omaha_request_params_.waiting_period is not being updated.
This CL fixes these invariants by ensuring all the scattering artifacts
are removed completely when scattering is disabled and they're properly
recomputed when scattering is enabled.
BUG=chromium-os:32924
TEST=Updated unit tests, tested on ZGB.
Change-Id: Iabd2fd744f8c1a5099c00cf4d1f952757ec3e634
Reviewed-on: https://gerrit.chromium.org/gerrit/28348
Reviewed-by: Gilad Arnold <garnold@chromium.org>
Commit-Ready: Jay Srinivasan <jaysri@chromium.org>
Tested-by: Jay Srinivasan <jaysri@chromium.org>
diff --git a/update_attempter.h b/update_attempter.h
index 1ab8352..9109cec 100644
--- a/update_attempter.h
+++ b/update_attempter.h
@@ -242,6 +242,16 @@
bool is_test,
bool is_user_initiated);
+ // Calculates all the scattering related parameters (such as waiting period,
+ // which type of scattering is enabled, etc.) and also updates/deletes
+ // the corresponding prefs file used in scattering. Should be called
+ // only after the device policy has been loaded and set in the system_state_.
+ void CalculateScatteringParams(bool is_user_initiated);
+
+ // Sets a random value for the omaha_request_params_.waiting_period
+ // based on the current scatter_factor_ value.
+ void GenerateNewWaitingPeriod();
+
// Helper method of Update() to construct the sequence of actions to
// be performed for an update check. Please refer to
// Update() method for the meaning of the parametes.
@@ -347,10 +357,6 @@
// The current scatter factor as found in the policy setting.
base::TimeDelta scatter_factor_;
- // True if we have to initialize the waiting period in prefs, if available.
- // False otherwise.
- bool init_waiting_period_from_prefs_;
-
// External state of the system outside the update_engine process
// carved out separately to mock out easily in unit tests.
SystemState* system_state_;