update_engine: Reset forced update flag before sending Omaha ping

Lack of resetting the forced update flag causes
InteractiveUpdatePolicyImpl to always return true for (non-)interactive
updates and this can cause the update check to fall into an infinite
loop because the policy will never reach to
NextUpdateCheckTimePolicyImpl:

CheckForUpdate -> ScheduleUpdates -> OnUpdateScheduled -> Update ->
PingOmaha -> ScheduleUpdates

BUG=chromium:960828
TEST=unitest
TEST=updated device using this flow:
- update_engine_client --interactive=false --update
- wait till the state changed to wait_reboot
- update_engine_client --interactive=false --update
and no infinite loop was entered.

Change-Id: Ie8f8308d8af79f56cd71324bcb8679897f6823e7
Reviewed-on: https://chromium-review.googlesource.com/1666252
Tested-by: Amin Hassani <ahassani@chromium.org>
Commit-Ready: Amin Hassani <ahassani@chromium.org>
Legacy-Commit-Queue: Commit Bot <commit-bot@chromium.org>
Reviewed-by: Sen Jiang <senj@chromium.org>
diff --git a/update_attempter.cc b/update_attempter.cc
index 73785bf..3f77886 100644
--- a/update_attempter.cc
+++ b/update_attempter.cc
@@ -835,7 +835,7 @@
   if (interactive && status_ != UpdateStatus::IDLE) {
     // An update check is either in-progress, or an update has completed and the
     // system is in UPDATED_NEED_REBOOT.  Either way, don't do an interactive
-    // update at this time
+    // update at this time.
     LOG(INFO) << "Refusing to do an interactive update with an update already "
                  "in progress";
     return false;
@@ -1031,17 +1031,12 @@
   // Reset cpu shares back to normal.
   cpu_limiter_.StopLimiter();
 
-  // reset the state that's only valid for a single update pass
-  current_update_attempt_flags_ = UpdateAttemptFlags::kNone;
-
-  if (forced_update_pending_callback_.get())
-    // Clear prior interactive requests once the processor is done.
-    forced_update_pending_callback_->Run(false, false);
+  ResetInteractivityFlags();
 
   if (status_ == UpdateStatus::REPORTING_ERROR_EVENT) {
     LOG(INFO) << "Error event sent.";
 
-    // Inform scheduler of new status;
+    // Inform scheduler of new status.
     SetStatusAndNotify(UpdateStatus::IDLE);
     ScheduleUpdates();
 
@@ -1138,9 +1133,9 @@
   // Reset cpu shares back to normal.
   cpu_limiter_.StopLimiter();
   download_progress_ = 0.0;
-  if (forced_update_pending_callback_.get())
-    // Clear prior interactive requests once the processor is done.
-    forced_update_pending_callback_->Run(false, false);
+
+  ResetInteractivityFlags();
+
   SetStatusAndNotify(UpdateStatus::IDLE);
   ScheduleUpdates();
   error_event_.reset(nullptr);
@@ -1294,6 +1289,15 @@
   }
 }
 
+void UpdateAttempter::ResetInteractivityFlags() {
+  // Reset the state that's only valid for a single update pass.
+  current_update_attempt_flags_ = UpdateAttemptFlags::kNone;
+
+  if (forced_update_pending_callback_.get())
+    // Clear prior interactive requests once the processor is done.
+    forced_update_pending_callback_->Run(false, false);
+}
+
 bool UpdateAttempter::ResetStatus() {
   LOG(INFO) << "Attempting to reset state from "
             << UpdateStatusToString(status_) << " to UpdateStatus::IDLE";
@@ -1500,6 +1504,8 @@
 
 void UpdateAttempter::PingOmaha() {
   if (!processor_->IsRunning()) {
+    ResetInteractivityFlags();
+
     auto ping_action = std::make_unique<OmahaRequestAction>(
         system_state_,
         nullptr,