omaha_response_handler_action.h revision 738fdf37c15284b60dac703408b8de19eef9c6a3
1// Copyright (c) 2011 The Chromium OS Authors. All rights reserved. 2// Use of this source code is governed by a BSD-style license that can be 3// found in the LICENSE file. 4 5#ifndef CHROMEOS_PLATFORM_UPDATE_ENGINE_OMAHA_RESPONSE_HANDLER_ACTION_H__ 6#define CHROMEOS_PLATFORM_UPDATE_ENGINE_OMAHA_RESPONSE_HANDLER_ACTION_H__ 7 8#include <string> 9 10#include <gtest/gtest_prod.h> // for FRIEND_TEST 11 12#include "update_engine/action.h" 13#include "update_engine/install_plan.h" 14#include "update_engine/omaha_request_action.h" 15 16// This class reads in an Omaha response and converts what it sees into 17// an install plan which is passed out. 18 19namespace chromeos_update_engine { 20 21class OmahaResponseHandlerAction; 22class PrefsInterface; 23 24template<> 25class ActionTraits<OmahaResponseHandlerAction> { 26 public: 27 typedef OmahaResponse InputObjectType; 28 typedef InstallPlan OutputObjectType; 29}; 30 31class OmahaResponseHandlerAction : public Action<OmahaResponseHandlerAction> { 32 public: 33 static const char kDeadlineFile[]; 34 35 OmahaResponseHandlerAction(PrefsInterface* prefs); 36 typedef ActionTraits<OmahaResponseHandlerAction>::InputObjectType 37 InputObjectType; 38 typedef ActionTraits<OmahaResponseHandlerAction>::OutputObjectType 39 OutputObjectType; 40 void PerformAction(); 41 42 // This is a synchronous action, and thus TerminateProcessing() should 43 // never be called 44 void TerminateProcessing() { CHECK(false); } 45 46 // For unit-testing 47 void set_boot_device(const std::string& boot_device) { 48 boot_device_ = boot_device; 49 } 50 51 bool GotNoUpdateResponse() const { return got_no_update_response_; } 52 const InstallPlan& install_plan() const { return install_plan_; } 53 54 // Debugging/logging 55 static std::string StaticType() { return "OmahaResponseHandlerAction"; } 56 std::string Type() const { return StaticType(); } 57 void set_key_path(const std::string& path) { key_path_ = path; } 58 59 private: 60 FRIEND_TEST(UpdateAttempterTest, CreatePendingErrorEventResumedTest); 61 62 // Assumes you want to install on the "other" device, where the other 63 // device is what you get if you swap 1 for 2 or 3 for 4 or vice versa 64 // for the number at the end of the boot device. E.g., /dev/sda1 -> /dev/sda2 65 // or /dev/sda4 -> /dev/sda3 66 static bool GetInstallDev(const std::string& boot_dev, 67 std::string* install_dev); 68 69 // Returns true if payload hash checks are mandatory based on the state 70 // of the system and the contents of the Omaha response. False otherwise. 71 bool AreHashChecksMandatory(const OmahaResponse& response); 72 73 // Update Engine preference store. 74 PrefsInterface* prefs_; 75 76 // set to non-empty in unit tests 77 std::string boot_device_; 78 79 // The install plan, if we have an update. 80 InstallPlan install_plan_; 81 82 // True only if we got a response and the response said no updates 83 bool got_no_update_response_; 84 85 // Public key path to use for payload verification. 86 std::string key_path_; 87 88 DISALLOW_COPY_AND_ASSIGN(OmahaResponseHandlerAction); 89}; 90 91} // namespace chromeos_update_engine 92 93#endif // CHROMEOS_PLATFORM_UPDATE_ENGINE_OMAHA_RESPONSE_HANDLER_ACTION_H__ 94