blob: db72c91254d04e8c33601fa7459bce052dcdbfc9 [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"
Jay Srinivasan6f6ea002012-12-14 11:26:28 -080015#include "update_engine/system_state.h"
adlr@google.com3defe6a2009-12-04 20:57:17 +000016
17// This class reads in an Omaha response and converts what it sees into
18// an install plan which is passed out.
19
20namespace chromeos_update_engine {
21
22class OmahaResponseHandlerAction;
23
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
Gilad Arnold4dbd47e2013-07-22 05:39:26 -070035 explicit OmahaResponseHandlerAction(SystemState* system_state);
36
adlr@google.com3defe6a2009-12-04 20:57:17 +000037 typedef ActionTraits<OmahaResponseHandlerAction>::InputObjectType
38 InputObjectType;
39 typedef ActionTraits<OmahaResponseHandlerAction>::OutputObjectType
40 OutputObjectType;
41 void PerformAction();
42
43 // This is a synchronous action, and thus TerminateProcessing() should
44 // never be called
45 void TerminateProcessing() { CHECK(false); }
46
47 // For unit-testing
48 void set_boot_device(const std::string& boot_device) {
49 boot_device_ = boot_device;
50 }
Darin Petkov6a5b3222010-07-13 14:55:28 -070051
Andrew de los Reyes4fe15d02009-12-10 19:01:36 -080052 bool GotNoUpdateResponse() const { return got_no_update_response_; }
Andrew de los Reyes63b96d72010-05-10 13:08:54 -070053 const InstallPlan& install_plan() const { return install_plan_; }
adlr@google.com3defe6a2009-12-04 20:57:17 +000054
55 // Debugging/logging
56 static std::string StaticType() { return "OmahaResponseHandlerAction"; }
57 std::string Type() const { return StaticType(); }
Darin Petkovabc7bc02011-02-23 14:39:43 -080058 void set_key_path(const std::string& path) { key_path_ = path; }
adlr@google.com3defe6a2009-12-04 20:57:17 +000059
60 private:
Jay Srinivasan738fdf32012-12-07 17:40:54 -080061 // Returns true if payload hash checks are mandatory based on the state
62 // of the system and the contents of the Omaha response. False otherwise.
63 bool AreHashChecksMandatory(const OmahaResponse& response);
64
Jay Srinivasan6f6ea002012-12-14 11:26:28 -080065 // Global system context.
66 SystemState* system_state_;
Darin Petkov73058b42010-10-06 16:32:19 -070067
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
Darin Petkovabc7bc02011-02-23 14:39:43 -080077 // Public key path to use for payload verification.
78 std::string key_path_;
79
Gilad Arnold4dbd47e2013-07-22 05:39:26 -070080 // File used for communication deadline to Chrome.
81 const std::string deadline_file_;
82
83 // Special ctor + friend declarations for testing purposes.
84 OmahaResponseHandlerAction(SystemState* system_state,
85 const std::string& deadline_file);
86
87 friend class OmahaResponseHandlerActionTest;
88
89 FRIEND_TEST(UpdateAttempterTest, CreatePendingErrorEventResumedTest);
90
adlr@google.com3defe6a2009-12-04 20:57:17 +000091 DISALLOW_COPY_AND_ASSIGN(OmahaResponseHandlerAction);
92};
93
94} // namespace chromeos_update_engine
95
96#endif // CHROMEOS_PLATFORM_UPDATE_ENGINE_OMAHA_RESPONSE_HANDLER_ACTION_H__