Do not create extended main loop for termination by |Terminate| 68/110768/2
authorYoungsoo Choi <kenshin.choi@samsung.com>
Mon, 16 Jan 2017 03:51:12 +0000 (12:51 +0900)
committerYoungsoo Choi <kenshin.choi@samsung.com>
Wed, 18 Jan 2017 03:41:14 +0000 (12:41 +0900)
There are two types of termination sequences.

The first one is terminated by |Terminate| and another one is
terminated by |OnTerminate| triggered by application framework.

In case of termination by |OnTerminate|, app f/w emits elm_shutdown that
quits main loop so extended main loop is needed to finish termination sequence.

Btw, in case of termination by |Terminate|, app f/w does not interrupt current
main loop so it is stll alive and extended main loop is not needed.

This CL introduces not to create extended main loop for the termination
by |Terminate|.

Bug: http://suprem.sec.samsung.net/jira/browse/TWF-2804

Change-Id: I15147c9d07ec768bdb7f8acf92e18886ec2c100d
Signed-off-by: Youngsoo Choi <kenshin.choi@samsung.com>
runtime/browser/runtime.cc
runtime/browser/runtime.h
runtime/browser/web_application.cc
runtime/browser/web_application.h

index 5861b0860716fa365d2285c6fa9c9567f0e3363d..2254bfc43929a989a3d66c062a700d6f49901153 100644 (file)
@@ -58,25 +58,10 @@ std::unique_ptr<Runtime> Runtime::MakeRuntime(
   }
 }
 
-// static
-Eina_Bool Runtime::ClosePageInExtendedMainLoop(void* user_data)
-{
-  LOGGER(DEBUG);
-  struct Timer* main_loop = static_cast<Timer*>(user_data);
-  main_loop->application->ClosePage();
-  return ECORE_CALLBACK_CANCEL;
-}
-
 void Runtime::ProcessClosingPage(WebApplication* application) {
   LOGGER(DEBUG);
-  if (application) {
-    struct Timer main_loop;
-    main_loop.application = application;
-    main_loop.timer = ecore_timer_add(MAIN_LOOP_INTERVAL, ClosePageInExtendedMainLoop, &main_loop);
-    LOGGER(DEBUG) << "Defer termination of main loop";
-    ecore_main_loop_begin();
-    ecore_timer_del(main_loop.timer);
-  }
+  if (application)
+    application->ProcessClosingPage();
 }
 
 }  // namespace runtime
index 63ddc97040833e087f656554eafb5adf98a129be..a003dac56d59dc9cb5acbbedbcf373831b854847 100755 (executable)
@@ -38,14 +38,6 @@ class Runtime {
 
  protected:
   void ProcessClosingPage(WebApplication* application);
-
- private:
-  static Eina_Bool ClosePageInExtendedMainLoop(void* user_data);
-  struct Timer
-  {
-    WebApplication* application;
-    Ecore_Timer* timer;
-  };
 };
 
 }  // namespace runtime
index e11d9e07831cdab4621c834704fbedfcf8628275..97d9bb388792c2facfb16baf86e366d6eee363da 100755 (executable)
@@ -52,7 +52,8 @@
 #error INJECTED_BUNDLE_PATH is not set.
 #endif
 
-#define TIMER_INTERVAL 0.1
+#define SESSION_COUNTER_INTERVAL 0.1
+#define MAIN_LOOP_INTERVAL 1
 
 using namespace extensions;
 
