123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147 |
- #include "update_engine/common/action_processor.h"
- #include <string>
- #include <utility>
- #include <base/logging.h>
- #include "update_engine/common/action.h"
- #include "update_engine/common/error_code_utils.h"
- using std::string;
- using std::unique_ptr;
- namespace chromeos_update_engine {
- ActionProcessor::~ActionProcessor() {
- if (IsRunning())
- StopProcessing();
- }
- void ActionProcessor::EnqueueAction(unique_ptr<AbstractAction> action) {
- action->SetProcessor(this);
- actions_.push_back(std::move(action));
- }
- bool ActionProcessor::IsRunning() const {
- return current_action_ != nullptr || suspended_;
- }
- void ActionProcessor::StartProcessing() {
- CHECK(!IsRunning());
- if (!actions_.empty()) {
- current_action_ = std::move(actions_.front());
- actions_.pop_front();
- LOG(INFO) << "ActionProcessor: starting " << current_action_->Type();
- current_action_->PerformAction();
- }
- }
- void ActionProcessor::StopProcessing() {
- CHECK(IsRunning());
- if (current_action_) {
- current_action_->TerminateProcessing();
- }
- LOG(INFO) << "ActionProcessor: aborted "
- << (current_action_ ? current_action_->Type() : "")
- << (suspended_ ? " while suspended" : "");
- current_action_.reset();
- suspended_ = false;
-
- actions_.clear();
- if (delegate_)
- delegate_->ProcessingStopped(this);
- }
- void ActionProcessor::SuspendProcessing() {
-
-
- if (suspended_ || !current_action_) {
- LOG(WARNING) << "Called SuspendProcessing while not processing.";
- return;
- }
- suspended_ = true;
-
-
- LOG(INFO) << "ActionProcessor: suspending " << current_action_->Type();
- current_action_->SuspendAction();
- }
- void ActionProcessor::ResumeProcessing() {
- if (!suspended_) {
- LOG(WARNING) << "Called ResumeProcessing while not suspended.";
- return;
- }
- suspended_ = false;
- if (current_action_) {
-
-
- LOG(INFO) << "ActionProcessor: resuming " << current_action_->Type();
- current_action_->ResumeAction();
- } else {
-
-
-
-
- LOG(INFO) << "ActionProcessor: resuming processing";
- StartNextActionOrFinish(suspended_error_code_);
- }
- }
- void ActionProcessor::ActionComplete(AbstractAction* actionptr,
- ErrorCode code) {
- CHECK_EQ(actionptr, current_action_.get());
- if (delegate_)
- delegate_->ActionCompleted(this, actionptr, code);
- string old_type = current_action_->Type();
- current_action_->ActionCompleted(code);
- current_action_.reset();
- LOG(INFO) << "ActionProcessor: finished "
- << (actions_.empty() ? "last action " : "") << old_type
- << (suspended_ ? " while suspended" : "") << " with code "
- << utils::ErrorCodeToString(code);
- if (!actions_.empty() && code != ErrorCode::kSuccess) {
- LOG(INFO) << "ActionProcessor: Aborting processing due to failure.";
- actions_.clear();
- }
- if (suspended_) {
-
-
-
- suspended_error_code_ = code;
- return;
- }
- StartNextActionOrFinish(code);
- }
- void ActionProcessor::StartNextActionOrFinish(ErrorCode code) {
- if (actions_.empty()) {
- if (delegate_) {
- delegate_->ProcessingDone(this, code);
- }
- return;
- }
- current_action_ = std::move(actions_.front());
- actions_.pop_front();
- LOG(INFO) << "ActionProcessor: starting " << current_action_->Type();
- current_action_->PerformAction();
- }
- }
|