--- /dev/null
+// Copyright (c) 2020 Samsung Electronics Co., Ltd All Rights Reserved
+// Use of this source code is governed by an apache-2.0 license that can be
+// found in the LICENSE file.
+
+#ifndef COMMON_INSTALLER_FACTORY_H_
+#define COMMON_INSTALLER_FACTORY_H_
+
+#include <memory>
+
+#include "common/pkgmgr_interface.h"
+
+namespace common_installer {
+
+class AppInstaller;
+
+class InstallerFactory {
+ public:
+ virtual std::unique_ptr<AppInstaller> CreateInstaller(PkgMgrPtr pkgmgr,
+ int idx) = 0;
+};
+
+} // namespace common_installer
+
+#endif // COMMON_INSTALLER_FACTORY_H_
--- /dev/null
+// Copyright (c) 2020 Samsung Electronics Co., Ltd All Rights Reserved
+// Use of this source code is governed by an apache 2.0 license that can be
+// found in the LICENSE file.
+
+#include "common/installer_runner.h"
+
+#include <manifest_parser/utils/logging.h>
+
+#include <list>
+
+#include "common/app_installer.h"
+#include "common/installer_factory.h"
+#include "common/pkgmgr_interface.h"
+
+namespace common_installer {
+
+InstallerRunner::InstallerRunner(
+ std::unique_ptr<InstallerFactory> factory, PkgMgrPtr pkgmgr)
+ : factory_(std::move(factory)), pkgmgr_(pkgmgr) {
+ Init();
+}
+
+AppInstaller::Result InstallerRunner::Run() {
+ AppInstaller::Result result = AppInstaller::Result::OK;
+ std::list<std::unique_ptr<AppInstaller>>::iterator it(installers_.begin());
+ for (; it != installers_.end(); ++it) {
+ result = (*it)->Process();
+ if (result != AppInstaller::Result::OK)
+ break;
+ }
+ if (it != installers_.end() && result == AppInstaller::Result::ERROR) {
+ do {
+ if ((*it)->Undo() != AppInstaller::Result::OK)
+ result = AppInstaller::Result::UNDO_ERROR;
+ } while (it-- != installers_.begin());
+ } else {
+ --it;
+ do {
+ if ((*it)->Clean() != AppInstaller::Result::OK)
+ result = AppInstaller::Result::CLEANUP_ERROR;
+ } while (it-- != installers_.begin());
+ }
+
+ return result;
+}
+
+void InstallerRunner::Init() {
+ for (int i = 0; i < pkgmgr_->GetRequestInfoCount(); i++) {
+ std::unique_ptr<AppInstaller> installer =
+ factory_->CreateInstaller(pkgmgr_, i);
+ installers_.emplace_back(std::move(installer));
+ }
+}
+
+} // namespace common_installer
--- /dev/null
+// Copyright (c) 2020 Samsung Electronics Co., Ltd All Rights Reserved
+// Use of this source code is governed by an apache 2.0 license that can be
+// found in the LICENSE file.
+
+#ifndef COMMON_INSTALLER_RUNNER_H_
+#define COMMON_INSTALLER_RUNNER_H_
+
+#include <list>
+#include <memory>
+
+#include "common/app_installer.h"
+#include "common/pkgmgr_interface.h"
+
+namespace common_installer {
+
+class InstallerFactory;
+
+class InstallerRunner {
+ public:
+ explicit InstallerRunner(
+ std::unique_ptr<InstallerFactory> factory, PkgMgrPtr pkgmgr);
+
+ AppInstaller::Result Run();
+
+ private:
+ void Init();
+
+ std::unique_ptr<InstallerFactory> factory_;
+ PkgMgrPtr pkgmgr_;
+ std::list<std::unique_ptr<AppInstaller>> installers_;
+};
+
+} // namespace common_installer
+
+#endif // COMMON_INSTALLER_RUNNER_H_