BrowserThread::PostTask(thread_id, FROM_HERE, quit_task);
}
-// Class used handle result callbacks for ExecuteScriptAndGetValue.
+// Class used to handle result callbacks for ExecuteScriptAndGetValue.
class ScriptCallback {
public:
ScriptCallback() { }
base::MessageLoop::current()->Quit();
}
+// Monitors if any task is processed by the message loop.
+class TaskObserver : public base::MessageLoop::TaskObserver {
+ public:
+ TaskObserver() : processed_(false) {}
+ virtual ~TaskObserver() {}
+
+ // MessageLoop::TaskObserver overrides.
+ virtual void WillProcessTask(const base::PendingTask& pending_task) OVERRIDE {
+ }
+ virtual void DidProcessTask(const base::PendingTask& pending_task) OVERRIDE {
+ processed_ = true;
+ }
+
+ // Returns true if any task was processed.
+ bool processed() const { return processed_; }
+
+ private:
+ bool processed_;
+ DISALLOW_COPY_AND_ASSIGN(TaskObserver);
+};
+
// Adapter that makes a WindowedNotificationObserver::ConditionTestCallback from
// a WindowedNotificationObserver::ConditionTestCallbackWithoutSourceAndDetails
// by ignoring the notification source and details.
RunThisRunLoop(&run_loop);
}
+void RunAllBlockingPoolTasksUntilIdle() {
+ while (true) {
+ content::BrowserThread::GetBlockingPool()->FlushForTesting();
+
+ TaskObserver task_observer;
+ base::MessageLoop::current()->AddTaskObserver(&task_observer);
+ base::RunLoop().RunUntilIdle();
+ base::MessageLoop::current()->RemoveTaskObserver(&task_observer);
+
+ if (!task_observer.processed())
+ break;
+ }
+}
+
base::Closure GetQuitTaskForRunLoop(base::RunLoop* run_loop) {
return base::Bind(&DeferredQuitRunLoop, run_loop->QuitClosure(),
kNumQuitDeferrals);