Don't schedule periodic update checks for non-official builds.

BUG=5334
TEST=unit tests, gmerged on device and tried with different tracks

Review URL: http://codereview.chromium.org/3041044
diff --git a/main.cc b/main.cc
index bdd216c..9e7a1ef 100644
--- a/main.cc
+++ b/main.cc
@@ -16,6 +16,7 @@
 #include "update_engine/dbus_service.h"
 #include "update_engine/prefs.h"
 #include "update_engine/update_attempter.h"
+#include "update_engine/utils.h"
 
 extern "C" {
 #include "update_engine/update_engine.dbusserver.h"
@@ -34,15 +35,28 @@
 
 namespace {
 
-struct PeriodicallyUpdateArgs {
-  UpdateAttempter* update_attempter;
-  gboolean should_repeat;
-};
+gboolean UpdateOnce(void* arg) {
+  UpdateAttempter* update_attempter = reinterpret_cast<UpdateAttempter*>(arg);
+  update_attempter->Update("", "");
+  return FALSE;
+}
 
-gboolean PeriodicallyUpdate(void* arg) {
-  PeriodicallyUpdateArgs* args = reinterpret_cast<PeriodicallyUpdateArgs*>(arg);
-  args->update_attempter->Update("", "");
-  return args->should_repeat;
+gboolean UpdatePeriodically(void* arg) {
+  UpdateAttempter* update_attempter = reinterpret_cast<UpdateAttempter*>(arg);
+  update_attempter->Update("", "");
+  return TRUE;
+}
+
+void SchedulePeriodicUpdateChecks(UpdateAttempter* update_attempter) {
+  if (!utils::IsOfficialBuild()) {
+    LOG(WARNING) << "No periodic update checks on non-official builds.";
+    return;
+  }
+
+  // Kick off periodic updating. First, update after 2 minutes. Also, update
+  // every 30 minutes.
+  g_timeout_add(2 * 60 * 1000, &UpdateOnce, update_attempter);
+  g_timeout_add(30 * 60 * 1000, &UpdatePeriodically, update_attempter);
 }
 
 void SetupDbusService(UpdateEngineService* service) {
@@ -126,19 +140,7 @@
   update_attempter.set_dbus_service(service);
   chromeos_update_engine::SetupDbusService(service);
 
-  // Kick off periodic updating. First, update after 2 minutes. Also, update
-  // every 30 minutes.
-  chromeos_update_engine::PeriodicallyUpdateArgs two_min_args =
-      {&update_attempter, FALSE};
-  g_timeout_add(2 * 60 * 1000,
-                &chromeos_update_engine::PeriodicallyUpdate,
-                &two_min_args);
-
-  chromeos_update_engine::PeriodicallyUpdateArgs thirty_min_args =
-      {&update_attempter, TRUE};
-  g_timeout_add(30 * 60 * 1000,
-                &chromeos_update_engine::PeriodicallyUpdate,
-                &thirty_min_args);
+  chromeos_update_engine::SchedulePeriodicUpdateChecks(&update_attempter);
 
   // Run the main loop until exit time:
   g_main_loop_run(loop);
diff --git a/utils.cc b/utils.cc
index 4c5a195..d691739 100644
--- a/utils.cc
+++ b/utils.cc
@@ -16,6 +16,7 @@
 #include <algorithm>
 #include "chromeos/obsolete_logging.h"
 #include "update_engine/file_writer.h"
+#include "update_engine/omaha_request_params.h"
 #include "update_engine/subprocess.h"
 
 using std::min;
@@ -26,6 +27,15 @@
 
 namespace utils {
 
+bool IsOfficialBuild() {
+  OmahaRequestDeviceParams params;
+  if (!params.Init("", "")) {
+    return true;
+  }
+  return params.app_track != "buildbot-build" &&
+      params.app_track != "developer-build";
+}
+
 bool WriteFile(const char* path, const char* data, int data_len) {
   DirectFileWriter writer;
   TEST_AND_RETURN_FALSE_ERRNO(0 == writer.Open(path,
diff --git a/utils.h b/utils.h
index 9be2509..f7f734e 100644
--- a/utils.h
+++ b/utils.h
@@ -18,6 +18,12 @@
 
 namespace utils {
 
+// Returns true if this is an official Chrome OS build, false
+// otherwise. Currently, this routine errs on the official build side
+// -- if it doesn't recognize the update track as non-official, it
+// assumes the build is official.
+bool IsOfficialBuild();
+
 // Writes the data passed to path. The file at path will be overwritten if it
 // exists. Returns true on success, false otherwise.
 bool WriteFile(const char* path, const char* data, int data_len);
diff --git a/utils_unittest.cc b/utils_unittest.cc
index a66e739..b67114a 100644
--- a/utils_unittest.cc
+++ b/utils_unittest.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// Copyright (c) 2010 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.
 
@@ -17,6 +17,11 @@
 
 class UtilsTest : public ::testing::Test { };
 
+TEST(UtilsTest, IsOfficialBuild) {
+  // Pretty lame test...
+  EXPECT_TRUE(utils::IsOfficialBuild());
+}
+
 TEST(UtilsTest, NormalizePathTest) {
   EXPECT_EQ("", utils::NormalizePath("", false));
   EXPECT_EQ("", utils::NormalizePath("", true));