Support in update_engine for the crosh autest "-scheduled" option.

This is needed to enable manual testing of scattering feature on
MP-signed images.

BUG=chromium-os:32289
TEST=update_engine_client works as expected on zgb when passing
     autest and autest-scatter to omaha_url.
Change-Id: Ib3d3e70f2e87632b6a61c7e5cd45791210c12c99
Reviewed-on: https://gerrit.chromium.org/gerrit/27005
Reviewed-by: Gilad Arnold <garnold@chromium.org>
Reviewed-by: Jay Srinivasan <jaysri@chromium.org>
Tested-by: Jay Srinivasan <jaysri@chromium.org>
Commit-Ready: Jay Srinivasan <jaysri@chromium.org>
diff --git a/dbus_service.cc b/dbus_service.cc
index 988ae2e..ef68596 100644
--- a/dbus_service.cc
+++ b/dbus_service.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium OS Authors. All rights reserved.
+// Copyright (c) 2012 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.
 
@@ -15,6 +15,11 @@
 using std::string;
 
 static const char kAUTestURLRequest[] = "autest";
+// By default autest bypasses scattering. If we want to test scattering,
+// we should use autest-scheduled. The Url used is same in both cases, but
+// different params are passed to CheckForUpdate method.
+static const char kScheduledAUTestURLRequest[] = "autest-scheduled";
+
 static const char kAUTestURL[] =
     "https://omaha.sandbox.google.com/service/update2";
 
@@ -62,6 +67,8 @@
                                               GError **error) {
   string update_app_version;
   string update_omaha_url;
+  bool is_user_initiated = true;
+
   // Only non-official (e.g., dev and test) builds can override the current
   // version and update server URL over D-Bus. However, pointing to the
   // hardcoded test update server URL is always allowed.
@@ -73,12 +80,23 @@
       update_omaha_url = omaha_url;
     }
   }
-  if (omaha_url && strcmp(omaha_url, kAUTestURLRequest) == 0) {
-    update_omaha_url = kAUTestURL;
+  if (omaha_url) {
+    if (strcmp(omaha_url, kScheduledAUTestURLRequest) == 0) {
+      update_omaha_url = kAUTestURL;
+      // pretend that it's not user-initiated even though it is,
+      // so as to test scattering logic, etc. which get kicked off
+      // only in scheduled update checks.
+      is_user_initiated = false;
+    } else if (strcmp(omaha_url, kAUTestURLRequest) == 0) {
+      update_omaha_url = kAUTestURL;
+    }
   }
   LOG(INFO) << "Attempt update: app_version=\"" << update_app_version << "\" "
-            << "omaha_url=\"" << update_omaha_url << "\"";
-  self->update_attempter_->CheckForUpdate(update_app_version, update_omaha_url);
+            << "omaha_url=\"" << update_omaha_url << "\" "
+            << "is_user_initiated=" << (is_user_initiated? "yes" : "no");
+  self->update_attempter_->CheckForUpdate(update_app_version,
+                                          update_omaha_url,
+                                          is_user_initiated);
   return TRUE;
 }
 
diff --git a/update_attempter.cc b/update_attempter.cc
index 68c1417..8b77a95 100644
--- a/update_attempter.cc
+++ b/update_attempter.cc
@@ -456,7 +456,8 @@
 }
 
 void UpdateAttempter::CheckForUpdate(const string& app_version,
-                                     const string& omaha_url) {
+                                     const string& omaha_url,
+                                     bool is_user_initiated) {
   LOG(INFO) << "New update check requested";
 
   if (status_ != UPDATE_STATUS_IDLE) {
@@ -477,7 +478,7 @@
 
   // Passing true for is_user_initiated to indicate that this
   // is not a scheduled update check.
-  Update(app_version, omaha_url, true, true, is_test, true);
+  Update(app_version, omaha_url, true, true, is_test, is_user_initiated);
 }
 
 bool UpdateAttempter::RebootIfNeeded() {
diff --git a/update_attempter.h b/update_attempter.h
index 7a1855f..77af499 100644
--- a/update_attempter.h
+++ b/update_attempter.h
@@ -133,10 +133,12 @@
     update_check_scheduler_ = scheduler;
   }
 
-  // This is the D-Bus service entry point for going through an
+  // This is the internal entry point for going through an
   // update. If the current status is idle invokes Update.
+  // This is called by the DBus implementation.
   void CheckForUpdate(const std::string& app_version,
-                      const std::string& omaha_url);
+                      const std::string& omaha_url,
+                      bool is_user_initiated);
 
   // Initiates a reboot if the current state is
   // UPDATED_NEED_REBOOT. Returns true on sucess, false otherwise.