| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "content/public/test/test_utils.h" | 5 #include "content/public/test/test_utils.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
| 9 #include "base/run_loop.h" | 9 #include "base/run_loop.h" |
| 10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 125 | 125 |
| 126 render_view_host->ExecuteJavascriptInWebFrameCallbackResult( | 126 render_view_host->ExecuteJavascriptInWebFrameCallbackResult( |
| 127 string16(), // frame_xpath, | 127 string16(), // frame_xpath, |
| 128 UTF8ToUTF16(script), | 128 UTF8ToUTF16(script), |
| 129 base::Bind(&ScriptCallback::ResultCallback, base::Unretained(&observer))); | 129 base::Bind(&ScriptCallback::ResultCallback, base::Unretained(&observer))); |
| 130 MessageLoop* loop = MessageLoop::current(); | 130 MessageLoop* loop = MessageLoop::current(); |
| 131 loop->Run(); | 131 loop->Run(); |
| 132 return observer.result().Pass(); | 132 return observer.result().Pass(); |
| 133 } | 133 } |
| 134 | 134 |
| 135 MessageLoopRunner::MessageLoopRunner() { | 135 MessageLoopRunner::MessageLoopRunner() |
| 136 : loop_running_(false), |
| 137 quit_closure_called_(false) { |
| 136 } | 138 } |
| 137 | 139 |
| 138 MessageLoopRunner::~MessageLoopRunner() { | 140 MessageLoopRunner::~MessageLoopRunner() { |
| 139 } | 141 } |
| 140 | 142 |
| 141 void MessageLoopRunner::Run() { | 143 void MessageLoopRunner::Run() { |
| 144 // Do not run the message loop if our quit closure has already been called. |
| 145 // This helps in scenarios where the closure has a chance to run before |
| 146 // we Run explicitly. |
| 147 if (quit_closure_called_) |
| 148 return; |
| 149 |
| 150 loop_running_ = true; |
| 142 RunThisRunLoop(&run_loop_); | 151 RunThisRunLoop(&run_loop_); |
| 143 } | 152 } |
| 144 | 153 |
| 145 base::Closure MessageLoopRunner::QuitClosure() { | 154 base::Closure MessageLoopRunner::QuitClosure() { |
| 146 return base::Bind(&MessageLoopRunner::Quit, this); | 155 return base::Bind(&MessageLoopRunner::Quit, this); |
| 147 } | 156 } |
| 148 | 157 |
| 149 void MessageLoopRunner::Quit() { | 158 void MessageLoopRunner::Quit() { |
| 150 GetQuitTaskForRunLoop(&run_loop_).Run(); | 159 quit_closure_called_ = true; |
| 160 |
| 161 // Only run the quit task if we are running the message loop. |
| 162 if (loop_running_) { |
| 163 GetQuitTaskForRunLoop(&run_loop_).Run(); |
| 164 loop_running_ = false; |
| 165 } |
| 151 } | 166 } |
| 152 | 167 |
| 153 WindowedNotificationObserver::WindowedNotificationObserver( | 168 WindowedNotificationObserver::WindowedNotificationObserver( |
| 154 int notification_type, | 169 int notification_type, |
| 155 const NotificationSource& source) | 170 const NotificationSource& source) |
| 156 : seen_(false), | 171 : seen_(false), |
| 157 running_(false), | 172 running_(false), |
| 158 source_(NotificationService::AllSources()) { | 173 source_(NotificationService::AllSources()) { |
| 159 registrar_.Add(this, notification_type, source); | 174 registrar_.Add(this, notification_type, source); |
| 160 } | 175 } |
| (...skipping 18 matching lines...) Expand all Loading... |
| 179 details_ = details; | 194 details_ = details; |
| 180 seen_ = true; | 195 seen_ = true; |
| 181 if (!running_) | 196 if (!running_) |
| 182 return; | 197 return; |
| 183 | 198 |
| 184 message_loop_runner_->Quit(); | 199 message_loop_runner_->Quit(); |
| 185 running_ = false; | 200 running_ = false; |
| 186 } | 201 } |
| 187 | 202 |
| 188 } // namespace content | 203 } // namespace content |
| OLD | NEW |