Fix a bug about pending request 39/291839/1
authorHwankyu Jhun <h.jhun@samsung.com>
Mon, 24 Apr 2023 04:42:08 +0000 (04:42 +0000)
committerHwankyu Jhun <h.jhun@samsung.com>
Mon, 24 Apr 2023 04:42:08 +0000 (04:42 +0000)
When the loader process is preparing, the request will be pended.
In this case, the OnLoaderPrepared() method has to be called.
Unfortunately, there was a bug about that. If the loader manager does
not set the timer, the method cannot be called.

Change-Id: I330974ce62f761b01f5ac09116927f31aaf43b22
Signed-off-by: Hwankyu Jhun <h.jhun@samsung.com>
src/launchpad-process-pool/loader_context.cc
src/launchpad-process-pool/loader_context.hh
src/launchpad-process-pool/loader_manager.cc

index e24c5d8..13d7b22 100644 (file)
@@ -350,11 +350,6 @@ void LoaderContext::UnsetTimer() {
   }
 }
 
-void LoaderContext::SetTimer(LoaderContext::IEvent* listener) {
-  listener_ = listener;
-  SetTimer();
-}
-
 void LoaderContext::SetTimer() {
   if (timer_ > 0) {
     _W("Already registered");
@@ -565,6 +560,10 @@ bool LoaderContext::IsPending() const {
   return pending_;
 }
 
+void LoaderContext::SetEventListener(IEvent* listener) {
+  listener_ = listener;
+}
+
 void LoaderContext::SetLiveTimer() {
   _W("type(%d), loader_name(%s), deactivation_method(%d)",
       GetType(), GetLoaderName().c_str(),
@@ -613,7 +612,7 @@ void LoaderContext::HandleLoaderEvent() {
         pid_ = peer_cred->GetPid();
 
       prepared_ = true;
-      if (listener_!= nullptr)
+      if (listener_ != nullptr)
         listener_->OnLoaderPrepared(this);
 
       SECURE_LOGI("Type %d loader was connected. pid: %d", GetType(), pid_);
index 154d764..0ab3bae 100644 (file)
@@ -95,7 +95,7 @@ class LoaderContext : public std::enable_shared_from_this<LoaderContext>,
   bool IsAppInstalled() const;
   CPUChecker* GetCPUChecker() const;
   void UnsetTimer();
-  void SetTimer(IEvent* listener);
+  void SetTimer();
   void SetOnBootTimer(int timeout);
   bool ShouldWaitForFileCreation();
   int IncreaseCPUCheckCount();
@@ -108,6 +108,7 @@ class LoaderContext : public std::enable_shared_from_this<LoaderContext>,
   bool IsLaunchable();
   void SetPending(bool pending);
   bool IsPending() const;
+  void SetEventListener(IEvent* listener);
 
  protected:
   void SetPrepared(bool prepared);
@@ -118,7 +119,6 @@ class LoaderContext : public std::enable_shared_from_this<LoaderContext>,
   void Activate();
   void Deactivate();
   bool CanDeactivate(LoaderMethod method) const;
-  void SetTimer();
   void SetLiveTimer();
   void HandleLoaderEvent();
   void HandleLoaderClientEvent(int condition);
index 333574a..7d88860 100644 (file)
@@ -98,8 +98,10 @@ void LoaderManager::AddDefaultLoaderContexts() {
 
   for (auto& info : loader_info_manager_->GetLoaderInfoList()) {
     auto context = LoaderFactory::GetInst().CreateLoaderContext(info);
-    if (context != nullptr)
+    if (context != nullptr) {
+      context->SetEventListener(this);
       loader_contexts_.push_back(std::move(context));
+    }
   }
 
   ActivateLoaderContexts(LoaderMethod::None);
@@ -164,7 +166,8 @@ std::shared_ptr<LoaderContext> LoaderManager::AddLoaderContext(
   if (context == nullptr)
     return nullptr;
 
-  context->SetTimer(this);
+  context->SetEventListener(this);
+  context->SetTimer();
   loader_contexts_.push_back(context);
   return context;
 }
@@ -184,7 +187,7 @@ void LoaderManager::HandleDirectLaunch(std::shared_ptr<LoaderContext> context) {
 
   context->UnsetTimer();
   context->UpdateState(LoaderMethod::Request, true);
-  context->SetTimer(this);
+  context->SetTimer();
 }
 
 void LoaderManager::UpdateAppInstallationStatus(const std::string& app_type,