AU: Implement exponential back off for 500 and 503 HTTP response codes.

Also refactors the automatic update checks into a separate
scheduler class and adds unit tests for them.

update_check_scheduler.cc                  59 /   59: 100.0%
update_check_scheduler.h                    1 /    1: 100.0%

Note: because the unit tests for this CL use the
UpdateAttempter class, the CL brings in several untested
modules into the test report reducing the overall test
coverage to ~82%.

BUG=2394
TEST=unit tests, gmerged on device and inspected logs

Change-Id: I078b1727b5338f6fc34e51f5e04a375518d63cef

Review URL: http://codereview.chromium.org/3215006
diff --git a/update_attempter.h b/update_attempter.h
index 1c9ad40..fd9bc2a 100644
--- a/update_attempter.h
+++ b/update_attempter.h
@@ -24,9 +24,7 @@
 
 namespace chromeos_update_engine {
 
-namespace utils {
-enum ProcessPriority;
-};
+class UpdateCheckScheduler;
 
 extern const char* kUpdateCompletedMarker;
 
@@ -47,12 +45,13 @@
                         public DownloadActionDelegate {
  public:
   UpdateAttempter(PrefsInterface* prefs, MetricsLibraryInterface* metrics_lib);
-  ~UpdateAttempter();
+  virtual ~UpdateAttempter();
 
   // Checks for update and, if a newer version is available, attempts
   // to update the system. Non-empty |in_app_version| or
   // |in_update_url| prevents automatic detection of the parameter.
-  void Update(const std::string& app_version, const std::string& omaha_url);
+  virtual void Update(const std::string& app_version,
+                      const std::string& omaha_url);
 
   // ActionProcessorDelegate methods:
   void ProcessingDone(const ActionProcessor* processor, ActionExitCode code);
@@ -75,10 +74,22 @@
                  std::string* new_version,
                  int64_t* new_size);
 
+  UpdateStatus status() const { return status_; }
+
+  int http_response_code() const { return http_response_code_; }
+  void set_http_response_code(int code) { http_response_code_ = code; }
+
   void set_dbus_service(struct UpdateEngineService* dbus_service) {
     dbus_service_ = dbus_service;
   }
 
+  UpdateCheckScheduler* update_check_scheduler() const {
+    return update_check_scheduler_;
+  }
+  void set_update_check_scheduler(UpdateCheckScheduler* scheduler) {
+    update_check_scheduler_ = scheduler;
+  }
+
   // This is the D-Bus service entry point for going through an
   // update. If the current status is idle invokes Update.
   void CheckForUpdate(const std::string& app_version,
@@ -88,13 +99,6 @@
   // UPDATED_NEED_REBOOT. Returns true on sucess, false otherwise.
   bool RebootIfNeeded();
 
-  // Kicks off the periodic update checks, if necessary.
-  void InitiatePeriodicUpdateChecks();
-
-  // Schedules the next periodic update check |seconds| from now. Note
-  // that the actual timeout will be fuzzed.
-  void SchedulePeriodicUpdateCheck(int seconds);
-
   // DownloadActionDelegate methods
   void SetDownloadStatus(bool active);
   void BytesReceived(uint64_t bytes_received, uint64_t total);
@@ -155,9 +159,14 @@
   // Pointer to the UMA metrics collection library.
   MetricsLibraryInterface* metrics_lib_;
 
+  // The current UpdateCheckScheduler to notify of state transitions.
+  UpdateCheckScheduler* update_check_scheduler_;
+
   // Pending error event, if any.
   scoped_ptr<OmahaEvent> error_event_;
 
+  int http_response_code_;
+
   // Current process priority.
   utils::ProcessPriority priority_;