blob: 9842c942d668446e0100ee3cae25f71391e8469c [file] [log] [blame]
Alex Deymoaea4c1c2015-08-19 20:24:43 -07001//
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.com3defe6a2009-12-04 20:57:17 +000016
Amin Hassaniec7bc112020-10-29 16:47:58 -070017#ifndef UPDATE_ENGINE_CROS_OMAHA_RESPONSE_HANDLER_ACTION_H_
18#define UPDATE_ENGINE_CROS_OMAHA_RESPONSE_HANDLER_ACTION_H_
adlr@google.com3defe6a2009-12-04 20:57:17 +000019
20#include <string>
Darin Petkov18c7bce2011-06-16 14:07:00 -070021
22#include <gtest/gtest_prod.h> // for FRIEND_TEST
23
Alex Deymo39910dc2015-11-09 17:04:30 -080024#include "update_engine/common/action.h"
Amin Hassaniec7bc112020-10-29 16:47:58 -070025#include "update_engine/cros/omaha_request_action.h"
Alex Deymo39910dc2015-11-09 17:04:30 -080026#include "update_engine/payload_consumer/install_plan.h"
adlr@google.com3defe6a2009-12-04 20:57:17 +000027
28// This class reads in an Omaha response and converts what it sees into
29// an install plan which is passed out.
30
31namespace chromeos_update_engine {
32
33class OmahaResponseHandlerAction;
34
Amin Hassani7cc8bb02019-01-14 16:29:47 -080035template <>
adlr@google.com3defe6a2009-12-04 20:57:17 +000036class ActionTraits<OmahaResponseHandlerAction> {
37 public:
Darin Petkov6a5b3222010-07-13 14:55:28 -070038 typedef OmahaResponse InputObjectType;
adlr@google.com3defe6a2009-12-04 20:57:17 +000039 typedef InstallPlan OutputObjectType;
40};
41
42class OmahaResponseHandlerAction : public Action<OmahaResponseHandlerAction> {
43 public:
Amin Hassani538bd592020-11-04 20:46:08 -080044 OmahaResponseHandlerAction();
Gilad Arnold4dbd47e2013-07-22 05:39:26 -070045
adlr@google.com3defe6a2009-12-04 20:57:17 +000046 typedef ActionTraits<OmahaResponseHandlerAction>::InputObjectType
47 InputObjectType;
48 typedef ActionTraits<OmahaResponseHandlerAction>::OutputObjectType
49 OutputObjectType;
Alex Deymo610277e2014-11-11 21:18:11 -080050 void PerformAction() override;
adlr@google.com3defe6a2009-12-04 20:57:17 +000051
52 // This is a synchronous action, and thus TerminateProcessing() should
53 // never be called
Alex Deymo610277e2014-11-11 21:18:11 -080054 void TerminateProcessing() override { CHECK(false); }
adlr@google.com3defe6a2009-12-04 20:57:17 +000055
Andrew de los Reyes63b96d72010-05-10 13:08:54 -070056 const InstallPlan& install_plan() const { return install_plan_; }
adlr@google.com3defe6a2009-12-04 20:57:17 +000057
58 // Debugging/logging
59 static std::string StaticType() { return "OmahaResponseHandlerAction"; }
Alex Deymo610277e2014-11-11 21:18:11 -080060 std::string Type() const override { return StaticType(); }
adlr@google.com3defe6a2009-12-04 20:57:17 +000061
62 private:
Jay Srinivasan738fdf32012-12-07 17:40:54 -080063 // Returns true if payload hash checks are mandatory based on the state
64 // of the system and the contents of the Omaha response. False otherwise.
65 bool AreHashChecksMandatory(const OmahaResponse& response);
66
Andrew de los Reyes63b96d72010-05-10 13:08:54 -070067 // The install plan, if we have an update.
68 InstallPlan install_plan_;
Darin Petkov6a5b3222010-07-13 14:55:28 -070069
Gilad Arnold4dbd47e2013-07-22 05:39:26 -070070 // File used for communication deadline to Chrome.
Amin Hassanid3f4bea2018-04-30 14:52:40 -070071 std::string deadline_file_;
Gilad Arnold4dbd47e2013-07-22 05:39:26 -070072
73 friend class OmahaResponseHandlerActionTest;
Amin Hassanid3f4bea2018-04-30 14:52:40 -070074 friend class OmahaResponseHandlerActionProcessorDelegate;
Gilad Arnold4dbd47e2013-07-22 05:39:26 -070075 FRIEND_TEST(UpdateAttempterTest, CreatePendingErrorEventResumedTest);
Marton Hunyadya0302682018-05-16 18:52:13 +020076 FRIEND_TEST(UpdateAttempterTest, RollbackMetricsNotRollbackFailure);
77 FRIEND_TEST(UpdateAttempterTest, RollbackMetricsNotRollbackSuccess);
78 FRIEND_TEST(UpdateAttempterTest, RollbackMetricsRollbackFailure);
79 FRIEND_TEST(UpdateAttempterTest, RollbackMetricsRollbackSuccess);
Marton Hunyady199152d2018-05-07 19:08:48 +020080 FRIEND_TEST(UpdateAttempterTest, SetRollbackHappenedNotRollback);
81 FRIEND_TEST(UpdateAttempterTest, SetRollbackHappenedRollback);
Aaron Wood23bd3392017-10-06 14:48:25 -070082 FRIEND_TEST(UpdateAttempterTest, UpdateDeferredByPolicyTest);
Gilad Arnold4dbd47e2013-07-22 05:39:26 -070083
adlr@google.com3defe6a2009-12-04 20:57:17 +000084 DISALLOW_COPY_AND_ASSIGN(OmahaResponseHandlerAction);
85};
86
87} // namespace chromeos_update_engine
88
Amin Hassaniec7bc112020-10-29 16:47:58 -070089#endif // UPDATE_ENGINE_CROS_OMAHA_RESPONSE_HANDLER_ACTION_H_