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 #ifndef NET_COOKIES_COOKIE_STORE_TEST_CALLBACKS_H_ | 5 #ifndef NET_COOKIES_COOKIE_STORE_TEST_CALLBACKS_H_ |
6 #define NET_COOKIES_COOKIE_STORE_TEST_CALLBACKS_H_ | 6 #define NET_COOKIES_COOKIE_STORE_TEST_CALLBACKS_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
| 11 #include "base/run_loop.h" |
11 #include "net/cookies/canonical_cookie.h" | 12 #include "net/cookies/canonical_cookie.h" |
12 #include "net/cookies/cookie_store.h" | 13 #include "net/cookies/cookie_store.h" |
13 | 14 |
14 namespace base { | 15 namespace base { |
15 class MessageLoop; | 16 class MessageLoop; |
16 class Thread; | 17 class Thread; |
17 } | 18 } |
18 | 19 |
19 namespace net { | 20 namespace net { |
20 | 21 |
21 // Defines common behaviour for the callbacks from GetCookies, SetCookies, etc. | 22 // Defines common behaviour for the callbacks from GetCookies, SetCookies, etc. |
22 // Asserts that the current thread is the expected invocation thread, sends a | 23 // Asserts that the current thread is the expected invocation thread, sends a |
23 // quit to the thread in which it was constructed. | 24 // quit to the thread in which it was constructed. |
24 class CookieCallback { | 25 class CookieCallback { |
25 public: | 26 public: |
26 // Indicates whether the callback has been called. | 27 // Waits until the callback is invoked. |
27 bool did_run() { return did_run_; } | 28 void WaitUntilDone(); |
28 | 29 |
29 protected: | 30 protected: |
30 // Constructs a callback that expects to be called in the given thread and | 31 // Constructs a callback that expects to be called in the given thread. |
31 // will, upon execution, send a QUIT to the constructing thread. | |
32 explicit CookieCallback(base::Thread* run_in_thread); | 32 explicit CookieCallback(base::Thread* run_in_thread); |
33 | 33 |
34 // Constructs a callback that expects to be called in current thread and will | 34 // Constructs a callback that expects to be called in current thread and will |
35 // send a QUIT to the constructing thread. | 35 // send a QUIT to the constructing thread. |
36 CookieCallback(); | 36 CookieCallback(); |
37 | 37 |
| 38 ~CookieCallback(); |
| 39 |
38 // Tests whether the current thread was the caller's thread. | 40 // Tests whether the current thread was the caller's thread. |
39 // Sends a QUIT to the constructing thread. | 41 // Sends a QUIT to the constructing thread. |
40 void CallbackEpilogue(); | 42 void CallbackEpilogue(); |
41 | 43 |
42 private: | 44 private: |
43 bool did_run_; | |
44 base::Thread* run_in_thread_; | 45 base::Thread* run_in_thread_; |
45 base::MessageLoop* run_in_loop_; | 46 base::MessageLoop* run_in_loop_; |
46 base::MessageLoop* parent_loop_; | 47 base::RunLoop loop_to_quit_; |
47 base::MessageLoop* loop_to_quit_; | |
48 }; | 48 }; |
49 | 49 |
50 // Callback implementations for the asynchronous CookieStore methods. | 50 // Callback implementations for the asynchronous CookieStore methods. |
51 | 51 |
52 template <typename T> | 52 template <typename T> |
53 class ResultSavingCookieCallback : public CookieCallback { | 53 class ResultSavingCookieCallback : public CookieCallback { |
54 public: | 54 public: |
55 ResultSavingCookieCallback() { | 55 ResultSavingCookieCallback() { |
56 } | 56 } |
57 explicit ResultSavingCookieCallback(base::Thread* run_in_thread) | 57 explicit ResultSavingCookieCallback(base::Thread* run_in_thread) |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
106 | 106 |
107 const CookieList& cookies() { return cookies_; } | 107 const CookieList& cookies() { return cookies_; } |
108 | 108 |
109 private: | 109 private: |
110 CookieList cookies_; | 110 CookieList cookies_; |
111 }; | 111 }; |
112 | 112 |
113 } // namespace net | 113 } // namespace net |
114 | 114 |
115 #endif // NET_COOKIES_COOKIE_STORE_TEST_CALLBACKS_H_ | 115 #endif // NET_COOKIES_COOKIE_STORE_TEST_CALLBACKS_H_ |
OLD | NEW |