Index: base/test/test_launcher.cc |
diff --git a/base/test/test_launcher.cc b/base/test/test_launcher.cc |
index b131506b026bc658b02edeaba95bec4388a31df6..deabb9a4add1dc1b8ed692d08b5cb6466f4be403 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()); |
@@ -424,7 +433,7 @@ void RunTests(TestLauncherDelegate* launcher_delegate, |
MessageLoop::current()->PostTask( |
FROM_HERE, |
- Bind(&ResultsPrinter::OnAllTestsStarted, Unretained(printer))); |
+ Bind(&ResultsPrinter::OnAllTestsStarted, printer->GetWeakPtr())); |
} |
void RunTestIteration(TestLauncherDelegate* launcher_delegate, |