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