omaha_response_handler_action.h revision 738fdf37c15284b60dac703408b8de19eef9c6a3
118c7bce69dc040dc8e9c2a1dc207f7447fb06e84Darin Petkov// Copyright (c) 2011 The Chromium OS Authors. All rights reserved.
23defe6acb3609e70e851a6eff062577d25a2af9dadlr@google.com// Use of this source code is governed by a BSD-style license that can be
33defe6acb3609e70e851a6eff062577d25a2af9dadlr@google.com// found in the LICENSE file.
43defe6acb3609e70e851a6eff062577d25a2af9dadlr@google.com
53defe6acb3609e70e851a6eff062577d25a2af9dadlr@google.com#ifndef CHROMEOS_PLATFORM_UPDATE_ENGINE_OMAHA_RESPONSE_HANDLER_ACTION_H__
63defe6acb3609e70e851a6eff062577d25a2af9dadlr@google.com#define CHROMEOS_PLATFORM_UPDATE_ENGINE_OMAHA_RESPONSE_HANDLER_ACTION_H__
73defe6acb3609e70e851a6eff062577d25a2af9dadlr@google.com
83defe6acb3609e70e851a6eff062577d25a2af9dadlr@google.com#include <string>
918c7bce69dc040dc8e9c2a1dc207f7447fb06e84Darin Petkov
1018c7bce69dc040dc8e9c2a1dc207f7447fb06e84Darin Petkov#include <gtest/gtest_prod.h>  // for FRIEND_TEST
1118c7bce69dc040dc8e9c2a1dc207f7447fb06e84Darin Petkov
123defe6acb3609e70e851a6eff062577d25a2af9dadlr@google.com#include "update_engine/action.h"
133defe6acb3609e70e851a6eff062577d25a2af9dadlr@google.com#include "update_engine/install_plan.h"
146a5b3229b44c1f81ee153829e9b501e547f29926Darin Petkov#include "update_engine/omaha_request_action.h"
153defe6acb3609e70e851a6eff062577d25a2af9dadlr@google.com
163defe6acb3609e70e851a6eff062577d25a2af9dadlr@google.com// This class reads in an Omaha response and converts what it sees into
173defe6acb3609e70e851a6eff062577d25a2af9dadlr@google.com// an install plan which is passed out.
183defe6acb3609e70e851a6eff062577d25a2af9dadlr@google.com
193defe6acb3609e70e851a6eff062577d25a2af9dadlr@google.comnamespace chromeos_update_engine {
203defe6acb3609e70e851a6eff062577d25a2af9dadlr@google.com
213defe6acb3609e70e851a6eff062577d25a2af9dadlr@google.comclass OmahaResponseHandlerAction;
2273058b421f91e04cc605c2a113e0010009a63594Darin Petkovclass PrefsInterface;
233defe6acb3609e70e851a6eff062577d25a2af9dadlr@google.com
243defe6acb3609e70e851a6eff062577d25a2af9dadlr@google.comtemplate<>
253defe6acb3609e70e851a6eff062577d25a2af9dadlr@google.comclass ActionTraits<OmahaResponseHandlerAction> {
263defe6acb3609e70e851a6eff062577d25a2af9dadlr@google.com public:
276a5b3229b44c1f81ee153829e9b501e547f29926Darin Petkov  typedef OmahaResponse InputObjectType;
283defe6acb3609e70e851a6eff062577d25a2af9dadlr@google.com  typedef InstallPlan OutputObjectType;
293defe6acb3609e70e851a6eff062577d25a2af9dadlr@google.com};
303defe6acb3609e70e851a6eff062577d25a2af9dadlr@google.com
313defe6acb3609e70e851a6eff062577d25a2af9dadlr@google.comclass OmahaResponseHandlerAction : public Action<OmahaResponseHandlerAction> {
323defe6acb3609e70e851a6eff062577d25a2af9dadlr@google.com public:
336c11864907e9a92f8069c77c08650102e0b34e0dDarin Petkov  static const char kDeadlineFile[];
346c11864907e9a92f8069c77c08650102e0b34e0dDarin Petkov
35abc7bc0f5d88f110b463191bb8384f95d3c4230aDarin Petkov  OmahaResponseHandlerAction(PrefsInterface* prefs);
363defe6acb3609e70e851a6eff062577d25a2af9dadlr@google.com  typedef ActionTraits<OmahaResponseHandlerAction>::InputObjectType
373defe6acb3609e70e851a6eff062577d25a2af9dadlr@google.com      InputObjectType;
383defe6acb3609e70e851a6eff062577d25a2af9dadlr@google.com  typedef ActionTraits<OmahaResponseHandlerAction>::OutputObjectType
393defe6acb3609e70e851a6eff062577d25a2af9dadlr@google.com      OutputObjectType;
403defe6acb3609e70e851a6eff062577d25a2af9dadlr@google.com  void PerformAction();
413defe6acb3609e70e851a6eff062577d25a2af9dadlr@google.com
423defe6acb3609e70e851a6eff062577d25a2af9dadlr@google.com  // This is a synchronous action, and thus TerminateProcessing() should
433defe6acb3609e70e851a6eff062577d25a2af9dadlr@google.com  // never be called
443defe6acb3609e70e851a6eff062577d25a2af9dadlr@google.com  void TerminateProcessing() { CHECK(false); }
453defe6acb3609e70e851a6eff062577d25a2af9dadlr@google.com
463defe6acb3609e70e851a6eff062577d25a2af9dadlr@google.com  // For unit-testing
473defe6acb3609e70e851a6eff062577d25a2af9dadlr@google.com  void set_boot_device(const std::string& boot_device) {
483defe6acb3609e70e851a6eff062577d25a2af9dadlr@google.com    boot_device_ = boot_device;
493defe6acb3609e70e851a6eff062577d25a2af9dadlr@google.com  }
506a5b3229b44c1f81ee153829e9b501e547f29926Darin Petkov
514fe15d017c145aca449c2248420c1b4ec8c23758Andrew de los Reyes  bool GotNoUpdateResponse() const { return got_no_update_response_; }
5263b96d74b2ffe5999243ab5c33f588030bcb42ceAndrew de los Reyes  const InstallPlan& install_plan() const { return install_plan_; }
533defe6acb3609e70e851a6eff062577d25a2af9dadlr@google.com
543defe6acb3609e70e851a6eff062577d25a2af9dadlr@google.com  // Debugging/logging
553defe6acb3609e70e851a6eff062577d25a2af9dadlr@google.com  static std::string StaticType() { return "OmahaResponseHandlerAction"; }
563defe6acb3609e70e851a6eff062577d25a2af9dadlr@google.com  std::string Type() const { return StaticType(); }
57abc7bc0f5d88f110b463191bb8384f95d3c4230aDarin Petkov  void set_key_path(const std::string& path) { key_path_ = path; }
583defe6acb3609e70e851a6eff062577d25a2af9dadlr@google.com
593defe6acb3609e70e851a6eff062577d25a2af9dadlr@google.com private:
6018c7bce69dc040dc8e9c2a1dc207f7447fb06e84Darin Petkov  FRIEND_TEST(UpdateAttempterTest, CreatePendingErrorEventResumedTest);
6118c7bce69dc040dc8e9c2a1dc207f7447fb06e84Darin Petkov
623defe6acb3609e70e851a6eff062577d25a2af9dadlr@google.com  // Assumes you want to install on the "other" device, where the other
633defe6acb3609e70e851a6eff062577d25a2af9dadlr@google.com  // device is what you get if you swap 1 for 2 or 3 for 4 or vice versa
643defe6acb3609e70e851a6eff062577d25a2af9dadlr@google.com  // for the number at the end of the boot device. E.g., /dev/sda1 -> /dev/sda2
653defe6acb3609e70e851a6eff062577d25a2af9dadlr@google.com  // or /dev/sda4 -> /dev/sda3
663defe6acb3609e70e851a6eff062577d25a2af9dadlr@google.com  static bool GetInstallDev(const std::string& boot_dev,
673defe6acb3609e70e851a6eff062577d25a2af9dadlr@google.com                            std::string* install_dev);
683defe6acb3609e70e851a6eff062577d25a2af9dadlr@google.com
69738fdf37c15284b60dac703408b8de19eef9c6a3Jay Srinivasan  // Returns true if payload hash checks are mandatory based on the state
70738fdf37c15284b60dac703408b8de19eef9c6a3Jay Srinivasan  // of the system and the contents of the Omaha response. False otherwise.
71738fdf37c15284b60dac703408b8de19eef9c6a3Jay Srinivasan  bool AreHashChecksMandatory(const OmahaResponse& response);
72738fdf37c15284b60dac703408b8de19eef9c6a3Jay Srinivasan
7373058b421f91e04cc605c2a113e0010009a63594Darin Petkov  // Update Engine preference store.
7473058b421f91e04cc605c2a113e0010009a63594Darin Petkov  PrefsInterface* prefs_;
7573058b421f91e04cc605c2a113e0010009a63594Darin Petkov
763defe6acb3609e70e851a6eff062577d25a2af9dadlr@google.com  // set to non-empty in unit tests
773defe6acb3609e70e851a6eff062577d25a2af9dadlr@google.com  std::string boot_device_;
786a5b3229b44c1f81ee153829e9b501e547f29926Darin Petkov
7963b96d74b2ffe5999243ab5c33f588030bcb42ceAndrew de los Reyes  // The install plan, if we have an update.
8063b96d74b2ffe5999243ab5c33f588030bcb42ceAndrew de los Reyes  InstallPlan install_plan_;
816a5b3229b44c1f81ee153829e9b501e547f29926Darin Petkov
824fe15d017c145aca449c2248420c1b4ec8c23758Andrew de los Reyes  // True only if we got a response and the response said no updates
834fe15d017c145aca449c2248420c1b4ec8c23758Andrew de los Reyes  bool got_no_update_response_;
843defe6acb3609e70e851a6eff062577d25a2af9dadlr@google.com
85abc7bc0f5d88f110b463191bb8384f95d3c4230aDarin Petkov  // Public key path to use for payload verification.
86abc7bc0f5d88f110b463191bb8384f95d3c4230aDarin Petkov  std::string key_path_;
87abc7bc0f5d88f110b463191bb8384f95d3c4230aDarin Petkov
883defe6acb3609e70e851a6eff062577d25a2af9dadlr@google.com  DISALLOW_COPY_AND_ASSIGN(OmahaResponseHandlerAction);
893defe6acb3609e70e851a6eff062577d25a2af9dadlr@google.com};
903defe6acb3609e70e851a6eff062577d25a2af9dadlr@google.com
913defe6acb3609e70e851a6eff062577d25a2af9dadlr@google.com}  // namespace chromeos_update_engine
923defe6acb3609e70e851a6eff062577d25a2af9dadlr@google.com
933defe6acb3609e70e851a6eff062577d25a2af9dadlr@google.com#endif  // CHROMEOS_PLATFORM_UPDATE_ENGINE_OMAHA_RESPONSE_HANDLER_ACTION_H__
94