Call chromeos-setgoodkernel asynchronously.

Currently, the script may take about 40 seconds to run and it used to run
synchronously thus blocking the event loop and making update-engine unresponsive
on D-Bus. This CL makes the call asynchronous -- however, the update process
still waits for the call to complete before it starts.

Also, make sure Omaha pings don't try to go in parallel.

Also, fail postinstall action if we fail to spawn the postinstall script.

BUG=chromium-os:14954
TEST=ran AU in different scenarios

Change-Id: I9af84e30ef075838e6625d74f3e6b72577d8c386
Reviewed-on: http://gerrit.chromium.org/gerrit/449
Reviewed-by: Thieu Le <thieule@chromium.org>
Reviewed-by: Darin Petkov <petkov@chromium.org>
Tested-by: Darin Petkov <petkov@chromium.org>
diff --git a/update_attempter.h b/update_attempter.h
index 02e7162..3bbd2ef 100644
--- a/update_attempter.h
+++ b/update_attempter.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2010 The Chromium OS Authors. All rights reserved.
+// Copyright (c) 2011 The Chromium OS Authors. All rights reserved.
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 
@@ -84,10 +84,19 @@
                  std::string* new_version,
                  int64_t* new_size);
 
-  // Runs setgoodkernel, whose responsibility it is to mark the currently
-  // booted partition has high priority/permanent/etc.
+  // Runs chromeos-setgoodkernel, whose responsibility it is to mark the
+  // currently booted partition has high priority/permanent/etc. The execution
+  // is asynchronous. On completion, the action processor may be started
+  // depending on the |start_action_processor_| field. Note that every update
+  // attempt goes through this method.
   void UpdateBootFlags();
 
+  // Subprocess::Exec callback.
+  void CompleteUpdateBootFlags(int return_code);
+  static void StaticCompleteUpdateBootFlags(int return_code,
+                                            const std::string& output,
+                                            void* p);
+
   UpdateStatus status() const { return status_; }
 
   int http_response_code() const { return http_response_code_; }
@@ -166,6 +175,10 @@
   // Callback to start the action processor.
   static gboolean StaticStartProcessing(gpointer data);
 
+  // Schedules an event loop callback to start the action processor. This is
+  // scheduled asynchronously to unblock the event loop.
+  void ScheduleProcessingStart();
+
   // Checks if a full update is needed and forces it by updating the Omaha
   // request params.
   void DisableDeltaUpdateIfNeeded();
@@ -255,8 +268,16 @@
   DirectProxyResolver direct_proxy_resolver_;
   ChromeBrowserProxyResolver chrome_proxy_resolver_;
 
-  // True if UpdateBootFlags has already been called
-  bool updated_boot_flags_;
+  // Originally, both of these flags are false. Once UpdateBootFlags is called,
+  // |update_boot_flags_running_| is set to true. As soon as UpdateBootFlags
+  // completes its asynchronous run, |update_boot_flags_running_| is reset to
+  // false and |updated_boot_flags_| is set to true. From that point on there
+  // will be no more changes to these flags.
+  bool updated_boot_flags_;  // True if UpdateBootFlags has completed.
+  bool update_boot_flags_running_;  // True if UpdateBootFlags is running.
+
+  // True if the action processor needs to be started by the boot flag updater.
+  bool start_action_processor_;
 
   DISALLOW_COPY_AND_ASSIGN(UpdateAttempter);
 };