blob: 0a001b809e574bf8e321b969da2d457e5fb5fe48 [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
Gilad Arnoldcf175a02014-07-10 16:48:47 -070017#ifndef UPDATE_ENGINE_OMAHA_RESPONSE_HANDLER_ACTION_H_
18#define UPDATE_ENGINE_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"
Darin Petkov6a5b3222010-07-13 14:55:28 -070025#include "update_engine/omaha_request_action.h"
Alex Deymo39910dc2015-11-09 17:04:30 -080026#include "update_engine/payload_consumer/install_plan.h"
Jay Srinivasan6f6ea002012-12-14 11:26:28 -080027#include "update_engine/system_state.h"
adlr@google.com3defe6a2009-12-04 20:57:17 +000028
29// This class reads in an Omaha response and converts what it sees into
30// an install plan which is passed out.
31
32namespace chromeos_update_engine {
33
34class OmahaResponseHandlerAction;
35
36template<>
37class ActionTraits<OmahaResponseHandlerAction> {
38 public:
Darin Petkov6a5b3222010-07-13 14:55:28 -070039 typedef OmahaResponse InputObjectType;
adlr@google.com3defe6a2009-12-04 20:57:17 +000040 typedef InstallPlan OutputObjectType;
41};
42
43class OmahaResponseHandlerAction : public Action<OmahaResponseHandlerAction> {
44 public:
Gilad Arnold4dbd47e2013-07-22 05:39:26 -070045 explicit OmahaResponseHandlerAction(SystemState* system_state);
46
adlr@google.com3defe6a2009-12-04 20:57:17 +000047 typedef ActionTraits<OmahaResponseHandlerAction>::InputObjectType
48 InputObjectType;
49 typedef ActionTraits<OmahaResponseHandlerAction>::OutputObjectType
50 OutputObjectType;
Alex Deymo610277e2014-11-11 21:18:11 -080051 void PerformAction() override;
adlr@google.com3defe6a2009-12-04 20:57:17 +000052
53 // This is a synchronous action, and thus TerminateProcessing() should
54 // never be called
Alex Deymo610277e2014-11-11 21:18:11 -080055 void TerminateProcessing() override { CHECK(false); }
adlr@google.com3defe6a2009-12-04 20:57:17 +000056
Andrew de los Reyes63b96d72010-05-10 13:08:54 -070057 const InstallPlan& install_plan() const { return install_plan_; }
adlr@google.com3defe6a2009-12-04 20:57:17 +000058
59 // Debugging/logging
60 static std::string StaticType() { return "OmahaResponseHandlerAction"; }
Alex Deymo610277e2014-11-11 21:18:11 -080061 std::string Type() const override { return StaticType(); }
Darin Petkovabc7bc02011-02-23 14:39:43 -080062 void set_key_path(const std::string& path) { key_path_ = path; }
adlr@google.com3defe6a2009-12-04 20:57:17 +000063
64 private:
Jay Srinivasan738fdf32012-12-07 17:40:54 -080065 // Returns true if payload hash checks are mandatory based on the state
66 // of the system and the contents of the Omaha response. False otherwise.
67 bool AreHashChecksMandatory(const OmahaResponse& response);
68
Jay Srinivasan6f6ea002012-12-14 11:26:28 -080069 // Global system context.
70 SystemState* system_state_;
Darin Petkov73058b42010-10-06 16:32:19 -070071
Andrew de los Reyes63b96d72010-05-10 13:08:54 -070072 // The install plan, if we have an update.
73 InstallPlan install_plan_;
Darin Petkov6a5b3222010-07-13 14:55:28 -070074
Darin Petkovabc7bc02011-02-23 14:39:43 -080075 // Public key path to use for payload verification.
76 std::string key_path_;
77
Gilad Arnold4dbd47e2013-07-22 05:39:26 -070078 // File used for communication deadline to Chrome.
79 const std::string deadline_file_;
80
81 // Special ctor + friend declarations for testing purposes.
82 OmahaResponseHandlerAction(SystemState* system_state,
83 const std::string& deadline_file);
84
85 friend class OmahaResponseHandlerActionTest;
86
87 FRIEND_TEST(UpdateAttempterTest, CreatePendingErrorEventResumedTest);
Marton Hunyadya0302682018-05-16 18:52:13 +020088 FRIEND_TEST(UpdateAttempterTest, RollbackMetricsNotRollbackFailure);
89 FRIEND_TEST(UpdateAttempterTest, RollbackMetricsNotRollbackSuccess);
90 FRIEND_TEST(UpdateAttempterTest, RollbackMetricsRollbackFailure);
91 FRIEND_TEST(UpdateAttempterTest, RollbackMetricsRollbackSuccess);
Marton Hunyady199152d2018-05-07 19:08:48 +020092 FRIEND_TEST(UpdateAttempterTest, SetRollbackHappenedNotRollback);
93 FRIEND_TEST(UpdateAttempterTest, SetRollbackHappenedRollback);
Aaron Wood23bd3392017-10-06 14:48:25 -070094 FRIEND_TEST(UpdateAttempterTest, UpdateDeferredByPolicyTest);
Gilad Arnold4dbd47e2013-07-22 05:39:26 -070095
adlr@google.com3defe6a2009-12-04 20:57:17 +000096 DISALLOW_COPY_AND_ASSIGN(OmahaResponseHandlerAction);
97};
98
99} // namespace chromeos_update_engine
100
Gilad Arnoldcf175a02014-07-10 16:48:47 -0700101#endif // UPDATE_ENGINE_OMAHA_RESPONSE_HANDLER_ACTION_H_