RenderProcessHostImpl dtor is not executed.
authorAntonio Gomes <a1.gomes@samsung.com>
Wed, 13 Jan 2016 20:51:26 +0000 (16:51 -0400)
committerYoungsoo Choi <kenshin.choi@samsung.com>
Tue, 10 Jul 2018 07:55:23 +0000 (07:55 +0000)
Since forcibly shutdown our UI message loop, it is possible
that important pending Tasks are simply not executed.
Among these, the destruction of RenderProcessHostImpl class
(scheduled with DeleteSoon) performs various process um-plumbing
stuff.
Particularly, RenderProcessHostImpl holds a strong references of lots
of other objects (e.g. URLRequestContextGetterEfl, RenderWidgetHelper,
ChildProcessLauncher, etc) and not performing the proper destruction
of them might result in crashes at shutdown or other undefined problems.

Patch gives the UI message loop a extra run ('till it gets idle)
to perform such pending tasks.

In order to implement this, it was required to unstub the
implementation of MessagePumpForUIEfl::Run, based on the logic
described in base/message_loop/message_pump.h, as well as in
message_pump_{default,glib}.cc

Callstack looks like:
- EwkGlobalData::~EwkGlobalData
- MessageLoop::RunUntilIdle
- RunLoop::RunUntilIdle
- RunLoop::Run
- MessageLoop::RunHandler
- MessagePumpForUIEfl::Run # idle state will break the loop

Original beta/m47 patches:
- http://165.213.202.130/gerrit/#/c/103446/
- http://165.213.202.130/gerrit/#/c/104287/

Bug: http://107.108.218.239/bugzilla/show_bug.cgi?id=15557

Reviewed by: djmix.kim, sns.park

Change-Id: I2957a0a7fb942daf9bcbf74431d91acb8cff7902
Signed-off-by: Antonio Gomes <a1.gomes@samsung.com>
tizen_src/ewk/efl_integration/ewk_global_data.cc
tizen_src/ewk/efl_integration/message_pump_for_ui_efl.cc
tizen_src/ewk/efl_integration/message_pump_for_ui_efl.h

index a7c6965..38a3560 100644 (file)
@@ -68,6 +68,20 @@ EwkGlobalData::~EwkGlobalData() {
   // We need to pretend that message loop was stopped so chromium unwinds correctly
   MessageLoop *loop = MessageLoop::current();
   loop->QuitNow();
+
+  // Since we forcibly shutdown our UI message loop, it is possible
+  // that important pending Tasks are simply not executed.
+  // Among these, the destruction of RenderProcessHostImpl class
+  // (scheduled with DeleteSoon) performs various process umplumbing
+  // stuff and also holds strong references of lots of other objects
+  // (e.g. URLRequestContextGetterEfl, RenderWidgetHelper,
+  // ChildProcessLauncher). Not performing the proper destruction
+  // of them might result in crashes or other undefined problems.
+  //
+  // Line below gives the message loop a extra run ('till it gets idle)
+  // to perform such pending tasks.
+  loop->RunUntilIdle();
+
   // browser_main_runner must be deleted first as it depends on content_main_runner
   delete browser_main_runner_;
   delete content_main_runner_;
index b624657..3f84660 100644 (file)
@@ -23,6 +23,7 @@ MessagePumpForUIEfl::MessagePumpForUIEfl()
   : pipe_(ecore_pipe_add(&PipeCallback, this))
   , schedule_delayed_work_timer_(NULL)
   , run_loop_(NULL)
+  , keep_running_(true)
   , work_scheduled_(false) {
 }
 
@@ -44,7 +45,30 @@ MessagePumpForUIEfl::~MessagePumpForUIEfl() {
 
 // FIXME: need to be implemented for tests.
 void MessagePumpForUIEfl::Run(base::MessagePump::Delegate* delegate) {
-  NOTREACHED();
+  DCHECK(keep_running_) << "Quit must have been called outside of Run!";
+
+  bool previous_keep_running = keep_running_;
+  keep_running_ = true;
+
+  for (;;) {
+    bool did_work = delegate->DoWork();
+    if (!keep_running_)
+      break;
+
+    base::TimeTicks next_time;
+    did_work |= delegate->DoDelayedWork(&next_time);
+    if (!keep_running_)
+      break;
+
+    if (did_work)
+      continue;
+
+    did_work = delegate->DoIdleWork();
+    if (!keep_running_)
+      break;
+  }
+
+  keep_running_ = previous_keep_running;
 }
 
 // FIXME: need to be implemented for tests.
@@ -61,6 +85,7 @@ void MessagePumpForUIEfl::Quit() {
   }
   pipe_ = NULL;
   schedule_delayed_work_timer_ = NULL;
+  keep_running_ = false;
 }
 
 void MessagePumpForUIEfl::ScheduleWork() {
index 42168a8..b8d5498 100644 (file)
@@ -41,6 +41,7 @@ class BASE_EXPORT MessagePumpForUIEfl : public base::MessagePump {
   Delegate* delegate_;
   RunLoop* run_loop_;
   base::Lock schedule_work_lock_;
+  bool keep_running_;
   bool work_scheduled_;
 
   DISALLOW_COPY_AND_ASSIGN(MessagePumpForUIEfl);