Chromium Code Reviews| Index: sandbox/tests/common/controller.cc |
| =================================================================== |
| --- sandbox/tests/common/controller.cc (revision 128951) |
| +++ sandbox/tests/common/controller.cc (working copy) |
| @@ -1,4 +1,4 @@ |
| -// Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| +// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| @@ -81,11 +81,13 @@ |
| } |
| TestRunner::TestRunner(JobLevel job_level, TokenLevel startup_token, |
| - TokenLevel main_token) : is_init_(false) { |
| + TokenLevel main_token) |
| + : is_init_(false), is_async_(false), target_process_id_(0) { |
| Init(job_level, startup_token, main_token); |
| } |
| -TestRunner::TestRunner() : is_init_(false) { |
| +TestRunner::TestRunner() |
| + : is_init_(false), is_async_(false), target_process_id_(0) { |
| Init(JOB_LOCKDOWN, USER_RESTRICTED_SAME_ACCESS, USER_LOCKDOWN); |
| } |
| @@ -95,6 +97,9 @@ |
| policy_ = NULL; |
| timeout_ = kDefaultTimeout; |
| state_ = AFTER_REVERT; |
| + is_async_= false; |
| + target_process_.Close(); |
|
rvargas (doing something else)
2012/03/27 00:35:33
?
jschuh
2012/03/27 01:36:19
Done.
|
| + target_process_id_ = 0; |
| broker_ = GetBroker(); |
| if (!broker_) |
| @@ -115,6 +120,9 @@ |
| } |
| TestRunner::~TestRunner() { |
| + if (broker_ && broker_->IsActiveTarget(target_process_id_)) |
|
rvargas (doing something else)
2012/03/27 00:35:33
why not always?
jschuh
2012/03/27 01:36:19
The process ID could get reused. Probably just par
rvargas (doing something else)
2012/03/27 02:30:59
But we have a handle, there's no need to worry abo
|
| + ::TerminateProcess(target_process_, 0); |
| + |
| if (policy_) |
| policy_->Release(); |
| } |
| @@ -177,6 +185,14 @@ |
| if (!is_init_) |
| return SBOX_TEST_FAILED_TO_RUN_TEST; |
| + // For simplicity TestRunner supports only one process per instance. |
| + if (target_process_) { |
| + if (broker_ && broker_->IsActiveTarget(target_process_id_)) |
|
rvargas (doing something else)
2012/03/27 00:35:33
We should be able to do this within this class (wi
jschuh
2012/03/27 01:36:19
I originally had it with GetExitCodeProcess, but t
rvargas (doing something else)
2012/03/27 02:30:59
But this only cares about creating two targets, th
|
| + return SBOX_TEST_FAILED_TO_RUN_TEST; |
| + target_process_.Close(); |
| + target_process_id_ = 0; |
| + } |
| + |
| // Get the path to the sandboxed process. |
| wchar_t prog_name[MAX_PATH]; |
| GetModuleFileNameW(NULL, prog_name, MAX_PATH); |
| @@ -198,6 +214,14 @@ |
| ::ResumeThread(target.hThread); |
| + // For an asynchronous run we don't bother waiting. |
| + if (is_async_) { |
| + target_process_.Set(target.hProcess); |
| + target_process_id_ = target.dwProcessId; |
| + ::CloseHandle(target.hThread); |
| + return SBOX_TEST_SUCCEEDED; |
| + } |
| + |
| if (::IsDebuggerPresent()) { |
| // Don't kill the target process on a time-out while we are debugging. |
| timeout_ = INFINITE; |