AU: Don't allow stateful /etc/lsb-release override in normal boot mode...

... on official images except for the release track.

BUG=chromium-os:6244
TEST=unit tests, tested on device

Change-Id: I2d2a634c7b5ac7dd4619f52d1f79b6d88c359e46

Review URL: http://codereview.chromium.org/6225001
diff --git a/omaha_request_params.cc b/omaha_request_params.cc
index eaff3d3..ed80060 100644
--- a/omaha_request_params.cc
+++ b/omaha_request_params.cc
@@ -38,27 +38,29 @@
 static const char kHWIDPath[] = "/sys/devices/platform/chromeos_acpi/HWID";
 
 OmahaRequestDeviceParams::OmahaRequestDeviceParams() :
-    force_build_type_(false),
-    forced_official_build_(false) {}
+    force_lock_down_(false),
+    forced_lock_down_(false) {}
 
 bool OmahaRequestDeviceParams::Init(const std::string& in_app_version,
                                     const std::string& in_update_url) {
+  bool stateful_override = !ShouldLockDown();
   os_platform = OmahaRequestParams::kOsPlatform;
   os_version = OmahaRequestParams::kOsVersion;
   app_version = in_app_version.empty() ?
-      GetLsbValue("CHROMEOS_RELEASE_VERSION", "", NULL, true) : in_app_version;
+      GetLsbValue("CHROMEOS_RELEASE_VERSION", "", NULL, stateful_override) :
+      in_app_version;
   os_sp = app_version + "_" + GetMachineType();
-  os_board = GetLsbValue("CHROMEOS_RELEASE_BOARD", "", NULL, true);
+  os_board = GetLsbValue("CHROMEOS_RELEASE_BOARD", "", NULL, stateful_override);
   app_id = GetLsbValue("CHROMEOS_RELEASE_APPID",
                        OmahaRequestParams::kAppId,
                        NULL,
-                       true);
+                       stateful_override);
   app_lang = "en-US";
   app_track = GetLsbValue(
       kUpdateTrackKey,
       "",
       &chromeos_update_engine::OmahaRequestDeviceParams::IsValidTrack,
-      true);
+      true);  // stateful_override
   hardware_class = GetHardwareClass();
   struct stat stbuf;
 
@@ -81,15 +83,15 @@
   const string rootfs_track = GetLsbValue(
       kUpdateTrackKey,
       "",
-      &chromeos_update_engine::OmahaRequestDeviceParams::IsValidTrack,
-      false);
+      NULL,  // No need to validate the read-only rootfs track.
+      false);  // stateful_override
   delta_okay = delta_okay && rootfs_track == app_track;
 
   update_url = in_update_url.empty() ?
       GetLsbValue("CHROMEOS_AUSERVER",
                   OmahaRequestParams::kUpdateUrl,
                   NULL,
-                  true) :
+                  stateful_override) :
       in_update_url;
   return true;
 }
@@ -173,8 +175,11 @@
   return hwid;
 }
 
-bool OmahaRequestDeviceParams::IsOfficialBuild() const {
-  return force_build_type_ ? forced_official_build_ : utils::IsOfficialBuild();
+bool OmahaRequestDeviceParams::ShouldLockDown() const {
+  if (force_lock_down_) {
+    return forced_lock_down_;
+  }
+  return utils::IsOfficialBuild() && utils::IsNormalBootMode();
 }
 
 bool OmahaRequestDeviceParams::IsValidTrack(const std::string& track) const {
@@ -183,7 +188,7 @@
     "beta-channel",
     "dev-channel",
   };
-  if (!IsOfficialBuild()) {
+  if (!ShouldLockDown()) {
     return true;
   }
   for (size_t t = 0; t < arraysize(kValidTracks); ++t) {
@@ -194,9 +199,9 @@
   return false;
 }
 
-void OmahaRequestDeviceParams::SetBuildTypeOfficial(bool is_official) {
-  force_build_type_ = true;
-  forced_official_build_ = is_official;
+void OmahaRequestDeviceParams::SetLockDown(bool lock) {
+  force_lock_down_ = true;
+  forced_lock_down_ = lock;
 }
 
 }  // namespace chromeos_update_engine