[M47_2526] Chromium upversion to m47_2526 branch
[platform/framework/web/chromium-efl.git] / tizen_src / ewk / efl_integration / message_pump_for_ui_efl.cc
index ca7e223..1c829de 100644 (file)
@@ -22,13 +22,8 @@ static const int dummy_pipe_message_size = 1;
 MessagePumpForUIEfl::MessagePumpForUIEfl()
   : pipe_(ecore_pipe_add(&PipeCallback, this))
   , schedule_delayed_work_timer_(NULL)
-  , delegate_(base::MessageLoopForUI::current())
-  , run_loop_(new RunLoop())
+  , run_loop_(NULL)
   , work_scheduled_(false) {
-  // Since the RunLoop was just created above, BeforeRun should be guaranteed to
-  // return true (it only returns false if the RunLoop has been Quit already).
-  bool result = run_loop_->BeforeRun();
-  DCHECK(result);
 }
 
 MessagePumpForUIEfl::~MessagePumpForUIEfl() {
@@ -58,10 +53,12 @@ void MessagePumpForUIEfl::Quit() {
   ecore_pipe_del(pipe_);
   if (schedule_delayed_work_timer_)
     ecore_timer_del(schedule_delayed_work_timer_);
-  DCHECK(run_loop_->running());
-  run_loop_->AfterRun();
-  delete run_loop_;
-  run_loop_ = NULL;
+  if (run_loop_) {
+    DCHECK(run_loop_->running());
+    run_loop_->AfterRun();
+    delete run_loop_;
+    run_loop_ = NULL;
+  }
   pipe_ = NULL;
   schedule_delayed_work_timer_ = NULL;
 }
@@ -127,17 +124,24 @@ void MessagePumpForUIEfl::DoWork() {
     work_scheduled_ = false;
   }
 
-  bool more_work_is_plausible = delegate_->DoWork();
+  Delegate* delegate = base::MessageLoopForUI::current();
+  if (!run_loop_) {
+    run_loop_ = new RunLoop();
+    bool result = run_loop_->BeforeRun();
+    DCHECK(result);
+  }
+
+  bool more_work_is_plausible = delegate->DoWork();
 
   base::TimeTicks delayed_work_time;
-  more_work_is_plausible |= delegate_->DoDelayedWork(&delayed_work_time);
+  more_work_is_plausible |= delegate->DoDelayedWork(&delayed_work_time);
 
   if (more_work_is_plausible) {
     ScheduleWork();
     return;
   }
 
-  more_work_is_plausible |= delegate_->DoIdleWork();
+  more_work_is_plausible |= delegate->DoIdleWork();
   if (more_work_is_plausible) {
     ScheduleWork();
     return;
@@ -149,7 +153,7 @@ void MessagePumpForUIEfl::DoWork() {
 
 void MessagePumpForUIEfl::DoDelayedWork() {
   base::TimeTicks next_delayed_work_time;
-  delegate_->DoDelayedWork(&next_delayed_work_time);
+  base::MessageLoopForUI::current()->DoDelayedWork(&next_delayed_work_time);
 
   if (!next_delayed_work_time.is_null())
     ScheduleDelayedWork(next_delayed_work_time);