Fix error code for no update.

PayloadState does not get notified if there's no update, so the error
code will not be updated, move this to UpdateAttempter.

We were using the generic kError for no update, this change added a
new error code kNoUpdate for this, now update_engine_client will show
kNoUpdate instead of kSuccess or a random last error.

Bug: 36946608
Test: update_engine_client --check_for_update --follow
Change-Id: Ie1e94841788437140e0894dc2e73c314a7564108
(cherry picked from commit 89e24c11b406fe048382bdf1c89334e10417b899)
Reviewed-on: https://chromium-review.googlesource.com/1055857
Commit-Ready: Amin Hassani <ahassani@chromium.org>
Tested-by: Amin Hassani <ahassani@chromium.org>
Reviewed-by: Nicolas Norvez <norvez@chromium.org>
Reviewed-by: Sen Jiang <senj@chromium.org>
diff --git a/update_attempter.cc b/update_attempter.cc
index 9d18932..db4be6b 100644
--- a/update_attempter.cc
+++ b/update_attempter.cc
@@ -961,6 +961,8 @@
         "so requesting reboot from user.";
   }
 
+  attempt_error_code_ = utils::GetBaseErrorCode(code);
+
   if (code == ErrorCode::kSuccess) {
     WriteUpdateCompletedMarker();
     prefs_->SetInt64(kPrefsDeltaUpdateFailures, 0);
@@ -1125,8 +1127,10 @@
           break;
       }
     }
-    // On failure, schedule an error event to be sent to Omaha.
-    CreatePendingErrorEvent(action, code);
+    if (code != ErrorCode::kNoUpdate) {
+      // On failure, schedule an error event to be sent to Omaha.
+      CreatePendingErrorEvent(action, code);
+    }
     return;
   }
   // Find out which action completed (successfully).
@@ -1326,22 +1330,12 @@
 
 void UpdateAttempter::CreatePendingErrorEvent(AbstractAction* action,
                                               ErrorCode code) {
-  if (error_event_.get()) {
+  if (error_event_.get() || status_ == UpdateStatus::REPORTING_ERROR_EVENT) {
     // This shouldn't really happen.
     LOG(WARNING) << "There's already an existing pending error event.";
     return;
   }
 
-  // For now assume that a generic Omaha response action failure means that
-  // there's no update so don't send an event. Also, double check that the
-  // failure has not occurred while sending an error event -- in which case
-  // don't schedule another. This shouldn't really happen but just in case...
-  if ((action->Type() == OmahaResponseHandlerAction::StaticType() &&
-       code == ErrorCode::kError) ||
-      status_ == UpdateStatus::REPORTING_ERROR_EVENT) {
-    return;
-  }
-
   // Classify the code to generate the appropriate result so that
   // the Borgmon charts show up the results correctly.
   // Do this before calling GetErrorCodeForAction which could potentially