blob: d9bf01f496991d85fec721106e20a019f1b5cdad [file] [log] [blame]
Darin Petkov18c7bce2011-06-16 14:07:00 -07001// Copyright (c) 2011 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>
Darin Petkov18c7bce2011-06-16 14:07:00 -07009
10#include <gtest/gtest_prod.h> // for FRIEND_TEST
11
adlr@google.com3defe6a2009-12-04 20:57:17 +000012#include "update_engine/action.h"
13#include "update_engine/install_plan.h"
Darin Petkov6a5b3222010-07-13 14:55:28 -070014#include "update_engine/omaha_request_action.h"
adlr@google.com3defe6a2009-12-04 20:57:17 +000015
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;
Darin Petkov73058b42010-10-06 16:32:19 -070022class PrefsInterface;
adlr@google.com3defe6a2009-12-04 20:57:17 +000023
24template<>
25class ActionTraits<OmahaResponseHandlerAction> {
26 public:
Darin Petkov6a5b3222010-07-13 14:55:28 -070027 typedef OmahaResponse InputObjectType;
adlr@google.com3defe6a2009-12-04 20:57:17 +000028 typedef InstallPlan OutputObjectType;
29};
30
31class OmahaResponseHandlerAction : public Action<OmahaResponseHandlerAction> {
32 public:
Darin Petkov6c118642010-10-21 12:06:30 -070033 static const char kDeadlineFile[];
34
Darin Petkovabc7bc02011-02-23 14:39:43 -080035 OmahaResponseHandlerAction(PrefsInterface* prefs);
adlr@google.com3defe6a2009-12-04 20:57:17 +000036 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 }
Darin Petkov6a5b3222010-07-13 14:55:28 -070050
Andrew de los Reyes4fe15d02009-12-10 19:01:36 -080051 bool GotNoUpdateResponse() const { return got_no_update_response_; }
Andrew de los Reyes63b96d72010-05-10 13:08:54 -070052 const InstallPlan& install_plan() const { return install_plan_; }
adlr@google.com3defe6a2009-12-04 20:57:17 +000053
54 // Debugging/logging
55 static std::string StaticType() { return "OmahaResponseHandlerAction"; }
56 std::string Type() const { return StaticType(); }
Darin Petkovabc7bc02011-02-23 14:39:43 -080057 void set_key_path(const std::string& path) { key_path_ = path; }
adlr@google.com3defe6a2009-12-04 20:57:17 +000058
59 private:
Darin Petkov18c7bce2011-06-16 14:07:00 -070060 FRIEND_TEST(UpdateAttempterTest, CreatePendingErrorEventResumedTest);
61
adlr@google.com3defe6a2009-12-04 20:57:17 +000062 // 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
Darin Petkov73058b42010-10-06 16:32:19 -070069 // Update Engine preference store.
70 PrefsInterface* prefs_;
71
adlr@google.com3defe6a2009-12-04 20:57:17 +000072 // set to non-empty in unit tests
73 std::string boot_device_;
Darin Petkov6a5b3222010-07-13 14:55:28 -070074
Andrew de los Reyes63b96d72010-05-10 13:08:54 -070075 // The install plan, if we have an update.
76 InstallPlan install_plan_;
Darin Petkov6a5b3222010-07-13 14:55:28 -070077
Andrew de los Reyes4fe15d02009-12-10 19:01:36 -080078 // True only if we got a response and the response said no updates
79 bool got_no_update_response_;
adlr@google.com3defe6a2009-12-04 20:57:17 +000080
Darin Petkovabc7bc02011-02-23 14:39:43 -080081 // Public key path to use for payload verification.
82 std::string key_path_;
83
adlr@google.com3defe6a2009-12-04 20:57:17 +000084 DISALLOW_COPY_AND_ASSIGN(OmahaResponseHandlerAction);
85};
86
87} // namespace chromeos_update_engine
88
89#endif // CHROMEOS_PLATFORM_UPDATE_ENGINE_OMAHA_RESPONSE_HANDLER_ACTION_H__