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 | |
Gilad Arnold | cf175a0 | 2014-07-10 16:48:47 -0700 | [diff] [blame] | 5 | #ifndef UPDATE_ENGINE_OMAHA_RESPONSE_HANDLER_ACTION_H_ |
| 6 | #define UPDATE_ENGINE_OMAHA_RESPONSE_HANDLER_ACTION_H_ |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 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 | |
Gilad Arnold | 4dbd47e | 2013-07-22 05:39:26 -0700 | [diff] [blame] | 35 | explicit OmahaResponseHandlerAction(SystemState* system_state); |
| 36 | |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 37 | typedef ActionTraits<OmahaResponseHandlerAction>::InputObjectType |
| 38 | InputObjectType; |
| 39 | typedef ActionTraits<OmahaResponseHandlerAction>::OutputObjectType |
| 40 | OutputObjectType; |
Alex Deymo | 610277e | 2014-11-11 21:18:11 -0800 | [diff] [blame] | 41 | void PerformAction() override; |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 42 | |
| 43 | // This is a synchronous action, and thus TerminateProcessing() should |
| 44 | // never be called |
Alex Deymo | 610277e | 2014-11-11 21:18:11 -0800 | [diff] [blame] | 45 | void TerminateProcessing() override { CHECK(false); } |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 46 | |
| 47 | // For unit-testing |
| 48 | void set_boot_device(const std::string& boot_device) { |
| 49 | boot_device_ = boot_device; |
| 50 | } |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 51 | |
Andrew de los Reyes | 4fe15d0 | 2009-12-10 19:01:36 -0800 | [diff] [blame] | 52 | bool GotNoUpdateResponse() const { return got_no_update_response_; } |
Andrew de los Reyes | 63b96d7 | 2010-05-10 13:08:54 -0700 | [diff] [blame] | 53 | const InstallPlan& install_plan() const { return install_plan_; } |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 54 | |
| 55 | // Debugging/logging |
| 56 | static std::string StaticType() { return "OmahaResponseHandlerAction"; } |
Alex Deymo | 610277e | 2014-11-11 21:18:11 -0800 | [diff] [blame] | 57 | std::string Type() const override { return StaticType(); } |
Darin Petkov | abc7bc0 | 2011-02-23 14:39:43 -0800 | [diff] [blame] | 58 | void set_key_path(const std::string& path) { key_path_ = path; } |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 59 | |
| 60 | private: |
Jay Srinivasan | 738fdf3 | 2012-12-07 17:40:54 -0800 | [diff] [blame] | 61 | // Returns true if payload hash checks are mandatory based on the state |
| 62 | // of the system and the contents of the Omaha response. False otherwise. |
| 63 | bool AreHashChecksMandatory(const OmahaResponse& response); |
| 64 | |
Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame] | 65 | // Global system context. |
| 66 | SystemState* system_state_; |
Darin Petkov | 73058b4 | 2010-10-06 16:32:19 -0700 | [diff] [blame] | 67 | |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 68 | // set to non-empty in unit tests |
| 69 | std::string boot_device_; |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 70 | |
Andrew de los Reyes | 63b96d7 | 2010-05-10 13:08:54 -0700 | [diff] [blame] | 71 | // The install plan, if we have an update. |
| 72 | InstallPlan install_plan_; |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 73 | |
Andrew de los Reyes | 4fe15d0 | 2009-12-10 19:01:36 -0800 | [diff] [blame] | 74 | // True only if we got a response and the response said no updates |
| 75 | bool got_no_update_response_; |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 76 | |
Darin Petkov | abc7bc0 | 2011-02-23 14:39:43 -0800 | [diff] [blame] | 77 | // Public key path to use for payload verification. |
| 78 | std::string key_path_; |
| 79 | |
Gilad Arnold | 4dbd47e | 2013-07-22 05:39:26 -0700 | [diff] [blame] | 80 | // File used for communication deadline to Chrome. |
| 81 | const std::string deadline_file_; |
| 82 | |
| 83 | // Special ctor + friend declarations for testing purposes. |
| 84 | OmahaResponseHandlerAction(SystemState* system_state, |
| 85 | const std::string& deadline_file); |
| 86 | |
| 87 | friend class OmahaResponseHandlerActionTest; |
| 88 | |
| 89 | FRIEND_TEST(UpdateAttempterTest, CreatePendingErrorEventResumedTest); |
| 90 | |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 91 | DISALLOW_COPY_AND_ASSIGN(OmahaResponseHandlerAction); |
| 92 | }; |
| 93 | |
| 94 | } // namespace chromeos_update_engine |
| 95 | |
Gilad Arnold | cf175a0 | 2014-07-10 16:48:47 -0700 | [diff] [blame] | 96 | #endif // UPDATE_ENGINE_OMAHA_RESPONSE_HANDLER_ACTION_H_ |