blob: 45cb61528b454f5483cbc44751f22d2a42cca2ec [file] [log] [blame]
Alex Deymoaea4c1c2015-08-19 20:24:43 -07001//
2// Copyright (C) 2010 The Android Open Source Project
3//
4// Licensed under the Apache License, Version 2.0 (the "License");
5// you may not use this file except in compliance with the License.
6// You may obtain a copy of the License at
7//
8// http://www.apache.org/licenses/LICENSE-2.0
9//
10// Unless required by applicable law or agreed to in writing, software
11// distributed under the License is distributed on an "AS IS" BASIS,
12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13// See the License for the specific language governing permissions and
14// limitations under the License.
15//
Andrew de los Reyes09e56d62010-04-23 13:45:53 -070016
Gilad Arnoldcf175a02014-07-10 16:48:47 -070017#ifndef UPDATE_ENGINE_DELTA_PERFORMER_H_
18#define UPDATE_ENGINE_DELTA_PERFORMER_H_
Andrew de los Reyes09e56d62010-04-23 13:45:53 -070019
20#include <inttypes.h>
Darin Petkovd7061ab2010-10-06 14:37:09 -070021
Alex Vakulenkod2779df2014-06-16 13:19:00 -070022#include <string>
Andrew de los Reyes09e56d62010-04-23 13:45:53 -070023#include <vector>
Darin Petkovd7061ab2010-10-06 14:37:09 -070024
Alex Vakulenko75039d72014-03-25 12:36:28 -070025#include <base/time/time.h>
Alex Vakulenkof68bbbc2015-02-09 12:53:18 -080026#include <chromeos/secure_blob.h>
Andrew de los Reyes09e56d62010-04-23 13:45:53 -070027#include <google/protobuf/repeated_field.h>
Andrew de los Reyes353777c2010-10-08 10:34:30 -070028#include <gtest/gtest_prod.h> // for FRIEND_TEST
Darin Petkovd7061ab2010-10-06 14:37:09 -070029
Nam T. Nguyenf1d582e2014-12-08 15:07:17 -080030#include "update_engine/file_descriptor.h"
Andrew de los Reyes09e56d62010-04-23 13:45:53 -070031#include "update_engine/file_writer.h"
Jay Srinivasan51dcf262012-09-13 17:24:32 -070032#include "update_engine/install_plan.h"
Darin Petkovd7061ab2010-10-06 14:37:09 -070033#include "update_engine/omaha_hash_calculator.h"
Jay Srinivasanf0572052012-10-23 18:12:56 -070034#include "update_engine/system_state.h"
Andrew de los Reyes09e56d62010-04-23 13:45:53 -070035#include "update_engine/update_metadata.pb.h"
36
37namespace chromeos_update_engine {
38
Allie Woodfdf00512015-03-02 13:34:55 -080039// The minor version used by the in-place delta generator algorithm.
40extern const uint32_t kInPlaceMinorPayloadVersion;
41
42// The minor version used by the A to B delta generator algorithm.
43extern const uint32_t kSourceMinorPayloadVersion;
44
Darin Petkov73058b42010-10-06 16:32:19 -070045class PrefsInterface;
46
Andrew de los Reyes09e56d62010-04-23 13:45:53 -070047// This class performs the actions in a delta update synchronously. The delta
48// update itself should be passed in in chunks as it is received.
49
50class DeltaPerformer : public FileWriter {
51 public:
Darin Petkov9574f7e2011-01-13 10:48:12 -080052 enum MetadataParseResult {
53 kMetadataParseSuccess,
54 kMetadataParseError,
55 kMetadataParseInsufficientData,
56 };
57
Jay Srinivasanf4318702012-09-24 11:56:24 -070058 static const uint64_t kDeltaVersionSize;
59 static const uint64_t kDeltaManifestSizeSize;
Don Garrett4d039442013-10-28 18:40:06 -070060 static const uint64_t kSupportedMajorPayloadVersion;
Don Garrettb8dd1d92013-11-22 17:40:02 -080061 static const uint64_t kSupportedMinorPayloadVersion;
62 static const uint64_t kFullPayloadMinorVersion;
Darin Petkovabc7bc02011-02-23 14:39:43 -080063 static const char kUpdatePayloadPublicKeyPath[];
64
Gilad Arnold8a86fa52013-01-15 12:35:05 -080065 // Defines the granularity of progress logging in terms of how many "completed
66 // chunks" we want to report at the most.
67 static const unsigned kProgressLogMaxChunks;
68 // Defines a timeout since the last progress was logged after which we want to
69 // force another log message (even if the current chunk was not completed).
70 static const unsigned kProgressLogTimeoutSeconds;
71 // These define the relative weights (0-100) we give to the different work
72 // components associated with an update when computing an overall progress.
73 // Currently they include the download progress and the number of completed
74 // operations. They must add up to one hundred (100).
75 static const unsigned kProgressDownloadWeight;
76 static const unsigned kProgressOperationsWeight;
77
Jay Srinivasanf0572052012-10-23 18:12:56 -070078 DeltaPerformer(PrefsInterface* prefs,
79 SystemState* system_state,
80 InstallPlan* install_plan)
Darin Petkov73058b42010-10-06 16:32:19 -070081 : prefs_(prefs),
Jay Srinivasanf0572052012-10-23 18:12:56 -070082 system_state_(system_state),
Jay Srinivasan51dcf262012-09-13 17:24:32 -070083 install_plan_(install_plan),
Nam T. Nguyenf1d582e2014-12-08 15:07:17 -080084 fd_(nullptr),
85 kernel_fd_(nullptr),
Allie Woodfdf00512015-03-02 13:34:55 -080086 source_fd_(nullptr),
87 source_kernel_fd_(nullptr),
Gilad Arnolddaa27402014-01-23 11:56:17 -080088 manifest_parsed_(false),
Andrew de los Reyes09e56d62010-04-23 13:45:53 -070089 manifest_valid_(false),
Gilad Arnoldfe133932014-01-14 12:25:50 -080090 metadata_size_(0),
Andrew de los Reyesf4c7ef12010-04-30 10:37:00 -070091 next_operation_num_(0),
Andrew de los Reyes09e56d62010-04-23 13:45:53 -070092 buffer_offset_(0),
Darin Petkov0406e402010-10-06 21:33:11 -070093 last_updated_buffer_offset_(kuint64max),
Jay Srinivasan51dcf262012-09-13 17:24:32 -070094 block_size_(0),
Gilad Arnold8a86fa52013-01-15 12:35:05 -080095 public_key_path_(kUpdatePayloadPublicKeyPath),
96 total_bytes_received_(0),
97 num_rootfs_operations_(0),
98 num_total_operations_(0),
99 overall_progress_(0),
100 last_progress_chunk_(0),
101 forced_progress_log_wait_(
Allie Woodfdf00512015-03-02 13:34:55 -0800102 base::TimeDelta::FromSeconds(kProgressLogTimeoutSeconds)),
103 supported_minor_version_(kSupportedMinorPayloadVersion) {}
Darin Petkovd7061ab2010-10-06 14:37:09 -0700104
Andrew de los Reyesf4c7ef12010-04-30 10:37:00 -0700105 // Opens the kernel. Should be called before or after Open(), but before
106 // Write(). The kernel file will be close()d when Close() is called.
107 bool OpenKernel(const char* kernel_path);
108
Allie Woodfdf00512015-03-02 13:34:55 -0800109 // Opens the source partition. The file will be closed when Close() is called.
110 bool OpenSourceRootfs(const std::string& kernel_path);
111
112 // Opens the source kernel. The file will be closed when Close() is called.
113 bool OpenSourceKernel(const std::string& source_kernel_path);
114
Andrew de los Reyes09e56d62010-04-23 13:45:53 -0700115 // flags and mode ignored. Once Close()d, a DeltaPerformer can't be
116 // Open()ed again.
Alex Deymo610277e2014-11-11 21:18:11 -0800117 int Open(const char* path, int flags, mode_t mode) override;
Andrew de los Reyes09e56d62010-04-23 13:45:53 -0700118
Jay Srinivasan51dcf262012-09-13 17:24:32 -0700119 // FileWriter's Write implementation where caller doesn't care about
120 // error codes.
Alex Deymo610277e2014-11-11 21:18:11 -0800121 bool Write(const void* bytes, size_t count) override {
David Zeuthena99981f2013-04-29 13:42:47 -0700122 ErrorCode error;
Jay Srinivasan51dcf262012-09-13 17:24:32 -0700123 return Write(bytes, count, &error);
124 }
125
126 // FileWriter's Write implementation that returns a more specific |error| code
127 // in case of failures in Write operation.
Alex Deymo610277e2014-11-11 21:18:11 -0800128 bool Write(const void* bytes, size_t count, ErrorCode *error) override;
Andrew de los Reyes09e56d62010-04-23 13:45:53 -0700129
130 // Wrapper around close. Returns 0 on success or -errno on error.
Andrew de los Reyesf4c7ef12010-04-30 10:37:00 -0700131 // Closes both 'path' given to Open() and the kernel path.
Alex Deymo610277e2014-11-11 21:18:11 -0800132 int Close() override;
Darin Petkovd7061ab2010-10-06 14:37:09 -0700133
David Zeuthen8f191b22013-08-06 12:27:50 -0700134 // Returns |true| only if the manifest has been processed and it's valid.
135 bool IsManifestValid();
136
Darin Petkovd7061ab2010-10-06 14:37:09 -0700137 // Verifies the downloaded payload against the signed hash included in the
Jay Srinivasan51dcf262012-09-13 17:24:32 -0700138 // payload, against the update check hash (which is in base64 format) and
Gilad Arnoldd1c4d2d2014-06-05 14:07:53 -0700139 // size using the public key and returns ErrorCode::kSuccess on success, an
Jay Srinivasan51dcf262012-09-13 17:24:32 -0700140 // error code on failure. This method should be called after closing the
141 // stream. Note this method skips the signed hash check if the public key is
Gilad Arnoldd1c4d2d2014-06-05 14:07:53 -0700142 // unavailable; it returns ErrorCode::kSignedDeltaPayloadExpectedError if the
Jay Srinivasan51dcf262012-09-13 17:24:32 -0700143 // public key is available but the delta payload doesn't include a signature.
David Zeuthena99981f2013-04-29 13:42:47 -0700144 ErrorCode VerifyPayload(const std::string& update_check_response_hash,
Allie Wood9f6f0a52015-03-30 11:25:47 -0700145 const uint64_t update_check_response_size);
Darin Petkovd7061ab2010-10-06 14:37:09 -0700146
Darin Petkov3aefa862010-12-07 14:45:00 -0800147 // Reads from the update manifest the expected sizes and hashes of the target
148 // kernel and rootfs partitions. These values can be used for applied update
149 // hash verification. This method must be called after the update manifest has
150 // been parsed (e.g., after closing the stream). Returns true on success, and
151 // false on failure (e.g., when the values are not present in the update
152 // manifest).
153 bool GetNewPartitionInfo(uint64_t* kernel_size,
Alex Vakulenkof68bbbc2015-02-09 12:53:18 -0800154 chromeos::Blob* kernel_hash,
Darin Petkov3aefa862010-12-07 14:45:00 -0800155 uint64_t* rootfs_size,
Alex Vakulenkof68bbbc2015-02-09 12:53:18 -0800156 chromeos::Blob* rootfs_hash);
Darin Petkov2dd01092010-10-08 15:43:05 -0700157
Andrew de los Reyes09e56d62010-04-23 13:45:53 -0700158 // Converts an ordered collection of Extent objects which contain data of
159 // length full_length to a comma-separated string. For each Extent, the
160 // string will have the start offset and then the length in bytes.
161 // The length value of the last extent in the string may be short, since
162 // the full length of all extents in the string is capped to full_length.
163 // Also, an extent starting at kSparseHole, appears as -1 in the string.
164 // For example, if the Extents are {1, 1}, {4, 2}, {kSparseHole, 1},
165 // {0, 1}, block_size is 4096, and full_length is 5 * block_size - 13,
166 // the resulting string will be: "4096:4096,16384:8192,-1:4096,0:4083"
167 static bool ExtentsToBsdiffPositionsString(
168 const google::protobuf::RepeatedPtrField<Extent>& extents,
169 uint64_t block_size,
170 uint64_t full_length,
171 std::string* positions_string);
172
Darin Petkov0406e402010-10-06 21:33:11 -0700173 // Returns true if a previous update attempt can be continued based on the
174 // persistent preferences and the new update check response hash.
175 static bool CanResumeUpdate(PrefsInterface* prefs,
176 std::string update_check_response_hash);
177
178 // Resets the persistent update progress state to indicate that an update
Darin Petkov9b230572010-10-08 10:20:09 -0700179 // can't be resumed. Performs a quick update-in-progress reset if |quick| is
180 // true, otherwise resets all progress-related update state. Returns true on
181 // success, false otherwise.
182 static bool ResetUpdateProgress(PrefsInterface* prefs, bool quick);
Darin Petkov0406e402010-10-06 21:33:11 -0700183
Darin Petkov9574f7e2011-01-13 10:48:12 -0800184 // Attempts to parse the update metadata starting from the beginning of
Gilad Arnolddaa27402014-01-23 11:56:17 -0800185 // |payload|. On success, returns kMetadataParseSuccess. Returns
Gilad Arnoldfe133932014-01-14 12:25:50 -0800186 // kMetadataParseInsufficientData if more data is needed to parse the complete
187 // metadata. Returns kMetadataParseError if the metadata can't be parsed given
188 // the payload.
Alex Vakulenkof68bbbc2015-02-09 12:53:18 -0800189 MetadataParseResult ParsePayloadMetadata(const chromeos::Blob& payload,
Gilad Arnolddaa27402014-01-23 11:56:17 -0800190 ErrorCode* error);
Darin Petkov9574f7e2011-01-13 10:48:12 -0800191
Jay Srinivasan51dcf262012-09-13 17:24:32 -0700192 void set_public_key_path(const std::string& public_key_path) {
193 public_key_path_ = public_key_path;
Darin Petkov698d0412010-10-13 10:59:44 -0700194 }
195
Don Garrett4d039442013-10-28 18:40:06 -0700196 // Returns the byte offset at which the payload version can be found.
197 static uint64_t GetVersionOffset();
Jay Srinivasanf4318702012-09-24 11:56:24 -0700198
199 // Returns the byte offset where the size of the manifest is stored in
200 // a payload. This offset precedes the actual start of the manifest
201 // that's returned by the GetManifestOffset method.
202 static uint64_t GetManifestSizeOffset();
203
Don Garrett4d039442013-10-28 18:40:06 -0700204 // Returns the byte offset at which the manifest protobuf begins in a
205 // payload.
206 static uint64_t GetManifestOffset();
207
Gilad Arnoldfe133932014-01-14 12:25:50 -0800208 // Returns the size of the payload metadata, which includes the payload header
209 // and the manifest. Is the header was not yet parsed, returns zero.
210 uint64_t GetMetadataSize() const;
211
Gilad Arnolddaa27402014-01-23 11:56:17 -0800212 // If the manifest was successfully parsed, copies it to |*out_manifest_p|.
213 // Returns true on success.
214 bool GetManifest(DeltaArchiveManifest* out_manifest_p) const;
215
Allie Woodfdf00512015-03-02 13:34:55 -0800216 // Returns the delta minor version. If this value is defined in the manifest,
217 // it returns that value, otherwise it returns the default value.
218 uint32_t GetMinorVersion() const;
219
Andrew de los Reyes09e56d62010-04-23 13:45:53 -0700220 private:
Andrew de los Reyes353777c2010-10-08 10:34:30 -0700221 friend class DeltaPerformerTest;
222 FRIEND_TEST(DeltaPerformerTest, IsIdempotentOperationTest);
David Zeuthene7f89172013-10-31 10:21:04 -0700223 FRIEND_TEST(DeltaPerformerTest, UsePublicKeyFromResponse);
Andrew de los Reyes353777c2010-10-08 10:34:30 -0700224
Gilad Arnoldfe133932014-01-14 12:25:50 -0800225 // Appends up to |*count_p| bytes from |*bytes_p| to |buffer_|, but only to
226 // the extent that the size of |buffer_| does not exceed |max|. Advances
227 // |*cbytes_p| and decreases |*count_p| by the actual number of bytes copied,
228 // and returns this number.
229 size_t CopyDataToBuffer(const char** bytes_p, size_t* count_p, size_t max);
230
231 // If |op_result| is false, emits an error message using |op_type_name| and
232 // sets |*error| accordingly. Otherwise does nothing. Returns |op_result|.
233 bool HandleOpResult(bool op_result, const char* op_type_name,
234 ErrorCode* error);
235
Gilad Arnold8a86fa52013-01-15 12:35:05 -0800236 // Logs the progress of downloading/applying an update.
237 void LogProgress(const char* message_prefix);
238
239 // Update overall progress metrics, log as necessary.
240 void UpdateOverallProgress(bool force_log, const char* message_prefix);
241
Darin Petkov698d0412010-10-13 10:59:44 -0700242 // Verifies that the expected source partition hashes (if present) match the
Alex Vakulenko072359c2014-07-18 11:41:07 -0700243 // hashes for the current partitions. Returns true if there are no expected
Darin Petkov698d0412010-10-13 10:59:44 -0700244 // hashes in the payload (e.g., if it's a new-style full update) or if the
245 // hashes match; returns false otherwise.
246 bool VerifySourcePartitions();
247
Andrew de los Reyes09e56d62010-04-23 13:45:53 -0700248 // Returns true if enough of the delta file has been passed via Write()
249 // to be able to perform a given install operation.
Alex Deymoa12ee112015-08-12 22:19:32 -0700250 bool CanPerformInstallOperation(const InstallOperation& operation);
Darin Petkovd7061ab2010-10-06 14:37:09 -0700251
Gilad Arnold21504f02013-05-24 08:51:22 -0700252 // Checks the integrity of the payload manifest. Returns true upon success,
253 // false otherwise.
254 ErrorCode ValidateManifest();
255
Jay Srinivasan51dcf262012-09-13 17:24:32 -0700256 // Validates that the hash of the blobs corresponding to the given |operation|
257 // matches what's specified in the manifest in the payload.
Gilad Arnoldd1c4d2d2014-06-05 14:07:53 -0700258 // Returns ErrorCode::kSuccess on match or a suitable error code otherwise.
Alex Deymoa12ee112015-08-12 22:19:32 -0700259 ErrorCode ValidateOperationHash(const InstallOperation& operation);
Jay Srinivasan51dcf262012-09-13 17:24:32 -0700260
261 // Interprets the given |protobuf| as a DeltaArchiveManifest protocol buffer
262 // of the given protobuf_length and verifies that the signed hash of the
Jay Srinivasanf4318702012-09-24 11:56:24 -0700263 // metadata matches what's specified in the install plan from Omaha.
Gilad Arnoldd1c4d2d2014-06-05 14:07:53 -0700264 // Returns ErrorCode::kSuccess on match or a suitable error code otherwise.
Jay Srinivasan51dcf262012-09-13 17:24:32 -0700265 // This method must be called before any part of the |protobuf| is parsed
266 // so that a man-in-the-middle attack on the SSL connection to the payload
267 // server doesn't exploit any vulnerability in the code that parses the
268 // protocol buffer.
Alex Vakulenkof68bbbc2015-02-09 12:53:18 -0800269 ErrorCode ValidateMetadataSignature(const void* protobuf,
270 uint64_t protobuf_length);
Jay Srinivasan51dcf262012-09-13 17:24:32 -0700271
Andrew de los Reyes09e56d62010-04-23 13:45:53 -0700272 // Returns true on success.
Alex Deymoa12ee112015-08-12 22:19:32 -0700273 bool PerformInstallOperation(const InstallOperation& operation);
Darin Petkovd7061ab2010-10-06 14:37:09 -0700274
Andrew de los Reyes09e56d62010-04-23 13:45:53 -0700275 // These perform a specific type of operation and return true on success.
Alex Deymoa12ee112015-08-12 22:19:32 -0700276 bool PerformReplaceOperation(const InstallOperation& operation,
277 bool is_kernel_partition);
278 bool PerformMoveOperation(const InstallOperation& operation,
279 bool is_kernel_partition);
280 bool PerformBsdiffOperation(const InstallOperation& operation,
281 bool is_kernel_partition);
282 bool PerformSourceCopyOperation(const InstallOperation& operation,
283 bool is_kernel_partition);
284 bool PerformSourceBsdiffOperation(const InstallOperation& operation,
285 bool is_kernel_partition);
Andrew de los Reyes09e56d62010-04-23 13:45:53 -0700286
Darin Petkovd7061ab2010-10-06 14:37:09 -0700287 // Returns true if the payload signature message has been extracted from
288 // |operation|, false otherwise.
Alex Deymoa12ee112015-08-12 22:19:32 -0700289 bool ExtractSignatureMessage(const InstallOperation& operation);
Darin Petkovd7061ab2010-10-06 14:37:09 -0700290
Gilad Arnoldfe133932014-01-14 12:25:50 -0800291 // Updates the hash calculator with the bytes in |buffer_|. Then discard the
Gilad Arnolddaa27402014-01-23 11:56:17 -0800292 // content, ensuring that memory is being deallocated. If |do_advance_offset|,
293 // advances the internal offset counter accordingly.
294 void DiscardBuffer(bool do_advance_offset);
Darin Petkovd7061ab2010-10-06 14:37:09 -0700295
Darin Petkov0406e402010-10-06 21:33:11 -0700296 // Checkpoints the update progress into persistent storage to allow this
297 // update attempt to be resumed after reboot.
Darin Petkov73058b42010-10-06 16:32:19 -0700298 bool CheckpointUpdateProgress();
299
Darin Petkov9b230572010-10-08 10:20:09 -0700300 // Primes the required update state. Returns true if the update state was
301 // successfully initialized to a saved resume state or if the update is a new
302 // update. Returns false otherwise.
303 bool PrimeUpdateState();
304
Jay Srinivasanf0572052012-10-23 18:12:56 -0700305 // Sends UMA statistics for the given error code.
David Zeuthena99981f2013-04-29 13:42:47 -0700306 void SendUmaStat(ErrorCode code);
Jay Srinivasanf0572052012-10-23 18:12:56 -0700307
David Zeuthene7f89172013-10-31 10:21:04 -0700308 // If the Omaha response contains a public RSA key and we're allowed
309 // to use it (e.g. if we're in developer mode), extract the key from
310 // the response and store it in a temporary file and return true. In
311 // the affirmative the path to the temporary file is stored in
312 // |out_tmp_key| and it is the responsibility of the caller to clean
313 // it up.
314 bool GetPublicKeyFromResponse(base::FilePath *out_tmp_key);
315
Darin Petkov73058b42010-10-06 16:32:19 -0700316 // Update Engine preference store.
317 PrefsInterface* prefs_;
318
Jay Srinivasanf0572052012-10-23 18:12:56 -0700319 // Global context of the system.
320 SystemState* system_state_;
321
Jay Srinivasan51dcf262012-09-13 17:24:32 -0700322 // Install Plan based on Omaha Response.
323 InstallPlan* install_plan_;
324
Andrew de los Reyes09e56d62010-04-23 13:45:53 -0700325 // File descriptor of open device.
Nam T. Nguyenf1d582e2014-12-08 15:07:17 -0800326 FileDescriptorPtr fd_;
Darin Petkovd7061ab2010-10-06 14:37:09 -0700327
Allie Woodfdf00512015-03-02 13:34:55 -0800328 // File descriptor of the kernel device.
Nam T. Nguyenf1d582e2014-12-08 15:07:17 -0800329 FileDescriptorPtr kernel_fd_;
Darin Petkovd7061ab2010-10-06 14:37:09 -0700330
Allie Woodfdf00512015-03-02 13:34:55 -0800331 // File descriptor of the source device.
332 FileDescriptorPtr source_fd_;
333
334 // File descriptor of the source kernel device.
335 FileDescriptorPtr source_kernel_fd_;
336
Andrew de los Reyesf4c7ef12010-04-30 10:37:00 -0700337 std::string path_; // Path that fd_ refers to.
338 std::string kernel_path_; // Path that kernel_fd_ refers to.
Darin Petkovd7061ab2010-10-06 14:37:09 -0700339
Andrew de los Reyes09e56d62010-04-23 13:45:53 -0700340 DeltaArchiveManifest manifest_;
Gilad Arnolddaa27402014-01-23 11:56:17 -0800341 bool manifest_parsed_;
Andrew de los Reyes09e56d62010-04-23 13:45:53 -0700342 bool manifest_valid_;
Gilad Arnoldfe133932014-01-14 12:25:50 -0800343 uint64_t metadata_size_;
Darin Petkovd7061ab2010-10-06 14:37:09 -0700344
Andrew de los Reyes09e56d62010-04-23 13:45:53 -0700345 // Index of the next operation to perform in the manifest.
Gilad Arnold8a86fa52013-01-15 12:35:05 -0800346 size_t next_operation_num_;
Andrew de los Reyes09e56d62010-04-23 13:45:53 -0700347
Gilad Arnoldfe133932014-01-14 12:25:50 -0800348 // A buffer used for accumulating downloaded data. Initially, it stores the
349 // payload metadata; once that's downloaded and parsed, it stores data for the
350 // next update operation.
Alex Vakulenkof68bbbc2015-02-09 12:53:18 -0800351 chromeos::Blob buffer_;
Andrew de los Reyes09e56d62010-04-23 13:45:53 -0700352 // Offset of buffer_ in the binary blobs section of the update.
353 uint64_t buffer_offset_;
Darin Petkovd7061ab2010-10-06 14:37:09 -0700354
Darin Petkov0406e402010-10-06 21:33:11 -0700355 // Last |buffer_offset_| value updated as part of the progress update.
356 uint64_t last_updated_buffer_offset_;
357
Andrew de los Reyes09e56d62010-04-23 13:45:53 -0700358 // The block size (parsed from the manifest).
359 uint32_t block_size_;
Darin Petkovd7061ab2010-10-06 14:37:09 -0700360
Darin Petkov437adc42010-10-07 13:12:24 -0700361 // Calculates the payload hash.
Darin Petkovd7061ab2010-10-06 14:37:09 -0700362 OmahaHashCalculator hash_calculator_;
363
Darin Petkov437adc42010-10-07 13:12:24 -0700364 // Saves the signed hash context.
365 std::string signed_hash_context_;
366
Darin Petkovd7061ab2010-10-06 14:37:09 -0700367 // Signatures message blob extracted directly from the payload.
Alex Vakulenkof68bbbc2015-02-09 12:53:18 -0800368 chromeos::Blob signatures_message_data_;
Darin Petkovd7061ab2010-10-06 14:37:09 -0700369
Jay Srinivasan51dcf262012-09-13 17:24:32 -0700370 // The public key to be used. Provided as a member so that tests can
371 // override with test keys.
372 std::string public_key_path_;
Darin Petkov698d0412010-10-13 10:59:44 -0700373
Gilad Arnold8a86fa52013-01-15 12:35:05 -0800374 // The number of bytes received so far, used for progress tracking.
375 size_t total_bytes_received_;
376
377 // The number rootfs and total operations in a payload, once we know them.
378 size_t num_rootfs_operations_;
379 size_t num_total_operations_;
380
381 // An overall progress counter, which should reflect both download progress
382 // and the ratio of applied operations. Range is 0-100.
383 unsigned overall_progress_;
384
385 // The last progress chunk recorded.
386 unsigned last_progress_chunk_;
387
388 // The timeout after which we should force emitting a progress log (constant),
389 // and the actual point in time for the next forced log to be emitted.
390 const base::TimeDelta forced_progress_log_wait_;
391 base::Time forced_progress_log_time_;
392
Allie Woodfdf00512015-03-02 13:34:55 -0800393 // The delta minor payload version supported by DeltaPerformer.
394 uint32_t supported_minor_version_;
395
Andrew de los Reyes09e56d62010-04-23 13:45:53 -0700396 DISALLOW_COPY_AND_ASSIGN(DeltaPerformer);
397};
398
399} // namespace chromeos_update_engine
400
Gilad Arnoldcf175a02014-07-10 16:48:47 -0700401#endif // UPDATE_ENGINE_DELTA_PERFORMER_H_