| // Copyright 2021 The Chromium OS Authors. All rights reserved. |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| |
| #ifndef RMAD_STATE_HANDLER_FINALIZE_STATE_HANDLER_H_ |
| #define RMAD_STATE_HANDLER_FINALIZE_STATE_HANDLER_H_ |
| |
| #include "rmad/state_handler/base_state_handler.h" |
| |
| #include <memory> |
| #include <utility> |
| |
| #include <base/files/file_util.h> |
| #include <base/memory/scoped_refptr.h> |
| #include <base/sequenced_task_runner.h> |
| #include <base/timer/timer.h> |
| |
| #include "rmad/utils/cr50_utils.h" |
| |
| namespace rmad { |
| |
| class FinalizeStateHandler : public BaseStateHandler { |
| public: |
| // Report status every second. |
| static constexpr base::TimeDelta kReportStatusInterval = |
| base::TimeDelta::FromSeconds(1); |
| |
| explicit FinalizeStateHandler(scoped_refptr<JsonStore> json_store); |
| FinalizeStateHandler(scoped_refptr<JsonStore> json_store, |
| std::unique_ptr<Cr50Utils> cr50_utils); |
| |
| ASSIGN_STATE(RmadState::StateCase::kFinalize); |
| SET_UNREPEATABLE; |
| |
| void RegisterSignalSender( |
| std::unique_ptr<FinalizeSignalCallback> callback) override { |
| finalize_signal_sender_ = std::move(callback); |
| } |
| |
| RmadErrorCode InitializeState() override; |
| void CleanUpState() override; |
| GetNextStateCaseReply GetNextStateCase(const RmadState& state) override; |
| |
| void StartTasks(); |
| |
| protected: |
| ~FinalizeStateHandler() override = default; |
| |
| private: |
| void SendStatusSignal(); |
| void StartStatusTimer(); |
| void StopStatusTimer(); |
| |
| void StartFinalize(); |
| void FinalizeTask(); |
| |
| std::unique_ptr<Cr50Utils> cr50_utils_; |
| FinalizeStatus status_; |
| std::unique_ptr<FinalizeSignalCallback> finalize_signal_sender_; |
| base::RepeatingTimer status_timer_; |
| scoped_refptr<base::SequencedTaskRunner> task_runner_; |
| }; |
| |
| namespace fake { |
| |
| class FakeFinalizeStateHandler : public FinalizeStateHandler { |
| public: |
| FakeFinalizeStateHandler(scoped_refptr<JsonStore> json_store, |
| const base::FilePath& working_dir_path); |
| |
| protected: |
| ~FakeFinalizeStateHandler() override = default; |
| }; |
| |
| } // namespace fake |
| |
| } // namespace rmad |
| |
| #endif // RMAD_STATE_HANDLER_FINALIZE_STATE_HANDLER_H_ |