}
void AppInstaller::HandleStepError(Step::Status result,
- const std::string& error) {
- if (pi_)
- pi_->SendError(result, error, context_->pkg_type.get(),
- context_->pkgid.get());
+ const std::string& error) {
+ if (!pi_)
+ return;
+
+ pi_->SendError(result, error, context_->pkg_type.get(),
+ context_->pkgid.get());
+}
+
+bool AppInstaller::SendStartIfNotSent() {
+ if (!pi_)
+ return false;
+
+ if (pi_->state() != PkgmgrSignal::State::NOT_SENT ||
+ context_->pkgid.get().empty())
+ return true;
+
+ // set request type before sending start signal
+ pi_->SetRequestType(context_->request_type.get());
+ pi_->SendStarted(context_->pkg_type.get(), context_->pkgid.get());
+
+ return true;
}
void AppInstaller::SendProgress(int progress) {
- if (pi_) {
- // send START signal as soon as possible if not sent
- if (pi_->state() == PkgmgrSignal::State::NOT_SENT) {
- if (!context_->pkgid.get().empty()) {
- // set request type before sending start signal
- pi_->SetRequestType(context_->request_type.get());
- pi_->SendStarted(context_->pkg_type.get(), context_->pkgid.get());
- }
- }
+ // send START signal as soon as possible if not sent
+ if (!SendStartIfNotSent())
+ return;
- // send installation progress
- pi_->SendProgress(progress,
- context_->pkg_type.get(), context_->pkgid.get());
- }
+ // send installation progress
+ pi_->SendProgress(progress,
+ context_->pkg_type.get(), context_->pkgid.get());
}
void AppInstaller::SendFinished(Step::Status process_status) {
- if (pi_) {
- // send START if pkgid was not parsed
- if (pi_->state() == PkgmgrSignal::State::NOT_SENT) {
- // set request type before sending start signal
- pi_->SetRequestType(context_->request_type.get());
- pi_->SendStarted(context_->pkg_type.get(), context_->pkgid.get());
- }
- pi_->SendFinished(process_status,
- context_->pkg_type.get(),
- context_->pkgid.get());
- }
+ if (!SendStartIfNotSent())
+ return;
+
+ pi_->SendFinished(process_status,
+ context_->pkg_type.get(),
+ context_->pkgid.get());
}
Step::Status AppInstaller::SafeExecute(std::unique_ptr<Step> const& step_ptr,