Add a feature to get the last UpdateAttempt ErrorCode from update_engine

For autotest, update_engine test failures are always hard to debug,
since the error message is not clear. Add a new flag 'last_attempt_error'
to get the last UpdateAttempt ErrorCode from update_engine.

Bug:25598547
Test:emerge-peppy update_engine
     emerge-peppy update_engine_client
     cros flash a test image to DUT.
     (on the DUT):update_engine_client --last_attempt_error
     Compare the results with the update_engine logs, matched.

Change-Id: Id12681097ed30b0826cad68809f17f934a07e5b2
diff --git a/payload_state.cc b/payload_state.cc
index 4b5b5fd..04b6579 100644
--- a/payload_state.cc
+++ b/payload_state.cc
@@ -62,6 +62,7 @@
       url_switch_count_(0),
       attempt_num_bytes_downloaded_(0),
       attempt_connection_type_(metrics::ConnectionType::kUnknown),
+      attempt_error_code_(ErrorCode::kSuccess),
       attempt_type_(AttemptType::kUpdate) {
   for (int i = 0; i <= kNumDownloadSources; i++)
     total_bytes_downloaded_[i] = current_bytes_downloaded_[i] = 0;
@@ -232,6 +233,7 @@
                                      metrics::RollbackResult::kSuccess);
       break;
   }
+  attempt_error_code_ = ErrorCode::kSuccess;
 
   // Reset the number of responses seen since it counts from the last
   // successful update, e.g. now.
@@ -265,6 +267,8 @@
       break;
   }
 
+  attempt_error_code_ = base_error;
+
   switch (base_error) {
     // Errors which are good indicators of a problem with a particular URL or
     // the protocol used in the URL or entities in the communication channel