OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 #ifndef NET_BASE_TEST_COMPLETION_CALLBACK_H_ | 5 #ifndef NET_BASE_TEST_COMPLETION_CALLBACK_H_ |
6 #define NET_BASE_TEST_COMPLETION_CALLBACK_H_ | 6 #define NET_BASE_TEST_COMPLETION_CALLBACK_H_ |
7 | 7 |
8 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
9 #include "net/base/completion_callback.h" | 9 #include "net/base/completion_callback.h" |
10 | 10 |
(...skipping 20 matching lines...) Expand all Loading... |
31 DCHECK(!waiting_for_result_); | 31 DCHECK(!waiting_for_result_); |
32 while (!have_result_) { | 32 while (!have_result_) { |
33 waiting_for_result_ = true; | 33 waiting_for_result_ = true; |
34 MessageLoop::current()->Run(); | 34 MessageLoop::current()->Run(); |
35 waiting_for_result_ = false; | 35 waiting_for_result_ = false; |
36 } | 36 } |
37 have_result_ = false; // auto-reset for next callback | 37 have_result_ = false; // auto-reset for next callback |
38 return result_; | 38 return result_; |
39 } | 39 } |
40 | 40 |
| 41 bool have_result() const { return have_result_; } |
| 42 |
41 private: | 43 private: |
42 virtual void RunWithParams(const Tuple1<int>& params) { | 44 virtual void RunWithParams(const Tuple1<int>& params) { |
43 result_ = params.a; | 45 result_ = params.a; |
44 have_result_ = true; | 46 have_result_ = true; |
45 if (waiting_for_result_) | 47 if (waiting_for_result_) |
46 MessageLoop::current()->Quit(); | 48 MessageLoop::current()->Quit(); |
47 } | 49 } |
48 | 50 |
49 int result_; | 51 int result_; |
50 bool have_result_; | 52 bool have_result_; |
51 bool waiting_for_result_; | 53 bool waiting_for_result_; |
52 }; | 54 }; |
53 | 55 |
54 #endif // NET_BASE_TEST_COMPLETION_CALLBACK_H_ | 56 #endif // NET_BASE_TEST_COMPLETION_CALLBACK_H_ |
OLD | NEW |