Alex Deymo | aea4c1c | 2015-08-19 20:24:43 -0700 | [diff] [blame] | 1 | // |
| 2 | // Copyright (C) 2011 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 | // |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 16 | |
Gilad Arnold | cf175a0 | 2014-07-10 16:48:47 -0700 | [diff] [blame] | 17 | #ifndef UPDATE_ENGINE_OMAHA_RESPONSE_HANDLER_ACTION_H_ |
| 18 | #define UPDATE_ENGINE_OMAHA_RESPONSE_HANDLER_ACTION_H_ |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 19 | |
| 20 | #include <string> |
Darin Petkov | 18c7bce | 2011-06-16 14:07:00 -0700 | [diff] [blame] | 21 | |
| 22 | #include <gtest/gtest_prod.h> // for FRIEND_TEST |
| 23 | |
Alex Deymo | 39910dc | 2015-11-09 17:04:30 -0800 | [diff] [blame] | 24 | #include "update_engine/common/action.h" |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 25 | #include "update_engine/omaha_request_action.h" |
Alex Deymo | 39910dc | 2015-11-09 17:04:30 -0800 | [diff] [blame] | 26 | #include "update_engine/payload_consumer/install_plan.h" |
Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame] | 27 | #include "update_engine/system_state.h" |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 28 | |
| 29 | // This class reads in an Omaha response and converts what it sees into |
| 30 | // an install plan which is passed out. |
| 31 | |
| 32 | namespace chromeos_update_engine { |
| 33 | |
| 34 | class OmahaResponseHandlerAction; |
| 35 | |
Amin Hassani | 7cc8bb0 | 2019-01-14 16:29:47 -0800 | [diff] [blame] | 36 | template <> |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 37 | class ActionTraits<OmahaResponseHandlerAction> { |
| 38 | public: |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 39 | typedef OmahaResponse InputObjectType; |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 40 | typedef InstallPlan OutputObjectType; |
| 41 | }; |
| 42 | |
| 43 | class OmahaResponseHandlerAction : public Action<OmahaResponseHandlerAction> { |
| 44 | public: |
Gilad Arnold | 4dbd47e | 2013-07-22 05:39:26 -0700 | [diff] [blame] | 45 | explicit OmahaResponseHandlerAction(SystemState* system_state); |
| 46 | |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 47 | typedef ActionTraits<OmahaResponseHandlerAction>::InputObjectType |
| 48 | InputObjectType; |
| 49 | typedef ActionTraits<OmahaResponseHandlerAction>::OutputObjectType |
| 50 | OutputObjectType; |
Alex Deymo | 610277e | 2014-11-11 21:18:11 -0800 | [diff] [blame] | 51 | void PerformAction() override; |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 52 | |
| 53 | // This is a synchronous action, and thus TerminateProcessing() should |
| 54 | // never be called |
Alex Deymo | 610277e | 2014-11-11 21:18:11 -0800 | [diff] [blame] | 55 | void TerminateProcessing() override { CHECK(false); } |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 56 | |
Andrew de los Reyes | 63b96d7 | 2010-05-10 13:08:54 -0700 | [diff] [blame] | 57 | const InstallPlan& install_plan() const { return install_plan_; } |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 58 | |
| 59 | // Debugging/logging |
| 60 | static std::string StaticType() { return "OmahaResponseHandlerAction"; } |
Alex Deymo | 610277e | 2014-11-11 21:18:11 -0800 | [diff] [blame] | 61 | std::string Type() const override { return StaticType(); } |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 62 | |
| 63 | private: |
Jay Srinivasan | 738fdf3 | 2012-12-07 17:40:54 -0800 | [diff] [blame] | 64 | // Returns true if payload hash checks are mandatory based on the state |
| 65 | // of the system and the contents of the Omaha response. False otherwise. |
| 66 | bool AreHashChecksMandatory(const OmahaResponse& response); |
| 67 | |
Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame] | 68 | // Global system context. |
| 69 | SystemState* system_state_; |
Darin Petkov | 73058b4 | 2010-10-06 16:32:19 -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 | |
Gilad Arnold | 4dbd47e | 2013-07-22 05:39:26 -0700 | [diff] [blame] | 74 | // File used for communication deadline to Chrome. |
Amin Hassani | d3f4bea | 2018-04-30 14:52:40 -0700 | [diff] [blame] | 75 | std::string deadline_file_; |
Gilad Arnold | 4dbd47e | 2013-07-22 05:39:26 -0700 | [diff] [blame] | 76 | |
| 77 | friend class OmahaResponseHandlerActionTest; |
Amin Hassani | d3f4bea | 2018-04-30 14:52:40 -0700 | [diff] [blame] | 78 | friend class OmahaResponseHandlerActionProcessorDelegate; |
Gilad Arnold | 4dbd47e | 2013-07-22 05:39:26 -0700 | [diff] [blame] | 79 | FRIEND_TEST(UpdateAttempterTest, CreatePendingErrorEventResumedTest); |
Marton Hunyady | a030268 | 2018-05-16 18:52:13 +0200 | [diff] [blame] | 80 | FRIEND_TEST(UpdateAttempterTest, RollbackMetricsNotRollbackFailure); |
| 81 | FRIEND_TEST(UpdateAttempterTest, RollbackMetricsNotRollbackSuccess); |
| 82 | FRIEND_TEST(UpdateAttempterTest, RollbackMetricsRollbackFailure); |
| 83 | FRIEND_TEST(UpdateAttempterTest, RollbackMetricsRollbackSuccess); |
Marton Hunyady | 199152d | 2018-05-07 19:08:48 +0200 | [diff] [blame] | 84 | FRIEND_TEST(UpdateAttempterTest, SetRollbackHappenedNotRollback); |
| 85 | FRIEND_TEST(UpdateAttempterTest, SetRollbackHappenedRollback); |
Aaron Wood | 23bd339 | 2017-10-06 14:48:25 -0700 | [diff] [blame] | 86 | FRIEND_TEST(UpdateAttempterTest, UpdateDeferredByPolicyTest); |
Gilad Arnold | 4dbd47e | 2013-07-22 05:39:26 -0700 | [diff] [blame] | 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 | |
Gilad Arnold | cf175a0 | 2014-07-10 16:48:47 -0700 | [diff] [blame] | 93 | #endif // UPDATE_ENGINE_OMAHA_RESPONSE_HANDLER_ACTION_H_ |