blob: 76fe3fb4a4ddd6c7a13bfea41ebfc28151af766e [file] [log] [blame]
Andrew de los Reyes4e9b9f42010-04-26 15:06:43 -07001// Copyright (c) 2010 The Chromium OS Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef CHROMEOS_PLATFORM_UPDATE_ENGINE_UPDATE_ATTEMPTER_H__
6#define CHROMEOS_PLATFORM_UPDATE_ENGINE_UPDATE_ATTEMPTER_H__
7
Andrew de los Reyes63b96d72010-05-10 13:08:54 -07008#include <time.h>
Andrew de los Reyes4e9b9f42010-04-26 15:06:43 -07009#include <tr1/memory>
10#include <string>
11#include <vector>
12#include <glib.h>
13#include "update_engine/action_processor.h"
Andrew de los Reyes63b96d72010-05-10 13:08:54 -070014#include "update_engine/download_action.h"
Andrew de los Reyes4e9b9f42010-04-26 15:06:43 -070015#include "update_engine/omaha_response_handler_action.h"
16
Andrew de los Reyes63b96d72010-05-10 13:08:54 -070017struct UpdateEngineService;
18
Andrew de los Reyes4e9b9f42010-04-26 15:06:43 -070019namespace chromeos_update_engine {
20
Andrew de los Reyes63b96d72010-05-10 13:08:54 -070021enum UpdateStatus {
22 UPDATE_STATUS_IDLE = 0,
23 UPDATE_STATUS_CHECKING_FOR_UPDATE,
24 UPDATE_STATUS_UPDATE_AVAILABLE,
25 UPDATE_STATUS_DOWNLOADING,
26 UPDATE_STATUS_VERIFYING,
27 UPDATE_STATUS_FINALIZING,
28 UPDATE_STATUS_UPDATED_NEED_REBOOT
29};
30
31const char* UpdateStatusToString(UpdateStatus status);
32
33class UpdateAttempter : public ActionProcessorDelegate,
34 public DownloadActionDelegate {
Andrew de los Reyes4e9b9f42010-04-26 15:06:43 -070035 public:
Andrew de los Reyes63b96d72010-05-10 13:08:54 -070036 UpdateAttempter() : full_update_(false),
37 dbus_service_(NULL),
38 status_(UPDATE_STATUS_IDLE),
39 download_progress_(0.0),
40 last_checked_time_(0),
41 new_version_("0.0.0.0"),
42 new_size_(0) {
43 last_notify_time_.tv_sec = 0;
44 last_notify_time_.tv_nsec = 0;
45 }
Andrew de los Reyes4e9b9f42010-04-26 15:06:43 -070046 void Update(bool force_full_update);
47
Andrew de los Reyes63b96d72010-05-10 13:08:54 -070048 // ActionProcessorDelegate methods:
Andrew de los Reyes4e9b9f42010-04-26 15:06:43 -070049 void ProcessingDone(const ActionProcessor* processor, bool success);
Andrew de los Reyes63b96d72010-05-10 13:08:54 -070050 void ProcessingStopped(const ActionProcessor* processor);
51 void ActionCompleted(ActionProcessor* processor,
52 AbstractAction* action,
53 bool success);
Andrew de los Reyes4e9b9f42010-04-26 15:06:43 -070054
55 // Stop updating. An attempt will be made to record status to the disk
56 // so that updates can be resumed later.
57 void Terminate();
58
59 // Try to resume from a previously Terminate()d update.
60 void ResumeUpdating();
61
62 // Returns the current status in the out params. Returns true on success.
63 bool GetStatus(int64_t* last_checked_time,
64 double* progress,
65 std::string* current_operation,
66 std::string* new_version,
67 int64_t* new_size);
68
Andrew de los Reyes63b96d72010-05-10 13:08:54 -070069 void set_dbus_service(struct UpdateEngineService* dbus_service) {
70 dbus_service_ = dbus_service;
71 }
72
73 void CheckForUpdate();
74
75 // DownloadActionDelegate method
76 void BytesReceived(uint64_t bytes_received, uint64_t total);
77
Andrew de los Reyes4e9b9f42010-04-26 15:06:43 -070078 private:
Andrew de los Reyes63b96d72010-05-10 13:08:54 -070079 // Sets the status to the given status and notifies a status update
80 // over dbus.
81 void SetStatusAndNotify(UpdateStatus status);
82
83 struct timespec last_notify_time_;
84
Andrew de los Reyes4e9b9f42010-04-26 15:06:43 -070085 bool full_update_;
86 std::vector<std::tr1::shared_ptr<AbstractAction> > actions_;
87 ActionProcessor processor_;
Andrew de los Reyes63b96d72010-05-10 13:08:54 -070088
89 // If non-null, this UpdateAttempter will send status updates over this
90 // dbus service.
91 UpdateEngineService* dbus_service_;
Andrew de los Reyes4e9b9f42010-04-26 15:06:43 -070092
93 // pointer to the OmahaResponseHandlerAction in the actions_ vector;
94 std::tr1::shared_ptr<OmahaResponseHandlerAction> response_handler_action_;
Andrew de los Reyes63b96d72010-05-10 13:08:54 -070095
96 // For status:
97 UpdateStatus status_;
98 double download_progress_;
99 int64_t last_checked_time_;
100 std::string new_version_;
101 int64_t new_size_;
102
Andrew de los Reyes4e9b9f42010-04-26 15:06:43 -0700103 DISALLOW_COPY_AND_ASSIGN(UpdateAttempter);
104};
105
106} // namespace chromeos_update_engine
107
108#endif // CHROMEOS_PLATFORM_UPDATE_ENGINE_UPDATE_ATTEMPTER_H__