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 #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 // Indicates whether the callback has been called. |
| 27 bool did_run() { return did_run_; } | 28 bool did_run() { return did_run_; } |
|
mmenke
2016/01/27 16:55:42
This is no longer needed - the fact that the messa
xunjieli
2016/01/27 18:35:02
Done.
| |
| 28 | 29 |
| 30 // Waits until the callback is invoked. | |
| 31 void WaitUntilDone(); | |
| 32 | |
| 29 protected: | 33 protected: |
| 30 // Constructs a callback that expects to be called in the given thread and | 34 // Constructs a callback that expects to be called in the given thread and |
| 31 // will, upon execution, send a QUIT to the constructing thread. | 35 // will, upon execution, send a QUIT to the constructing thread. |
| 32 explicit CookieCallback(base::Thread* run_in_thread); | 36 explicit CookieCallback(base::Thread* run_in_thread); |
| 33 | 37 |
| 34 // Constructs a callback that expects to be called in current thread and will | 38 // Constructs a callback that expects to be called in current thread and will |
| 35 // send a QUIT to the constructing thread. | 39 // send a QUIT to the constructing thread. |
| 36 CookieCallback(); | 40 CookieCallback(); |
| 37 | 41 |
| 42 ~CookieCallback(); | |
| 43 | |
| 38 // Tests whether the current thread was the caller's thread. | 44 // Tests whether the current thread was the caller's thread. |
| 39 // Sends a QUIT to the constructing thread. | 45 // Sends a QUIT to the constructing thread. |
| 40 void CallbackEpilogue(); | 46 void CallbackEpilogue(); |
| 41 | 47 |
| 42 private: | 48 private: |
| 43 bool did_run_; | 49 bool did_run_; |
| 44 base::Thread* run_in_thread_; | 50 base::Thread* run_in_thread_; |
| 45 base::MessageLoop* run_in_loop_; | 51 base::MessageLoop* run_in_loop_; |
| 46 base::MessageLoop* parent_loop_; | 52 scoped_ptr<base::RunLoop> loop_to_quit_; |
|
mmenke
2016/01/27 16:55:42
No need to use a scoped_ptr.
xunjieli
2016/01/27 18:35:02
Done.
| |
| 47 base::MessageLoop* loop_to_quit_; | |
| 48 }; | 53 }; |
| 49 | 54 |
| 50 // Callback implementations for the asynchronous CookieStore methods. | 55 // Callback implementations for the asynchronous CookieStore methods. |
| 51 | 56 |
| 52 template <typename T> | 57 template <typename T> |
| 53 class ResultSavingCookieCallback : public CookieCallback { | 58 class ResultSavingCookieCallback : public CookieCallback { |
| 54 public: | 59 public: |
| 55 ResultSavingCookieCallback() { | 60 ResultSavingCookieCallback() { |
| 56 } | 61 } |
| 57 explicit ResultSavingCookieCallback(base::Thread* run_in_thread) | 62 explicit ResultSavingCookieCallback(base::Thread* run_in_thread) |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 106 | 111 |
| 107 const CookieList& cookies() { return cookies_; } | 112 const CookieList& cookies() { return cookies_; } |
| 108 | 113 |
| 109 private: | 114 private: |
| 110 CookieList cookies_; | 115 CookieList cookies_; |
| 111 }; | 116 }; |
| 112 | 117 |
| 113 } // namespace net | 118 } // namespace net |
| 114 | 119 |
| 115 #endif // NET_COOKIES_COOKIE_STORE_TEST_CALLBACKS_H_ | 120 #endif // NET_COOKIES_COOKIE_STORE_TEST_CALLBACKS_H_ |
| OLD | NEW |