blob: 3ec9d55ba622110ea0548405bcea489f03e0fa34 [file] [log] [blame]
Darin Petkov7ed561b2011-10-04 02:59:03 -07001// Copyright (c) 2011 The Chromium OS Authors. All rights reserved.
adlr@google.com3defe6a2009-12-04 20:57:17 +00002// 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_INSTALL_PLAN_H__
6#define CHROMEOS_PLATFORM_UPDATE_ENGINE_INSTALL_PLAN_H__
7
8#include <string>
Darin Petkov698d0412010-10-13 10:59:44 -07009#include <vector>
10
Jay Srinivasanae4697c2013-03-18 17:08:08 -070011#include <base/basictypes.h>
adlr@google.com3defe6a2009-12-04 20:57:17 +000012
Chris Sosad317e402013-06-12 13:47:09 -070013#include "update_engine/action.h"
14
adlr@google.com3defe6a2009-12-04 20:57:17 +000015// InstallPlan is a simple struct that contains relevant info for many
16// parts of the update system about the install that should happen.
adlr@google.com3defe6a2009-12-04 20:57:17 +000017namespace chromeos_update_engine {
18
19struct InstallPlan {
Darin Petkov7ed561b2011-10-04 02:59:03 -070020 InstallPlan(bool is_resume,
Gilad Arnold21504f02013-05-24 08:51:22 -070021 bool is_full_update,
adlr@google.com3defe6a2009-12-04 20:57:17 +000022 const std::string& url,
Jay Srinivasan51dcf262012-09-13 17:24:32 -070023 uint64_t payload_size,
24 const std::string& payload_hash,
Jay Srinivasanf4318702012-09-24 11:56:24 -070025 uint64_t metadata_size,
26 const std::string& metadata_signature,
Andrew de los Reyesf9185172010-05-03 11:07:05 -070027 const std::string& install_path,
Jay Srinivasanae4697c2013-03-18 17:08:08 -070028 const std::string& kernel_install_path);
Jay Srinivasan738fdf32012-12-07 17:40:54 -080029
30 // Default constructor: Initialize all members which don't have a class
31 // initializer.
Jay Srinivasanae4697c2013-03-18 17:08:08 -070032 InstallPlan();
33
34 bool operator==(const InstallPlan& that) const;
35 bool operator!=(const InstallPlan& that) const;
36
37 void Dump() const;
adlr@google.com3defe6a2009-12-04 20:57:17 +000038
Darin Petkov0406e402010-10-06 21:33:11 -070039 bool is_resume;
Gilad Arnold21504f02013-05-24 08:51:22 -070040 bool is_full_update;
adlr@google.com3defe6a2009-12-04 20:57:17 +000041 std::string download_url; // url to download from
Chris Sosafb1020e2013-07-29 17:27:33 -070042 std::string version; // version we are installing.
Jay Srinivasan51dcf262012-09-13 17:24:32 -070043
44 uint64_t payload_size; // size of the payload
Chris Sosad317e402013-06-12 13:47:09 -070045 std::string payload_hash; // SHA256 hash of the payload
Jay Srinivasanf4318702012-09-24 11:56:24 -070046 uint64_t metadata_size; // size of the metadata
47 std::string metadata_signature; // signature of the metadata
Jay Srinivasan51dcf262012-09-13 17:24:32 -070048 std::string install_path; // path to install device
49 std::string kernel_install_path; // path to kernel install device
Darin Petkov3aefa862010-12-07 14:45:00 -080050
51 // The fields below are used for kernel and rootfs verification. The flow is:
52 //
53 // 1. FilesystemCopierAction(verify_hash=false) computes and fills in the
54 // source partition sizes and hashes.
55 //
56 // 2. DownloadAction verifies the source partition sizes and hashes against
57 // the expected values transmitted in the update manifest. It fills in the
58 // expected applied partition sizes and hashes based on the manifest.
59 //
60 // 4. FilesystemCopierAction(verify_hashes=true) computes and verifies the
61 // applied partition sizes and hashes against the expected values.
62 uint64_t kernel_size;
63 uint64_t rootfs_size;
64 std::vector<char> kernel_hash;
65 std::vector<char> rootfs_hash;
adlr@google.com3defe6a2009-12-04 20:57:17 +000066
Jay Srinivasan738fdf32012-12-07 17:40:54 -080067 // True if payload hash checks are mandatory based on the system state and
68 // the Omaha response.
69 bool hash_checks_mandatory;
70
Jay Srinivasanae4697c2013-03-18 17:08:08 -070071 // True if Powerwash is required on reboot after applying the payload.
72 // False otherwise.
73 bool powerwash_required;
adlr@google.com3defe6a2009-12-04 20:57:17 +000074};
75
Chris Sosad317e402013-06-12 13:47:09 -070076class InstallPlanAction;
77
78template<>
79class ActionTraits<InstallPlanAction> {
80 public:
81 // Takes the install plan as input
82 typedef InstallPlan InputObjectType;
83 // Passes the install plan as output
84 typedef InstallPlan OutputObjectType;
85};
86
87// Basic action that only receives and sends Install Plans.
88// Can be used to construct an Install Plan to send to any other Action that
89// accept an InstallPlan.
90class InstallPlanAction : public Action<InstallPlanAction> {
91 public:
92 InstallPlanAction() {}
93 InstallPlanAction(const InstallPlan& install_plan):
94 install_plan_(install_plan) {}
95
96 virtual void PerformAction() {
97 if (HasOutputPipe()) {
98 SetOutputObject(install_plan_);
99 }
100 processor_->ActionComplete(this, kErrorCodeSuccess);
101 }
102
Chris Sosa76a29ae2013-07-11 17:59:24 -0700103 InstallPlan* install_plan() { return &install_plan_; }
104
105 static std::string StaticType() { return "InstallPlanAction"; }
106 virtual std::string Type() const { return StaticType(); }
Chris Sosad317e402013-06-12 13:47:09 -0700107
108 typedef ActionTraits<InstallPlanAction>::InputObjectType InputObjectType;
109 typedef ActionTraits<InstallPlanAction>::OutputObjectType OutputObjectType;
110
111 private:
112 InstallPlan install_plan_;
113
114 DISALLOW_COPY_AND_ASSIGN (InstallPlanAction);
115};
116
adlr@google.com3defe6a2009-12-04 20:57:17 +0000117} // namespace chromeos_update_engine
118
119#endif // CHROMEOS_PLATFORM_UPDATE_ENGINE_INSTALL_PLAN_H__