1aea4c1cea20dda7ae7e85fc8924a2d784f70d806Alex Deymo//
2aea4c1cea20dda7ae7e85fc8924a2d784f70d806Alex Deymo// Copyright (C) 2011 The Android Open Source Project
3aea4c1cea20dda7ae7e85fc8924a2d784f70d806Alex Deymo//
4aea4c1cea20dda7ae7e85fc8924a2d784f70d806Alex Deymo// Licensed under the Apache License, Version 2.0 (the "License");
5aea4c1cea20dda7ae7e85fc8924a2d784f70d806Alex Deymo// you may not use this file except in compliance with the License.
6aea4c1cea20dda7ae7e85fc8924a2d784f70d806Alex Deymo// You may obtain a copy of the License at
7aea4c1cea20dda7ae7e85fc8924a2d784f70d806Alex Deymo//
8aea4c1cea20dda7ae7e85fc8924a2d784f70d806Alex Deymo//      http://www.apache.org/licenses/LICENSE-2.0
9aea4c1cea20dda7ae7e85fc8924a2d784f70d806Alex Deymo//
10aea4c1cea20dda7ae7e85fc8924a2d784f70d806Alex Deymo// Unless required by applicable law or agreed to in writing, software
11aea4c1cea20dda7ae7e85fc8924a2d784f70d806Alex Deymo// distributed under the License is distributed on an "AS IS" BASIS,
12aea4c1cea20dda7ae7e85fc8924a2d784f70d806Alex Deymo// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13aea4c1cea20dda7ae7e85fc8924a2d784f70d806Alex Deymo// See the License for the specific language governing permissions and
14aea4c1cea20dda7ae7e85fc8924a2d784f70d806Alex Deymo// limitations under the License.
15aea4c1cea20dda7ae7e85fc8924a2d784f70d806Alex Deymo//
163defe6acb3609e70e851a6eff062577d25a2af9dadlr@google.com
17cf175a098081f3f0e9ca52d997a7ce1585c14c2dGilad Arnold#ifndef UPDATE_ENGINE_OMAHA_RESPONSE_HANDLER_ACTION_H_
18cf175a098081f3f0e9ca52d997a7ce1585c14c2dGilad Arnold#define UPDATE_ENGINE_OMAHA_RESPONSE_HANDLER_ACTION_H_
193defe6acb3609e70e851a6eff062577d25a2af9dadlr@google.com
203defe6acb3609e70e851a6eff062577d25a2af9dadlr@google.com#include <string>
2118c7bce69dc040dc8e9c2a1dc207f7447fb06e84Darin Petkov
2218c7bce69dc040dc8e9c2a1dc207f7447fb06e84Darin Petkov#include <gtest/gtest_prod.h>  // for FRIEND_TEST
2318c7bce69dc040dc8e9c2a1dc207f7447fb06e84Darin Petkov
2439910dcd1d68987ccee7c3031dc269233a8490bbAlex Deymo#include "update_engine/common/action.h"
256a5b3229b44c1f81ee153829e9b501e547f29926Darin Petkov#include "update_engine/omaha_request_action.h"
2639910dcd1d68987ccee7c3031dc269233a8490bbAlex Deymo#include "update_engine/payload_consumer/install_plan.h"
276f6ea00aa8c4cf54b6842be32ca1226854c24f78Jay Srinivasan#include "update_engine/system_state.h"
283defe6acb3609e70e851a6eff062577d25a2af9dadlr@google.com
293defe6acb3609e70e851a6eff062577d25a2af9dadlr@google.com// This class reads in an Omaha response and converts what it sees into
303defe6acb3609e70e851a6eff062577d25a2af9dadlr@google.com// an install plan which is passed out.
313defe6acb3609e70e851a6eff062577d25a2af9dadlr@google.com
323defe6acb3609e70e851a6eff062577d25a2af9dadlr@google.comnamespace chromeos_update_engine {
333defe6acb3609e70e851a6eff062577d25a2af9dadlr@google.com
343defe6acb3609e70e851a6eff062577d25a2af9dadlr@google.comclass OmahaResponseHandlerAction;
353defe6acb3609e70e851a6eff062577d25a2af9dadlr@google.com
363defe6acb3609e70e851a6eff062577d25a2af9dadlr@google.comtemplate<>
373defe6acb3609e70e851a6eff062577d25a2af9dadlr@google.comclass ActionTraits<OmahaResponseHandlerAction> {
383defe6acb3609e70e851a6eff062577d25a2af9dadlr@google.com public:
396a5b3229b44c1f81ee153829e9b501e547f29926Darin Petkov  typedef OmahaResponse InputObjectType;
403defe6acb3609e70e851a6eff062577d25a2af9dadlr@google.com  typedef InstallPlan OutputObjectType;
413defe6acb3609e70e851a6eff062577d25a2af9dadlr@google.com};
423defe6acb3609e70e851a6eff062577d25a2af9dadlr@google.com
433defe6acb3609e70e851a6eff062577d25a2af9dadlr@google.comclass OmahaResponseHandlerAction : public Action<OmahaResponseHandlerAction> {
443defe6acb3609e70e851a6eff062577d25a2af9dadlr@google.com public:
454dbd47eb03169faac44fce86daffef10cac94b7dGilad Arnold  explicit OmahaResponseHandlerAction(SystemState* system_state);
464dbd47eb03169faac44fce86daffef10cac94b7dGilad Arnold
473defe6acb3609e70e851a6eff062577d25a2af9dadlr@google.com  typedef ActionTraits<OmahaResponseHandlerAction>::InputObjectType
483defe6acb3609e70e851a6eff062577d25a2af9dadlr@google.com      InputObjectType;
493defe6acb3609e70e851a6eff062577d25a2af9dadlr@google.com  typedef ActionTraits<OmahaResponseHandlerAction>::OutputObjectType
503defe6acb3609e70e851a6eff062577d25a2af9dadlr@google.com      OutputObjectType;
51610277efc6f7e5239158dfa4bb3b1021804326e0Alex Deymo  void PerformAction() override;
523defe6acb3609e70e851a6eff062577d25a2af9dadlr@google.com
533defe6acb3609e70e851a6eff062577d25a2af9dadlr@google.com  // This is a synchronous action, and thus TerminateProcessing() should
543defe6acb3609e70e851a6eff062577d25a2af9dadlr@google.com  // never be called
55610277efc6f7e5239158dfa4bb3b1021804326e0Alex Deymo  void TerminateProcessing() override { CHECK(false); }
563defe6acb3609e70e851a6eff062577d25a2af9dadlr@google.com
574fe15d017c145aca449c2248420c1b4ec8c23758Andrew de los Reyes  bool GotNoUpdateResponse() const { return got_no_update_response_; }
5863b96d74b2ffe5999243ab5c33f588030bcb42ceAndrew de los Reyes  const InstallPlan& install_plan() const { return install_plan_; }
593defe6acb3609e70e851a6eff062577d25a2af9dadlr@google.com
603defe6acb3609e70e851a6eff062577d25a2af9dadlr@google.com  // Debugging/logging
613defe6acb3609e70e851a6eff062577d25a2af9dadlr@google.com  static std::string StaticType() { return "OmahaResponseHandlerAction"; }
62610277efc6f7e5239158dfa4bb3b1021804326e0Alex Deymo  std::string Type() const override { return StaticType(); }
63abc7bc0f5d88f110b463191bb8384f95d3c4230aDarin Petkov  void set_key_path(const std::string& path) { key_path_ = path; }
643defe6acb3609e70e851a6eff062577d25a2af9dadlr@google.com
653defe6acb3609e70e851a6eff062577d25a2af9dadlr@google.com private:
66738fdf37c15284b60dac703408b8de19eef9c6a3Jay Srinivasan  // Returns true if payload hash checks are mandatory based on the state
67738fdf37c15284b60dac703408b8de19eef9c6a3Jay Srinivasan  // of the system and the contents of the Omaha response. False otherwise.
68738fdf37c15284b60dac703408b8de19eef9c6a3Jay Srinivasan  bool AreHashChecksMandatory(const OmahaResponse& response);
69738fdf37c15284b60dac703408b8de19eef9c6a3Jay Srinivasan
706f6ea00aa8c4cf54b6842be32ca1226854c24f78Jay Srinivasan  // Global system context.
716f6ea00aa8c4cf54b6842be32ca1226854c24f78Jay Srinivasan  SystemState* system_state_;
7273058b421f91e04cc605c2a113e0010009a63594Darin Petkov
7363b96d74b2ffe5999243ab5c33f588030bcb42ceAndrew de los Reyes  // The install plan, if we have an update.
7463b96d74b2ffe5999243ab5c33f588030bcb42ceAndrew de los Reyes  InstallPlan install_plan_;
756a5b3229b44c1f81ee153829e9b501e547f29926Darin Petkov
764fe15d017c145aca449c2248420c1b4ec8c23758Andrew de los Reyes  // True only if we got a response and the response said no updates
774fe15d017c145aca449c2248420c1b4ec8c23758Andrew de los Reyes  bool got_no_update_response_;
783defe6acb3609e70e851a6eff062577d25a2af9dadlr@google.com
79abc7bc0f5d88f110b463191bb8384f95d3c4230aDarin Petkov  // Public key path to use for payload verification.
80abc7bc0f5d88f110b463191bb8384f95d3c4230aDarin Petkov  std::string key_path_;
81abc7bc0f5d88f110b463191bb8384f95d3c4230aDarin Petkov
824dbd47eb03169faac44fce86daffef10cac94b7dGilad Arnold  // File used for communication deadline to Chrome.
834dbd47eb03169faac44fce86daffef10cac94b7dGilad Arnold  const std::string deadline_file_;
844dbd47eb03169faac44fce86daffef10cac94b7dGilad Arnold
854dbd47eb03169faac44fce86daffef10cac94b7dGilad Arnold  // Special ctor + friend declarations for testing purposes.
864dbd47eb03169faac44fce86daffef10cac94b7dGilad Arnold  OmahaResponseHandlerAction(SystemState* system_state,
874dbd47eb03169faac44fce86daffef10cac94b7dGilad Arnold                             const std::string& deadline_file);
884dbd47eb03169faac44fce86daffef10cac94b7dGilad Arnold
894dbd47eb03169faac44fce86daffef10cac94b7dGilad Arnold  friend class OmahaResponseHandlerActionTest;
904dbd47eb03169faac44fce86daffef10cac94b7dGilad Arnold
914dbd47eb03169faac44fce86daffef10cac94b7dGilad Arnold  FRIEND_TEST(UpdateAttempterTest, CreatePendingErrorEventResumedTest);
924dbd47eb03169faac44fce86daffef10cac94b7dGilad Arnold
933defe6acb3609e70e851a6eff062577d25a2af9dadlr@google.com  DISALLOW_COPY_AND_ASSIGN(OmahaResponseHandlerAction);
943defe6acb3609e70e851a6eff062577d25a2af9dadlr@google.com};
953defe6acb3609e70e851a6eff062577d25a2af9dadlr@google.com
963defe6acb3609e70e851a6eff062577d25a2af9dadlr@google.com}  // namespace chromeos_update_engine
973defe6acb3609e70e851a6eff062577d25a2af9dadlr@google.com
98cf175a098081f3f0e9ca52d997a7ce1585c14c2dGilad Arnold#endif  // UPDATE_ENGINE_OMAHA_RESPONSE_HANDLER_ACTION_H_
99