Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "net/base/test_completion_callback.h" | 5 #include "net/base/test_completion_callback.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
| 9 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
| 10 #include "base/message_loop/message_loop.h" | 10 #include "base/run_loop.h" |
| 11 #include "net/base/io_buffer.h" | 11 #include "net/base/io_buffer.h" |
| 12 | 12 |
| 13 namespace net { | 13 namespace net { |
| 14 | 14 |
| 15 namespace internal { | 15 namespace internal { |
| 16 | 16 |
| 17 void TestCompletionCallbackBaseInternal::DidSetResult() { | 17 void TestCompletionCallbackBaseInternal::DidSetResult() { |
| 18 have_result_ = true; | 18 have_result_ = true; |
| 19 if (waiting_for_result_) | 19 if (run_loop_) |
| 20 base::MessageLoop::current()->Quit(); | 20 run_loop_->Quit(); |
| 21 } | 21 } |
| 22 | 22 |
| 23 void TestCompletionCallbackBaseInternal::WaitForResult() { | 23 void TestCompletionCallbackBaseInternal::WaitForResult() { |
| 24 DCHECK(!waiting_for_result_); | 24 DCHECK(!run_loop_); |
| 25 while (!have_result_) { | 25 if (!have_result_) { |
| 26 waiting_for_result_ = true; | 26 run_loop_.reset(new base::RunLoop()); |
| 27 base::MessageLoop::current()->Run(); | 27 run_loop_->Run(); |
| 28 waiting_for_result_ = false; | 28 run_loop_.reset(); |
| 29 DCHECK(have_result_); | |
| 30 // A huge number of tests depend on this class running events after the | |
| 31 // result is set. | |
| 32 // TODO(mmenke): We really should fix this. | |
|
mmenke
2015/05/20 17:37:05
Note that 300+ tests depend on this - mostly SPDY
Ryan Hamilton
2015/05/20 22:43:48
Oy!
| |
| 33 base::RunLoop().RunUntilIdle(); | |
| 29 } | 34 } |
| 30 have_result_ = false; // Auto-reset for next callback. | 35 have_result_ = false; // Auto-reset for next callback. |
| 31 } | 36 } |
| 32 | 37 |
| 33 TestCompletionCallbackBaseInternal::TestCompletionCallbackBaseInternal() | 38 TestCompletionCallbackBaseInternal::TestCompletionCallbackBaseInternal() |
| 34 : have_result_(false), | 39 : have_result_(false) { |
| 35 waiting_for_result_(false) { | |
| 36 } | 40 } |
| 37 | 41 |
| 38 TestCompletionCallbackBaseInternal::~TestCompletionCallbackBaseInternal() { | 42 TestCompletionCallbackBaseInternal::~TestCompletionCallbackBaseInternal() { |
| 39 } | 43 } |
| 40 | 44 |
| 41 } // namespace internal | 45 } // namespace internal |
| 42 | 46 |
| 43 TestClosure::TestClosure() | 47 TestClosure::TestClosure() |
| 44 : closure_(base::Bind(&TestClosure::DidSetResult, base::Unretained(this))) { | 48 : closure_(base::Bind(&TestClosure::DidSetResult, base::Unretained(this))) { |
| 45 } | 49 } |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 70 ReleaseBufferCompletionCallback::~ReleaseBufferCompletionCallback() { | 74 ReleaseBufferCompletionCallback::~ReleaseBufferCompletionCallback() { |
| 71 } | 75 } |
| 72 | 76 |
| 73 void ReleaseBufferCompletionCallback::SetResult(int result) { | 77 void ReleaseBufferCompletionCallback::SetResult(int result) { |
| 74 if (!buffer_->HasOneRef()) | 78 if (!buffer_->HasOneRef()) |
| 75 result = ERR_FAILED; | 79 result = ERR_FAILED; |
| 76 TestCompletionCallback::SetResult(result); | 80 TestCompletionCallback::SetResult(result); |
| 77 } | 81 } |
| 78 | 82 |
| 79 } // namespace net | 83 } // namespace net |
| OLD | NEW |