Chromium Code Reviews| Index: base/test/test_launcher.cc |
| diff --git a/base/test/test_launcher.cc b/base/test/test_launcher.cc |
| index b131506b026bc658b02edeaba95bec4388a31df6..14bef22324b12ae1946638bb8fcdb73e0a862bfb 100644 |
| --- a/base/test/test_launcher.cc |
| +++ b/base/test/test_launcher.cc |
| @@ -128,6 +128,8 @@ class ResultsPrinter { |
| // Adds |result| to the stored test results. |
| void AddTestResult(const TestResult& result); |
| + WeakPtr<ResultsPrinter> GetWeakPtr(); |
| + |
| private: |
| // Prints a list of tests that finished with |status|. |
| void PrintTestsByStatus(TestResult::Status status, |
| @@ -153,6 +155,8 @@ class ResultsPrinter { |
| ThreadChecker thread_checker_; |
| + WeakPtrFactory<ResultsPrinter> weak_ptr_; |
| + |
| DISALLOW_COPY_AND_ASSIGN(ResultsPrinter); |
| }; |
| @@ -161,7 +165,8 @@ ResultsPrinter::ResultsPrinter(const CommandLine& command_line, |
| : test_started_count_(0), |
| test_run_count_(0), |
| out_(NULL), |
| - callback_(callback) { |
| + callback_(callback), |
| + weak_ptr_(this) { |
| if (!command_line.HasSwitch(kGTestOutputFlag)) |
| return; |
| std::string flag = command_line.GetSwitchValueASCII(kGTestOutputFlag); |
| @@ -291,6 +296,10 @@ void ResultsPrinter::AddTestResult(const TestResult& result) { |
| } |
| } |
| +WeakPtr<ResultsPrinter> ResultsPrinter::GetWeakPtr() { |
| + return weak_ptr_.GetWeakPtr(); |
| +} |
| + |
| void ResultsPrinter::PrintTestsByStatus(TestResult::Status status, |
| const std::string& description) { |
| DCHECK(thread_checker_.CalledOnValidThread()); |
| @@ -413,7 +422,7 @@ void RunTests(TestLauncherDelegate* launcher_delegate, |
| Unretained(launcher_delegate), |
| test_case, |
| test_info, |
| - Bind(&ResultsPrinter::AddTestResult, Unretained(printer)))); |
| + Bind(&ResultsPrinter::AddTestResult, printer->GetWeakPtr()))); |
|
Paweł Hajdan Jr.
2013/09/04 21:41:39
This shouldn't be a weak pointer and should crash
sadrul
2013/09/04 21:46:36
Reverted this change.
|
| } |
| } |
| @@ -424,7 +433,8 @@ void RunTests(TestLauncherDelegate* launcher_delegate, |
| MessageLoop::current()->PostTask( |
| FROM_HERE, |
| - Bind(&ResultsPrinter::OnAllTestsStarted, Unretained(printer))); |
| + Bind(&ResultsPrinter::OnAllTestsStarted, |
| + printer->GetWeakPtr())); |
|
Paweł Hajdan Jr.
2013/09/04 21:41:39
nit: Does this fit on the previous line?
sadrul
2013/09/04 21:46:36
Yep. Done.
|
| } |
| void RunTestIteration(TestLauncherDelegate* launcher_delegate, |