@@ -647,20 +648,35 @@ void WebApplication::Suspend() {
 
 void WebApplication::Terminate() {
   is_terminate_called_ = true;
-  if (terminator_) {
-    LOGGER(DEBUG) << "terminator_";
-    terminator_();
-  } else {
-    LOGGER(ERROR) << "There's no registered terminator.";
-    elm_exit();
-  }
-  auto extension_server = extensions::XWalkExtensionServer::GetInstance();
-  LOGGER(DEBUG) << "Shutdown extension server";
-  extension_server->Shutdown();
+  ClosePage();
+}
+
+// static
+Eina_Bool WebApplication::ClosePageInExtendedMainLoop(void* user_data)
+{
+  LOGGER(DEBUG);
+  struct Timer* main_loop = static_cast<Timer*>(user_data);
+  main_loop->application->ClosePage();
+  return ECORE_CALLBACK_CANCEL;
+}
+
+void WebApplication::ProcessClosingPage() {
+  LOGGER(DEBUG);
+
+  main_loop.application = this;
+  main_loop.timer = ecore_timer_add(MAIN_LOOP_INTERVAL,
+      ClosePageInExtendedMainLoop, &main_loop);
+  if (!main_loop.timer)
+    LOGGER(ERROR) << "It's failed to create main_loop timer";
+  LOGGER(DEBUG) << "Defer termination of main loop";
+  ecore_main_loop_begin();
+  ecore_timer_del(main_loop.timer);
+  ecore_timer_del(session_counter.timer);
 }
 
 void WebApplication::ClosePage() {
   LOGGER(DEBUG);
+
   int valid_evas_object_count = 0;
   auto it = view_stack_.begin();
   if (it != view_stack_.end()) {
@@ -675,18 +691,20 @@ void WebApplication::ClosePage() {
       }
     }
   }
-  if (valid_evas_object_count == 0) {
-    if (is_terminate_called_) {
-      ecore_main_loop_quit();
-    } else {
-      if (terminator_) {
-        LOGGER(DEBUG) << "terminator_";
-        terminator_();
-      } else {
-        LOGGER(ERROR) << "There's no registered terminator.";
-        elm_exit();
-      }
-    }
+  if (valid_evas_object_count == 0)
+    Exit();
+}
+
+void WebApplication::Exit() {
+  if (!is_terminate_called_)
+    ecore_main_loop_quit();
+
+  if (terminator_) {
+    LOGGER(DEBUG) << "terminator_";
+    terminator_();
+  } else {
+    LOGGER(ERROR) << "There's no registered terminator.";
+    elm_exit();
   }
 }
 
@@ -723,13 +741,9 @@ void WebApplication::RemoveWebViewFromStack(WebView* view) {
   }
 
   if (view_stack_.size() == 0) {
-    // If |Terminate()| hasn't been called,
-    // main loop shouldn't be terminated here.
-    if (!is_terminate_called_) {
-      auto extension_server = XWalkExtensionServer::GetInstance();
-      LOGGER(DEBUG) << "Shutdown extension server";
-      extension_server->Shutdown();
-    }
+    auto extension_server = XWalkExtensionServer::GetInstance();
+    LOGGER(DEBUG) << "Shutdown extension server";
+    extension_server->Shutdown();
   } else if (current != view_stack_.front()) {
     view_stack_.front()->SetVisibility(true);
     window_->SetContent(view_stack_.front()->evas_object());
@@ -746,7 +760,7 @@ void WebApplication::RemoveWebViewFromStack(WebView* view) {
 
 Eina_Bool WebApplication::CheckPluginSession(void* user_data)
 {
-  WebApplication* that = static_cast<WebApplication*>(user_data);
+  struct Timer* session_counter = static_cast<Timer*>(user_data);
   if(XWalkExtensionRendererController::plugin_session_count > 0) {
     LOGGER(ERROR) << "plugin_session_count : " <<
         XWalkExtensionRendererController::plugin_session_count;
@@ -755,30 +769,22 @@ Eina_Bool WebApplication::CheckPluginSession(void* user_data)
   LOGGER(DEBUG) << "plugin_session_count : " <<
       XWalkExtensionRendererController::plugin_session_count;
   LOGGER(DEBUG) << "Execute deferred termination of main loop";
-  if (that->is_terminate_called_) {
-    ecore_main_loop_quit();
-  } else {
-    if (that->terminator_) {
-      LOGGER(DEBUG) << "terminator_";
-      that->terminator_();
-    } else {
-      LOGGER(ERROR) << "There's no registered terminator.";
-      elm_exit();
-    }
-  }
+  session_counter->application->Exit();
   return ECORE_CALLBACK_CANCEL;
 }
 
 void WebApplication::OnClosedWebView(WebView* view) {
-  Ecore_Timer* timeout_id = NULL;
   // Reply to javascript dialog for preventing freeze issue.
   view->ReplyToJavascriptDialog();
   RemoveWebViewFromStack(view);
 
   LOGGER(DEBUG) << "plugin_session_count : " <<
       XWalkExtensionRendererController::plugin_session_count;
-  if (!ecore_timer_add(TIMER_INTERVAL, CheckPluginSession, this))
-    LOGGER(ERROR) << "It's failed to create timer";
+  session_counter.application = this;
+  session_counter.timer = ecore_timer_add(SESSION_COUNTER_INTERVAL,
+      CheckPluginSession, &session_counter);
+  if (!session_counter.timer)
+    LOGGER(ERROR) << "It's failed to create session_counter timer";
 }
 
 void WebApplication::OnReceivedWrtMessage(WebView* view,
index 3fdbdfe516aaab2106801d3ef3cb2401c331fd1f..446fb49436000fe613caf01714c189bccdbbe443 100755 (executable)
@@ -53,6 +53,9 @@ class WebApplication : public WebView::EventListener {
   void Terminate();
 
   void ClosePage();
+  void Exit();
+  void ProcessClosingPage();
+
   std::string data_path() const { return app_data_path_; }
   void set_terminator(std::function<void(void)> terminator) {
     terminator_ = terminator;
@@ -107,6 +110,12 @@ class WebApplication : public WebView::EventListener {
   virtual void OnRotatePrepared(WebView* view);
 #endif // MANUAL_ROTATE_FEATURE_SUPPORT
   static Eina_Bool CheckPluginSession(void* user_data);
+  static Eina_Bool ClosePageInExtendedMainLoop(void* user_data);
+  struct Timer
+  {
+    WebApplication* application;
+    Ecore_Timer* timer;
+  } main_loop, session_counter;
 
  private:
   bool Initialize();