Minor refactor 12/237612/4
authorJunghyun Yeon <jungh.yeon@samsung.com>
Thu, 2 Jul 2020 01:15:21 +0000 (10:15 +0900)
committerJunghyun Yeon <jungh.yeon@samsung.com>
Tue, 7 Jul 2020 04:24:23 +0000 (04:24 +0000)
- Apply early-return policy.
- Extract common codes into separate function.

Change-Id: Ied7b9789e5063ec580baa7d297626763070eed0b
Signed-off-by: Junghyun Yeon <jungh.yeon@samsung.com>
src/common/installer/app_installer.cc
src/common/installer/app_installer.h

index 5c1b468a451b834cae10c3dd35470425a893e900..c3fcd07807f5224d1765ed4ab38a7a2a5feca923 100644 (file)
@@ -815,41 +815,46 @@ void AppInstaller::UnknownSteps() {
 }
 
 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,
index ad2b8ea10679f1f2c9a1f709110949248d986ebd..ce225de49c9b0526710fb1cde22f2a4edec44f38 100644 (file)
@@ -291,6 +291,7 @@ class AppInstaller {
   // data used to send signal
   std::unique_ptr<PkgmgrSignal> pi_;
 
+  bool SendStartIfNotSent();
   void SendProgress(int progress);
   void SendFinished(Step::Status status);
   Step::Status SafeExecute(std::unique_ptr<Step> const& step_ptr,