AU: Only retry HTTP connect failures when updating in background.

Interactive updates (those that come from dbus, rather than a timer)
will have the check for updates retry on failed HTTP connections only
once. We will still retry on connect failures for background updates 3
times, which is important for the case where a user has just woken
from sleep.

BUG=chromium-os:16255
TEST=unittests, on device test

Change-Id: I9cb0f854856846850cfdeaa4ffbe921d76eee15b
Reviewed-on: http://gerrit.chromium.org/gerrit/2449
Tested-by: Andrew de los Reyes <adlr@chromium.org>
Reviewed-by: Darin Petkov <petkov@chromium.org>
diff --git a/update_attempter.cc b/update_attempter.cc
index a1efa95..f29b3d7 100644
--- a/update_attempter.cc
+++ b/update_attempter.cc
@@ -130,7 +130,8 @@
 
 void UpdateAttempter::Update(const std::string& app_version,
                              const std::string& omaha_url,
-                             bool obey_proxies) {
+                             bool obey_proxies,
+                             bool interactive) {
   chrome_proxy_resolver_.Init();
   fake_update_success_ = false;
   if (status_ == UPDATE_STATUS_UPDATED_NEED_REBOOT) {
@@ -175,9 +176,9 @@
   // Actions:
   LibcurlHttpFetcher* update_check_fetcher =
       new LibcurlHttpFetcher(GetProxyResolver());
-  // Try harder to connect to the network. See comment in
-  // libcurl_http_fetcher.cc.
-  update_check_fetcher->set_no_network_max_retries(3);
+  // Try harder to connect to the network, esp when not interactive.
+  // See comment in libcurl_http_fetcher.cc.
+  update_check_fetcher->set_no_network_max_retries(interactive ? 1 : 3);
   shared_ptr<OmahaRequestAction> update_check_action(
       new OmahaRequestAction(prefs_,
                              omaha_request_params_,
@@ -293,7 +294,7 @@
               << UpdateStatusToString(status_) << ", so not checking.";
     return;
   }
-  Update(app_version, omaha_url, true);
+  Update(app_version, omaha_url, true, true);
 }
 
 bool UpdateAttempter::RebootIfNeeded() {
diff --git a/update_attempter.h b/update_attempter.h
index f4b82ff..33e97c5 100644
--- a/update_attempter.h
+++ b/update_attempter.h
@@ -59,9 +59,11 @@
   // |in_update_url| prevents automatic detection of the parameter.
   // If |obey_proxies| is true, the update will likely respect Chrome's
   // proxy setting. For security reasons, we may still not honor them.
+  // Interactive should be true if this was called from the user (ie dbus).
   virtual void Update(const std::string& app_version,
                       const std::string& omaha_url,
-                      bool obey_proxies);
+                      bool obey_proxies,
+                      bool interactive);
 
   // ActionProcessorDelegate methods:
   void ProcessingDone(const ActionProcessor* processor, ActionExitCode code);
diff --git a/update_attempter_mock.h b/update_attempter_mock.h
index 16c0e11..21fa4a3 100644
--- a/update_attempter_mock.h
+++ b/update_attempter_mock.h
@@ -17,9 +17,10 @@
   explicit UpdateAttempterMock(MockDbusGlib* dbus)
       : UpdateAttempter(NULL, NULL, dbus) {}
 
-  MOCK_METHOD3(Update, void(const std::string& app_version,
+  MOCK_METHOD4(Update, void(const std::string& app_version,
                             const std::string& omaha_url,
-                            bool obey_proxies));
+                            bool obey_proxies,
+                            bool interactive));
 };
 
 }  // namespace chromeos_update_engine
diff --git a/update_attempter_unittest.cc b/update_attempter_unittest.cc
index 8b7be1a..4059957 100644
--- a/update_attempter_unittest.cc
+++ b/update_attempter_unittest.cc
@@ -284,7 +284,7 @@
   }
   EXPECT_CALL(*processor_, StartProcessing()).Times(1);
 
-  attempter_.Update("", "", false);
+  attempter_.Update("", "", false, false);
   g_idle_add(&StaticUpdateTestVerify, this);
 }
 
diff --git a/update_check_scheduler.cc b/update_check_scheduler.cc
index f9b45bd..2d08aea 100644
--- a/update_check_scheduler.cc
+++ b/update_check_scheduler.cc
@@ -82,7 +82,7 @@
   CHECK(me->scheduled_);
   me->scheduled_ = false;
   if (me->IsOOBEComplete()) {
-    me->update_attempter_->Update("", "", false);
+    me->update_attempter_->Update("", "", false, false);
   } else {
     // Skips all automatic update checks if the OOBE process is not complete and
     // schedules a new check as if it is the first one.
diff --git a/update_check_scheduler_unittest.cc b/update_check_scheduler_unittest.cc
index c1dd330..010cc82 100644
--- a/update_check_scheduler_unittest.cc
+++ b/update_check_scheduler_unittest.cc
@@ -271,7 +271,7 @@
 TEST_F(UpdateCheckSchedulerTest, StaticCheckOOBECompleteTest) {
   scheduler_.scheduled_ = true;
   EXPECT_CALL(scheduler_, IsOOBEComplete()).Times(1).WillOnce(Return(true));
-  EXPECT_CALL(attempter_, Update("", "", false))
+  EXPECT_CALL(attempter_, Update("", "", false, false))
       .Times(1)
       .WillOnce(Assign(&scheduler_.scheduled_, true));
   scheduler_.enabled_ = true;
@@ -282,7 +282,7 @@
 TEST_F(UpdateCheckSchedulerTest, StaticCheckOOBENotCompleteTest) {
   scheduler_.scheduled_ = true;
   EXPECT_CALL(scheduler_, IsOOBEComplete()).Times(1).WillOnce(Return(false));
-  EXPECT_CALL(attempter_, Update("", "", _)).Times(0);
+  EXPECT_CALL(attempter_, Update("", "", _, _)).Times(0);
   int interval_min, interval_max;
   FuzzRange(UpdateCheckScheduler::kTimeoutOnce,
             UpdateCheckScheduler::kTimeoutRegularFuzz,