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// 16 17#ifndef UPDATE_ENGINE_OMAHA_RESPONSE_HANDLER_ACTION_H_ 18#define UPDATE_ENGINE_OMAHA_RESPONSE_HANDLER_ACTION_H_ 19 20#include <string> 21 22#include <gtest/gtest_prod.h> // for FRIEND_TEST 23 24#include "update_engine/common/action.h" 25#include "update_engine/omaha_request_action.h" 26#include "update_engine/payload_consumer/install_plan.h" 27#include "update_engine/system_state.h" 28 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: 39 typedef OmahaResponse InputObjectType; 40 typedef InstallPlan OutputObjectType; 41}; 42 43class OmahaResponseHandlerAction : public Action<OmahaResponseHandlerAction> { 44 public: 45 explicit OmahaResponseHandlerAction(SystemState* system_state); 46 47 typedef ActionTraits<OmahaResponseHandlerAction>::InputObjectType 48 InputObjectType; 49 typedef ActionTraits<OmahaResponseHandlerAction>::OutputObjectType 50 OutputObjectType; 51 void PerformAction() override; 52 53 // This is a synchronous action, and thus TerminateProcessing() should 54 // never be called 55 void TerminateProcessing() override { CHECK(false); } 56 57 bool GotNoUpdateResponse() const { return got_no_update_response_; } 58 const InstallPlan& install_plan() const { return install_plan_; } 59 60 // Debugging/logging 61 static std::string StaticType() { return "OmahaResponseHandlerAction"; } 62 std::string Type() const override { return StaticType(); } 63 void set_key_path(const std::string& path) { key_path_ = path; } 64 65 private: 66 // Returns true if payload hash checks are mandatory based on the state 67 // of the system and the contents of the Omaha response. False otherwise. 68 bool AreHashChecksMandatory(const OmahaResponse& response); 69 70 // Global system context. 71 SystemState* system_state_; 72 73 // The install plan, if we have an update. 74 InstallPlan install_plan_; 75 76 // True only if we got a response and the response said no updates 77 bool got_no_update_response_; 78 79 // Public key path to use for payload verification. 80 std::string key_path_; 81 82 // File used for communication deadline to Chrome. 83 const std::string deadline_file_; 84 85 // Special ctor + friend declarations for testing purposes. 86 OmahaResponseHandlerAction(SystemState* system_state, 87 const std::string& deadline_file); 88 89 friend class OmahaResponseHandlerActionTest; 90 91 FRIEND_TEST(UpdateAttempterTest, CreatePendingErrorEventResumedTest); 92 93 DISALLOW_COPY_AND_ASSIGN(OmahaResponseHandlerAction); 94}; 95 96} // namespace chromeos_update_engine 97 98#endif // UPDATE_ENGINE_OMAHA_RESPONSE_HANDLER_ACTION_H_ 99