Send "success reboot" only after an update.

The <event> message sent to omaha after we reboot into a new version
was originally sent only on the first updatecheck after rebooting into
the new installed version, and included the old version number. A bug
introduced in 2013 removed the check for the empty previous version
making the update_engine send this message on *every* updatecheck. This
patch inserts back the check for the empty previous version to send the
"success reboot" event only after.

While there are still discussions about what's the right event message
to send on that case, this fixes the regression.

Bug: 24867646
Test: FEATURES=test emerge-link update_engine; second <updatecheck> didn't include the <event>

Change-Id: Icd00364aae15c8bf420f1f89ae7b526999b3a124
diff --git a/omaha_request_action.cc b/omaha_request_action.cc
index 8967762..8f405e8 100644
--- a/omaha_request_action.cc
+++ b/omaha_request_action.cc
@@ -123,20 +123,25 @@
       // generated with a previous version of 0.0.0.0 -- this is relevant for
       // older clients or new installs. The previous version event is not sent
       // for ping-only requests because they come before the client has
-      // rebooted.
+      // rebooted. The previous version event is also not sent if it was already
+      // sent for this new version with a previous updatecheck.
       string prev_version;
       if (!prefs->GetString(kPrefsPreviousVersion, &prev_version)) {
         prev_version = "0.0.0.0";
       }
-
-      app_body += base::StringPrintf(
-          "        <event eventtype=\"%d\" eventresult=\"%d\" "
-          "previousversion=\"%s\"></event>\n",
-          OmahaEvent::kTypeUpdateComplete,
-          OmahaEvent::kResultSuccessReboot,
-          XmlEncodeWithDefault(prev_version, "0.0.0.0").c_str());
-      LOG_IF(WARNING, !prefs->SetString(kPrefsPreviousVersion, ""))
-          << "Unable to reset the previous version.";
+      // We only store a non-empty previous version value after a successful
+      // update in the previous boot. After reporting it back to the server,
+      // we clear the previous version value so it doesn't get reported again.
+      if (!prev_version.empty()) {
+        app_body += base::StringPrintf(
+            "        <event eventtype=\"%d\" eventresult=\"%d\" "
+            "previousversion=\"%s\"></event>\n",
+            OmahaEvent::kTypeUpdateComplete,
+            OmahaEvent::kResultSuccessReboot,
+            XmlEncodeWithDefault(prev_version, "0.0.0.0").c_str());
+        LOG_IF(WARNING, !prefs->SetString(kPrefsPreviousVersion, ""))
+            << "Unable to reset the previous version.";
+      }
     }
   } else {
     // The error code is an optional attribute so append it only if the result