AU: Optimize checkpointing a bit and decide on new update vs. resume.
BUG=7390
TEST=unit tests, gmerged on device
Change-Id: Ibed6082fe697e6b28b03fb1cc39d700826bf2bfe
Review URL: http://codereview.chromium.org/3541016
diff --git a/delta_performer.h b/delta_performer.h
index 2f9fd8a..87a27dd 100644
--- a/delta_performer.h
+++ b/delta_performer.h
@@ -31,6 +31,7 @@
manifest_valid_(false),
next_operation_num_(0),
buffer_offset_(0),
+ last_updated_buffer_offset_(kuint64max),
block_size_(0) {}
// Opens the kernel. Should be called before or after Open(), but before
@@ -72,6 +73,15 @@
uint64_t full_length,
std::string* positions_string);
+ // Returns true if a previous update attempt can be continued based on the
+ // persistent preferences and the new update check response hash.
+ static bool CanResumeUpdate(PrefsInterface* prefs,
+ std::string update_check_response_hash);
+
+ // Resets the persistent update progress state to indicate that an update
+ // can't be resumed. Returns true on success, false otherwise.
+ static bool ResetUpdateProgress(PrefsInterface* prefs);
+
private:
// Returns true if enough of the delta file has been passed via Write()
// to be able to perform a given install operation.
@@ -102,7 +112,8 @@
// updates the hash calculator with these bytes before discarding them.
void DiscardBufferHeadBytes(size_t count, bool do_hash);
- bool ResetUpdateProgress();
+ // Checkpoints the update progress into persistent storage to allow this
+ // update attempt to be resumed after reboot.
bool CheckpointUpdateProgress();
// Update Engine preference store.
@@ -131,6 +142,9 @@
// Offset of buffer_ in the binary blobs section of the update.
uint64_t buffer_offset_;
+ // Last |buffer_offset_| value updated as part of the progress update.
+ uint64_t last_updated_buffer_offset_;
+
// The block size (parsed from the manifest).
uint32_t block_size_;