blob: b5feabdecd51b215171e3dd3a407d3752e72cf1f [file] [log] [blame]
adlr@google.com3defe6a2009-12-04 20:57:17 +00001// Copyright (c) 2009 The Chromium 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#include "update_engine/action.h"
10#include "update_engine/install_plan.h"
Darin Petkov6a5b3222010-07-13 14:55:28 -070011#include "update_engine/omaha_request_action.h"
adlr@google.com3defe6a2009-12-04 20:57:17 +000012
13// This class reads in an Omaha response and converts what it sees into
14// an install plan which is passed out.
15
16namespace chromeos_update_engine {
17
18class OmahaResponseHandlerAction;
19
20template<>
21class ActionTraits<OmahaResponseHandlerAction> {
22 public:
Darin Petkov6a5b3222010-07-13 14:55:28 -070023 typedef OmahaResponse InputObjectType;
adlr@google.com3defe6a2009-12-04 20:57:17 +000024 typedef InstallPlan OutputObjectType;
25};
26
27class OmahaResponseHandlerAction : public Action<OmahaResponseHandlerAction> {
28 public:
Andrew de los Reyes4fe15d02009-12-10 19:01:36 -080029 OmahaResponseHandlerAction() : got_no_update_response_(false) {}
adlr@google.com3defe6a2009-12-04 20:57:17 +000030 typedef ActionTraits<OmahaResponseHandlerAction>::InputObjectType
31 InputObjectType;
32 typedef ActionTraits<OmahaResponseHandlerAction>::OutputObjectType
33 OutputObjectType;
34 void PerformAction();
35
36 // This is a synchronous action, and thus TerminateProcessing() should
37 // never be called
38 void TerminateProcessing() { CHECK(false); }
39
40 // For unit-testing
41 void set_boot_device(const std::string& boot_device) {
42 boot_device_ = boot_device;
43 }
Darin Petkov6a5b3222010-07-13 14:55:28 -070044
Andrew de los Reyes4fe15d02009-12-10 19:01:36 -080045 bool GotNoUpdateResponse() const { return got_no_update_response_; }
Andrew de los Reyes63b96d72010-05-10 13:08:54 -070046 const InstallPlan& install_plan() const { return install_plan_; }
adlr@google.com3defe6a2009-12-04 20:57:17 +000047
48 // Debugging/logging
49 static std::string StaticType() { return "OmahaResponseHandlerAction"; }
50 std::string Type() const { return StaticType(); }
51
52 private:
53 // Assumes you want to install on the "other" device, where the other
54 // device is what you get if you swap 1 for 2 or 3 for 4 or vice versa
55 // for the number at the end of the boot device. E.g., /dev/sda1 -> /dev/sda2
56 // or /dev/sda4 -> /dev/sda3
57 static bool GetInstallDev(const std::string& boot_dev,
58 std::string* install_dev);
59
60 // set to non-empty in unit tests
61 std::string boot_device_;
Darin Petkov6a5b3222010-07-13 14:55:28 -070062
Andrew de los Reyes63b96d72010-05-10 13:08:54 -070063 // The install plan, if we have an update.
64 InstallPlan install_plan_;
Darin Petkov6a5b3222010-07-13 14:55:28 -070065
Andrew de los Reyes4fe15d02009-12-10 19:01:36 -080066 // True only if we got a response and the response said no updates
67 bool got_no_update_response_;
adlr@google.com3defe6a2009-12-04 20:57:17 +000068
69 DISALLOW_COPY_AND_ASSIGN(OmahaResponseHandlerAction);
70};
71
72} // namespace chromeos_update_engine
73
74#endif // CHROMEOS_PLATFORM_UPDATE_ENGINE_OMAHA_RESPONSE_HANDLER_ACTION_H__