Index: chrome/browser/automation/testing_automation_provider.cc |
diff --git a/chrome/browser/automation/testing_automation_provider.cc b/chrome/browser/automation/testing_automation_provider.cc |
index 58a04741f2109e7b289ffce7f17fd92bf98a8d0e..be0adb24c0ce513d625ee8a8c94b3598f820bff5 100644 |
--- a/chrome/browser/automation/testing_automation_provider.cc |
+++ b/chrome/browser/automation/testing_automation_provider.cc |
@@ -20,6 +20,7 @@ |
#include "base/process.h" |
#include "base/process_util.h" |
#include "base/stringprintf.h" |
+#include "base/synchronization/waitable_event.h" |
#include "base/threading/thread_restrictions.h" |
#include "base/time.h" |
#include "base/utf_string_conversions.h" |
@@ -176,6 +177,17 @@ class AutomationInterstitialPage : public InterstitialPage { |
DISALLOW_COPY_AND_ASSIGN(AutomationInterstitialPage); |
}; |
+void WaitForPendingTasksOn(BrowserThread::ID identifier) { |
+ CHECK(!BrowserThread::CurrentlyOn(identifier)); |
Paweł Hajdan Jr.
2011/10/18 10:30:45
I commented about those lines. Please apply that c
|
+ base::WaitableEvent event(true, // manual reset |
+ false); // not initially signaled |
+ CHECK(BrowserThread::PostTask( |
+ identifier, |
+ FROM_HERE, |
+ base::Bind(&base::WaitableEvent::Signal, base::Unretained(&event)))); |
+ event.Wait(); |
+} |
+ |
} // namespace |
TestingAutomationProvider::TestingAutomationProvider(Profile* profile) |
@@ -2734,12 +2746,10 @@ namespace { |
// Used by AutomationProvider::GetBrowserInfo(). |
class GetChildProcessHostInfoTask : public Task { |
public: |
- GetChildProcessHostInfoTask(base::WaitableEvent* event, |
- ListValue* child_processes) |
- : event_(event), |
- child_processes_(child_processes) {} |
+ explicit GetChildProcessHostInfoTask(ListValue* child_processes) |
+ : child_processes_(child_processes) {} |
- virtual void Run() { |
+ virtual void Run() OVERRIDE { |
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
for (BrowserChildProcessHost::Iterator iter; !iter.Done(); ++iter) { |
// Only add processes which are already started, |
@@ -2755,11 +2765,9 @@ class GetChildProcessHostInfoTask : public Task { |
item->SetInteger("pid", base::GetProcId(info->handle())); |
child_processes_->Append(item); |
} |
- event_->Signal(); |
} |
private: |
- base::WaitableEvent* const event_; // weak |
ListValue* child_processes_; |
DISALLOW_COPY_AND_ASSIGN(GetChildProcessHostInfoTask); |
@@ -2881,12 +2889,10 @@ void TestingAutomationProvider::GetBrowserInfo( |
// Add all child processes in a list of dictionaries, one dictionary item |
// per child process. |
ListValue* child_processes = new ListValue; |
- base::WaitableEvent event(true /* manual reset */, |
- false /* not initially signaled */); |
CHECK(BrowserThread::PostTask( |
BrowserThread::IO, FROM_HERE, |
- new GetChildProcessHostInfoTask(&event, child_processes))); |
- event.Wait(); |
+ new GetChildProcessHostInfoTask(child_processes))); |
+ WaitForPendingTasksOn(BrowserThread::IO); |
return_value->Set("child_processes", child_processes); |
// Add all extension processes in a list of dictionaries, one dictionary |
@@ -5901,6 +5907,14 @@ void TestingAutomationProvider::SetPolicies( |
} |
} |
+ // OverridePolicies() triggers preference updates, which triggers preference |
+ // listeners. Some policies (e.g. URLBlacklist) post tasks to other message |
+ // loops before they start being enforced; make sure those tasks have |
+ // finished. |
+ WaitForPendingTasksOn(BrowserThread::IO); |
+ WaitForPendingTasksOn(BrowserThread::FILE); |
+ WaitForPendingTasksOn(BrowserThread::IO); |
+ |
reply.SendSuccess(NULL); |
#endif // defined(OFFICIAL_BUILD) |
} |