Update engine should use the release channel policy if it exists.

The release channel (aka update track) can be specified by a device
policy. When this is the case, the update engine should use the
value specified by the policy instead of the value specified in
/etc/lsb-release.

BUG=chromium-os:17015
TEST=Added two new tests:
- Added test that OmahaRequestParams uses the release channel passed
  in to it when the value is valid, and otherwise uses /etc/lsb-release.
- Added test that the update engine correctly picks up the release
  channel that's specified by the policy.

Change-Id: I2fe03712220bb3286476b12cd1f1b330ad006d7c
Reviewed-on: http://gerrit.chromium.org/gerrit/5072
Tested-by: Patrick Dubroy <dubroy@chromium.org>
Reviewed-by: Andrew de los Reyes <adlr@chromium.org>
diff --git a/omaha_request_params.cc b/omaha_request_params.cc
index 0f5af5b..c4dff9d 100644
--- a/omaha_request_params.cc
+++ b/omaha_request_params.cc
@@ -13,6 +13,7 @@
 #include <vector>
 
 #include <base/file_util.h>
+#include <policy/device_policy.h>
 
 #include "update_engine/simple_key_value_store.h"
 #include "update_engine/utils.h"
@@ -25,8 +26,6 @@
 
 namespace chromeos_update_engine {
 
-const char OmahaRequestParams::kUpdateTrackKey[] = "CHROMEOS_RELEASE_TRACK";
-
 const char* const OmahaRequestParams::kAppId(
     "{87efface-864d-49a5-9bb3-4b050a7c227a}");
 const char* const OmahaRequestParams::kOsPlatform("Chrome OS");
@@ -34,12 +33,15 @@
 const char* const OmahaRequestParams::kUpdateUrl(
     "https://tools.google.com/service/update2");
 
+const char OmahaRequestParams::kUpdateTrackKey[] = "CHROMEOS_RELEASE_TRACK";
+
 OmahaRequestDeviceParams::OmahaRequestDeviceParams() :
     force_lock_down_(false),
     forced_lock_down_(false) {}
 
 bool OmahaRequestDeviceParams::Init(const std::string& in_app_version,
-                                    const std::string& in_update_url) {
+                                    const std::string& in_update_url,
+                                    const std::string& in_release_track) {
   bool stateful_override = !ShouldLockDown();
   os_platform = OmahaRequestParams::kOsPlatform;
   os_version = OmahaRequestParams::kOsVersion;
@@ -53,11 +55,18 @@
                        NULL,
                        stateful_override);
   app_lang = "en-US";
-  app_track = GetLsbValue(
-      kUpdateTrackKey,
-      "",
-      &chromeos_update_engine::OmahaRequestDeviceParams::IsValidTrack,
-      true);  // stateful_override
+
+  // Determine the release track if it wasn't specified by the caller.
+  if (in_release_track.empty() || !IsValidTrack(in_release_track)) {
+    app_track = GetLsbValue(
+        kUpdateTrackKey,
+        "",
+        &chromeos_update_engine::OmahaRequestDeviceParams::IsValidTrack,
+        true);  // stateful_override
+  } else {
+    app_track = in_release_track;
+  }
+
   hardware_class = utils::GetHardwareClass();
   struct stat stbuf;
 
@@ -113,7 +122,7 @@
 
 bool OmahaRequestDeviceParams::SetDeviceTrack(const std::string& track) {
   OmahaRequestDeviceParams params;
-  TEST_AND_RETURN_FALSE(params.Init("", ""));
+  TEST_AND_RETURN_FALSE(params.Init("", "", ""));
   return params.SetTrack(track);
 }
 
@@ -121,7 +130,7 @@
   OmahaRequestDeviceParams params;
   // Note that params.app_track is an empty string if the value in
   // lsb-release file is invalid. See Init() for details.
-  return params.Init("", "") ? params.app_track : "";
+  return params.Init("", "", "") ? params.app_track : "";
 }
 
 string OmahaRequestDeviceParams::GetLsbValue(const string& key,