blob: 25c57e0e1d297e3e4883fceb7cd92f43f781d1ee [file] [log] [blame]
Darin Petkov73058b42010-10-06 16:32:19 -07001// Copyright (c) 2010 The Chromium OS Authors. All rights reserved.
adlr@google.com3defe6a2009-12-04 20:57:17 +00002// 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;
Darin Petkov73058b42010-10-06 16:32:19 -070019class PrefsInterface;
adlr@google.com3defe6a2009-12-04 20:57:17 +000020
21template<>
22class ActionTraits<OmahaResponseHandlerAction> {
23 public:
Darin Petkov6a5b3222010-07-13 14:55:28 -070024 typedef OmahaResponse InputObjectType;
adlr@google.com3defe6a2009-12-04 20:57:17 +000025 typedef InstallPlan OutputObjectType;
26};
27
28class OmahaResponseHandlerAction : public Action<OmahaResponseHandlerAction> {
29 public:
Darin Petkov6c118642010-10-21 12:06:30 -070030 static const char kDeadlineFile[];
31
Darin Petkov73058b42010-10-06 16:32:19 -070032 OmahaResponseHandlerAction(PrefsInterface* prefs)
33 : prefs_(prefs),
34 got_no_update_response_(false) {}
adlr@google.com3defe6a2009-12-04 20:57:17 +000035 typedef ActionTraits<OmahaResponseHandlerAction>::InputObjectType
36 InputObjectType;
37 typedef ActionTraits<OmahaResponseHandlerAction>::OutputObjectType
38 OutputObjectType;
39 void PerformAction();
40
41 // This is a synchronous action, and thus TerminateProcessing() should
42 // never be called
43 void TerminateProcessing() { CHECK(false); }
44
45 // For unit-testing
46 void set_boot_device(const std::string& boot_device) {
47 boot_device_ = boot_device;
48 }
Darin Petkov6a5b3222010-07-13 14:55:28 -070049
Andrew de los Reyes4fe15d02009-12-10 19:01:36 -080050 bool GotNoUpdateResponse() const { return got_no_update_response_; }
Andrew de los Reyes63b96d72010-05-10 13:08:54 -070051 const InstallPlan& install_plan() const { return install_plan_; }
adlr@google.com3defe6a2009-12-04 20:57:17 +000052
53 // Debugging/logging
54 static std::string StaticType() { return "OmahaResponseHandlerAction"; }
55 std::string Type() const { return StaticType(); }
56
57 private:
58 // Assumes you want to install on the "other" device, where the other
59 // device is what you get if you swap 1 for 2 or 3 for 4 or vice versa
60 // for the number at the end of the boot device. E.g., /dev/sda1 -> /dev/sda2
61 // or /dev/sda4 -> /dev/sda3
62 static bool GetInstallDev(const std::string& boot_dev,
63 std::string* install_dev);
64
Darin Petkov73058b42010-10-06 16:32:19 -070065 // Update Engine preference store.
66 PrefsInterface* prefs_;
67
adlr@google.com3defe6a2009-12-04 20:57:17 +000068 // set to non-empty in unit tests
69 std::string boot_device_;
Darin Petkov6a5b3222010-07-13 14:55:28 -070070
Andrew de los Reyes63b96d72010-05-10 13:08:54 -070071 // The install plan, if we have an update.
72 InstallPlan install_plan_;
Darin Petkov6a5b3222010-07-13 14:55:28 -070073
Andrew de los Reyes4fe15d02009-12-10 19:01:36 -080074 // True only if we got a response and the response said no updates
75 bool got_no_update_response_;
adlr@google.com3defe6a2009-12-04 20:57:17 +000076
77 DISALLOW_COPY_AND_ASSIGN(OmahaResponseHandlerAction);
78};
79
80} // namespace chromeos_update_engine
81
82#endif // CHROMEOS_PLATFORM_UPDATE_ENGINE_OMAHA_RESPONSE_HANDLER_ACTION_H__