Enhanced channel changing behavior

This CL adds a new DBUS API to UpdateEngine called SetTargetChannel to
change the current channel of the device with an option to indicate
whether to do eventually or immediately.

The API will be called with the option to do it immediately in a
subsequent CL in Chrome UI. For now the old API (set_track) has been
wired up to call the new API to produce the old behavior (i.e. change
eventually). The old API will be removed after Chrome UI code stops
using it.

It's the UI's responsibility to ask the user for confirmation for the
powerwash that may happen in some cases and call the API with the
appropriate value whether or not the powerwash should happen.

For now, we're restricting the changing of channels to only those
devices that are on canary-channel or running test builds. This
restriction will be lifted off once the UI work is ready to give
warning to the users about the powerwash that may happen when they move
to a more stable channel.

We also enforce ReleaseChannelDelegated and ReleaseChannel policies
correctly now as follows:

* If ReleaseChannelDelegated is false, SetTargetChannel will fail as we
need to honor (only) the ReleaseChannel value in this case.
* If ReleaseChannelDelegated is true, we'll allow the SetTargetChannel
call to specify. In this case, we'll ignore the value of ReleaseChannel,
if any.

BUG=chromium-os:39095
TEST=Tested on ZGB by going from canary to dev-channel with and without
powerwash.
TEST=Existing unit tests have been updated and they pass.
TEST=New unit tests have been added.

Change-Id: Ifbf806a06e1c30d2f318e94d73735d1812049abd
Reviewed-on: https://gerrit.chromium.org/gerrit/44619
Commit-Queue: Jay Srinivasan <[email protected]>
Reviewed-by: Jay Srinivasan <[email protected]>
Tested-by: Jay Srinivasan <[email protected]>
diff --git a/install_plan.h b/install_plan.h
index c0fa4cd..fc33f25 100644
--- a/install_plan.h
+++ b/install_plan.h
@@ -8,11 +8,10 @@
 #include <string>
 #include <vector>
 
-#include "base/logging.h"
+#include <base/basictypes.h>
 
 // InstallPlan is a simple struct that contains relevant info for many
 // parts of the update system about the install that should happen.
-
 namespace chromeos_update_engine {
 
 struct InstallPlan {
@@ -23,27 +22,16 @@
               uint64_t metadata_size,
               const std::string& metadata_signature,
               const std::string& install_path,
-              const std::string& kernel_install_path)
-      : is_resume(is_resume),
-        download_url(url),
-        payload_size(payload_size),
-        payload_hash(payload_hash),
-        metadata_size(metadata_size),
-        metadata_signature(metadata_signature),
-        install_path(install_path),
-        kernel_install_path(kernel_install_path),
-        kernel_size(0),
-        rootfs_size(0),
-        hash_checks_mandatory(false) {}
+              const std::string& kernel_install_path);
 
   // Default constructor: Initialize all members which don't have a class
   // initializer.
-  InstallPlan() : is_resume(false),
-                  payload_size(0),
-                  metadata_size(0),
-                  kernel_size(0),
-                  rootfs_size(0),
-                  hash_checks_mandatory(false) {}
+  InstallPlan();
+
+  bool operator==(const InstallPlan& that) const;
+  bool operator!=(const InstallPlan& that) const;
+
+  void Dump() const;
 
   bool is_resume;
   std::string download_url;  // url to download from
@@ -75,31 +63,9 @@
   // the Omaha response.
   bool hash_checks_mandatory;
 
-  bool operator==(const InstallPlan& that) const {
-    return ((is_resume == that.is_resume) &&
-            (download_url == that.download_url) &&
-            (payload_size == that.payload_size) &&
-            (payload_hash == that.payload_hash) &&
-            (metadata_size == that.metadata_size) &&
-            (metadata_signature == that.metadata_signature) &&
-            (install_path == that.install_path) &&
-            (kernel_install_path == that.kernel_install_path));
-  }
-  bool operator!=(const InstallPlan& that) const {
-    return !((*this) == that);
-  }
-  void Dump() const {
-    LOG(INFO) << "InstallPlan: "
-              << (is_resume ? ", resume" : ", new_update")
-              << ", url: " << download_url
-              << ", payload size: " << payload_size
-              << ", payload hash: " << payload_hash
-              << ", metadata size: " << metadata_size
-              << ", metadata signature: " << metadata_signature
-              << ", install_path: " << install_path
-              << ", kernel_install_path: " << kernel_install_path
-              << ", hash_checks_mandatory: " << hash_checks_mandatory;
-  }
+  // True if Powerwash is required on reboot after applying the payload.
+  // False otherwise.
+  bool powerwash_required;
 };
 
 }  // namespace chromeos_update_engine