Darin Petkov | 18c7bce | 2011-06-16 14:07:00 -0700 | [diff] [blame] | 1 | // Copyright (c) 2011 The Chromium OS Authors. All rights reserved. |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 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_OMAHA_RESPONSE_HANDLER_ACTION_H__ |
| 6 | #define CHROMEOS_PLATFORM_UPDATE_ENGINE_OMAHA_RESPONSE_HANDLER_ACTION_H__ |
| 7 | |
| 8 | #include <string> |
Darin Petkov | 18c7bce | 2011-06-16 14:07:00 -0700 | [diff] [blame] | 9 | |
| 10 | #include <gtest/gtest_prod.h> // for FRIEND_TEST |
| 11 | |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 12 | #include "update_engine/action.h" |
| 13 | #include "update_engine/install_plan.h" |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 14 | #include "update_engine/omaha_request_action.h" |
Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame^] | 15 | #include "update_engine/system_state.h" |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 16 | |
| 17 | // This class reads in an Omaha response and converts what it sees into |
| 18 | // an install plan which is passed out. |
| 19 | |
| 20 | namespace chromeos_update_engine { |
| 21 | |
| 22 | class OmahaResponseHandlerAction; |
| 23 | |
| 24 | template<> |
| 25 | class ActionTraits<OmahaResponseHandlerAction> { |
| 26 | public: |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 27 | typedef OmahaResponse InputObjectType; |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 28 | typedef InstallPlan OutputObjectType; |
| 29 | }; |
| 30 | |
| 31 | class OmahaResponseHandlerAction : public Action<OmahaResponseHandlerAction> { |
| 32 | public: |
Darin Petkov | 6c11864 | 2010-10-21 12:06:30 -0700 | [diff] [blame] | 33 | static const char kDeadlineFile[]; |
| 34 | |
Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame^] | 35 | OmahaResponseHandlerAction(SystemState* system_state); |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 36 | typedef ActionTraits<OmahaResponseHandlerAction>::InputObjectType |
| 37 | InputObjectType; |
| 38 | typedef ActionTraits<OmahaResponseHandlerAction>::OutputObjectType |
| 39 | OutputObjectType; |
| 40 | void PerformAction(); |
| 41 | |
| 42 | // This is a synchronous action, and thus TerminateProcessing() should |
| 43 | // never be called |
| 44 | void TerminateProcessing() { CHECK(false); } |
| 45 | |
| 46 | // For unit-testing |
| 47 | void set_boot_device(const std::string& boot_device) { |
| 48 | boot_device_ = boot_device; |
| 49 | } |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 50 | |
Andrew de los Reyes | 4fe15d0 | 2009-12-10 19:01:36 -0800 | [diff] [blame] | 51 | bool GotNoUpdateResponse() const { return got_no_update_response_; } |
Andrew de los Reyes | 63b96d7 | 2010-05-10 13:08:54 -0700 | [diff] [blame] | 52 | const InstallPlan& install_plan() const { return install_plan_; } |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 53 | |
| 54 | // Debugging/logging |
| 55 | static std::string StaticType() { return "OmahaResponseHandlerAction"; } |
| 56 | std::string Type() const { return StaticType(); } |
Darin Petkov | abc7bc0 | 2011-02-23 14:39:43 -0800 | [diff] [blame] | 57 | void set_key_path(const std::string& path) { key_path_ = path; } |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 58 | |
| 59 | private: |
Darin Petkov | 18c7bce | 2011-06-16 14:07:00 -0700 | [diff] [blame] | 60 | FRIEND_TEST(UpdateAttempterTest, CreatePendingErrorEventResumedTest); |
| 61 | |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 62 | // Assumes you want to install on the "other" device, where the other |
| 63 | // device is what you get if you swap 1 for 2 or 3 for 4 or vice versa |
| 64 | // for the number at the end of the boot device. E.g., /dev/sda1 -> /dev/sda2 |
| 65 | // or /dev/sda4 -> /dev/sda3 |
| 66 | static bool GetInstallDev(const std::string& boot_dev, |
| 67 | std::string* install_dev); |
| 68 | |
Jay Srinivasan | 738fdf3 | 2012-12-07 17:40:54 -0800 | [diff] [blame] | 69 | // Returns true if payload hash checks are mandatory based on the state |
| 70 | // of the system and the contents of the Omaha response. False otherwise. |
| 71 | bool AreHashChecksMandatory(const OmahaResponse& response); |
| 72 | |
Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame^] | 73 | // Global system context. |
| 74 | SystemState* system_state_; |
Darin Petkov | 73058b4 | 2010-10-06 16:32:19 -0700 | [diff] [blame] | 75 | |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 76 | // set to non-empty in unit tests |
| 77 | std::string boot_device_; |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 78 | |
Andrew de los Reyes | 63b96d7 | 2010-05-10 13:08:54 -0700 | [diff] [blame] | 79 | // The install plan, if we have an update. |
| 80 | InstallPlan install_plan_; |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 81 | |
Andrew de los Reyes | 4fe15d0 | 2009-12-10 19:01:36 -0800 | [diff] [blame] | 82 | // True only if we got a response and the response said no updates |
| 83 | bool got_no_update_response_; |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 84 | |
Darin Petkov | abc7bc0 | 2011-02-23 14:39:43 -0800 | [diff] [blame] | 85 | // Public key path to use for payload verification. |
| 86 | std::string key_path_; |
| 87 | |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 88 | DISALLOW_COPY_AND_ASSIGN(OmahaResponseHandlerAction); |
| 89 | }; |
| 90 | |
| 91 | } // namespace chromeos_update_engine |
| 92 | |
| 93 | #endif // CHROMEOS_PLATFORM_UPDATE_ENGINE_OMAHA_RESPONSE_HANDLER_ACTION_H__ |