Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1567)

Unified Diff: chrome/browser/automation/testing_automation_provider.cc

Issue 8274012: Wait for URLBlacklist update tasks on automation tests. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Added CHECKs Created 9 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | chrome/test/functional/PYAUTO_TESTS » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 51ae96eddac979f4cdc9ded67d1c8753dfb86d98..836fe06342d1fc80b98e73c2f7fa47b9e1351b21 100644
--- a/chrome/browser/automation/testing_automation_provider.cc
+++ b/chrome/browser/automation/testing_automation_provider.cc
@@ -176,6 +176,12 @@ class AutomationInterstitialPage : public InterstitialPage {
DISALLOW_COPY_AND_ASSIGN(AutomationInterstitialPage);
};
+// Helper function for nested Binds that resolves the overloading of
+// BrowserThread::PostTask, and ignores the return value.
Joao da Silva 2011/10/21 12:59:58 I tried to resolve the overloading with bool (*po
+void PostTask(BrowserThread::ID id, const base::Closure& task) {
+ CHECK(BrowserThread::PostTask(id, FROM_HERE, task));
Paweł Hajdan Jr. 2011/10/21 15:13:17 Please make it return the value it gets from the r
+}
+
} // namespace
TestingAutomationProvider::TestingAutomationProvider(Profile* profile)
@@ -2730,41 +2736,26 @@ void TestingAutomationProvider::PerformActionOnInfobar(
namespace {
-// Task to get info about BrowserChildProcessHost. Must run on IO thread to
+// Gets info about BrowserChildProcessHost. Must run on IO thread to
// honor the semantics of BrowserChildProcessHost.
// Used by AutomationProvider::GetBrowserInfo().
-class GetChildProcessHostInfoTask : public Task {
- public:
- GetChildProcessHostInfoTask(base::WaitableEvent* event,
- ListValue* child_processes)
- : event_(event),
- child_processes_(child_processes) {}
-
- virtual void Run() {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
- for (BrowserChildProcessHost::Iterator iter; !iter.Done(); ++iter) {
- // Only add processes which are already started,
- // since we need their handle.
- if ((*iter)->handle() == base::kNullProcessHandle) {
- continue;
- }
- ChildProcessInfo* info = *iter;
- DictionaryValue* item = new DictionaryValue;
- item->SetString("name", info->name());
- item->SetString("type",
- ChildProcessInfo::GetTypeNameInEnglish(info->type()));
- item->SetInteger("pid", base::GetProcId(info->handle()));
- child_processes_->Append(item);
+void GetChildProcessHostInfo(ListValue* child_processes) {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
+ for (BrowserChildProcessHost::Iterator iter; !iter.Done(); ++iter) {
+ // Only add processes which are already started,
+ // since we need their handle.
+ if ((*iter)->handle() == base::kNullProcessHandle) {
Paweł Hajdan Jr. 2011/10/21 15:13:17 nit: No need for braces {}.
Joao da Silva 2011/10/22 11:26:50 Done.
+ continue;
}
- event_->Signal();
+ ChildProcessInfo* info = *iter;
+ DictionaryValue* item = new DictionaryValue;
+ item->SetString("name", info->name());
+ item->SetString("type",
+ ChildProcessInfo::GetTypeNameInEnglish(info->type()));
+ item->SetInteger("pid", base::GetProcId(info->handle()));
+ child_processes->Append(item);
}
-
- private:
- base::WaitableEvent* const event_; // weak
- ListValue* child_processes_;
-
- DISALLOW_COPY_AND_ASSIGN(GetChildProcessHostInfoTask);
-};
+}
} // namespace
@@ -2876,20 +2867,6 @@ void TestingAutomationProvider::GetBrowserInfo(
int flags = ChildProcessHost::CHILD_NORMAL;
#endif
- return_value->SetString("child_process_path",
- ChildProcessHost::GetChildPath(flags).value());
- // Child processes are the processes for plugins and other workers.
- // 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();
- return_value->Set("child_processes", child_processes);
-
// Add all extension processes in a list of dictionaries, one dictionary
// item per extension process.
ListValue* extension_views = new ListValue;
@@ -2945,7 +2922,20 @@ void TestingAutomationProvider::GetBrowserInfo(
}
}
return_value->Set("extension_views", extension_views);
- AutomationJSONReply(this, reply_message).SendSuccess(return_value.get());
+
+ return_value->SetString("child_process_path",
+ ChildProcessHost::GetChildPath(flags).value());
+ // Child processes are the processes for plugins and other workers.
+ // Add all child processes in a list of dictionaries, one dictionary item
+ // per child process.
+ ListValue* child_processes = new ListValue;
+ return_value->Set("child_processes", child_processes);
+ CHECK(BrowserThread::PostTaskAndReply(
Paweł Hajdan Jr. 2011/10/21 15:13:17 Why don't you just SendError if this fails?
+ BrowserThread::IO, FROM_HERE,
+ base::Bind(&GetChildProcessHostInfo, child_processes),
+ base::Bind(&AutomationJSONReply::SendSuccess,
+ base::Owned(new AutomationJSONReply(this, reply_message)),
+ base::Owned(return_value.release()))));
}
// Sample json input: { "command": "GetProcessInfo" }
@@ -5871,10 +5861,11 @@ void TestingAutomationProvider::WaitForAllTabsToStopLoading(
void TestingAutomationProvider::SetPolicies(
DictionaryValue* args,
IPC::Message* reply_message) {
- AutomationJSONReply reply(this, reply_message);
+ scoped_ptr<AutomationJSONReply> reply(
+ new AutomationJSONReply(this, reply_message));
#if !defined(ENABLE_CONFIGURATION_POLICY) || defined(OFFICIAL_BUILD)
- reply.SendError("Configuration Policy disabled");
+ reply->SendError("Configuration Policy disabled");
#else
const policy::PolicyDefinitionList* list =
policy::GetChromePolicyDefinitionList();
@@ -5895,7 +5886,7 @@ void TestingAutomationProvider::SetPolicies(
if (args->GetDictionary(providers[i].name, &policies) &&
policies &&
!providers[i].provider) {
- reply.SendError("Provider not available: " + providers[i].name);
+ reply->SendError("Provider not available: " + providers[i].name);
return;
}
}
@@ -5908,7 +5899,17 @@ void TestingAutomationProvider::SetPolicies(
}
}
- reply.SendSuccess(NULL);
+ // 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.
+ PostTask(BrowserThread::IO,
Paweł Hajdan Jr. 2011/10/21 15:13:17 Please add some base::Bind gurus for possible advi
Joao da Silva 2011/10/21 16:25:53 Good idea, adding @willchan as the Bind guru :-)
willchan no longer on Chromium 2011/10/21 20:50:29 This code gave me a good chuckle today. Thanks for
Joao da Silva 2011/10/22 11:26:50 Thanks for taking a look. I've added an explicit c
+ base::Bind(&PostTask, BrowserThread::FILE,
+ base::Bind(&PostTask, BrowserThread::IO,
+ base::Bind(&PostTask, BrowserThread::UI,
Paweł Hajdan Jr. 2011/10/21 15:13:17 So it seems you've done the CHECK in PostTask beca
Joao da Silva 2011/10/21 16:25:53 I think replies have to be sent from UI; please co
+ base::Bind(&AutomationJSONReply::SendSuccess,
+ base::Owned(reply.release()),
+ static_cast<const Value*>(NULL))))));
#endif // defined(OFFICIAL_BUILD)
}
« no previous file with comments | « no previous file | chrome/test/functional/PYAUTO_TESTS » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698