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
3 // found in the LICENSE file.
5 #ifndef NET_COOKIES_COOKIE_STORE_TEST_CALLBACKS_H_
6 #define NET_COOKIES_COOKIE_STORE_TEST_CALLBACKS_H_
12 #include "net/cookies/cookie_store.h"
22 // Defines common behaviour for the callbacks from GetCookies, SetCookies, etc.
23 // Asserts that the current thread is the expected invocation thread, sends a
24 // quit to the thread in which it was constructed.
25 class CookieCallback
{
27 // Indicates whether the callback has been called.
28 bool did_run() { return did_run_
; }
31 // Constructs a callback that expects to be called in the given thread and
32 // will, upon execution, send a QUIT to the constructing thread.
33 explicit CookieCallback(base::Thread
* run_in_thread
);
35 // Constructs a callback that expects to be called in current thread and will
36 // send a QUIT to the constructing thread.
39 // Tests whether the current thread was the caller's thread.
40 // Sends a QUIT to the constructing thread.
41 void CallbackEpilogue();
45 base::Thread
* run_in_thread_
;
46 MessageLoop
* run_in_loop_
;
47 MessageLoop
* parent_loop_
;
48 MessageLoop
* loop_to_quit_
;
51 // Callback implementations for the asynchronous CookieStore methods.
53 class SetCookieCallback
: public CookieCallback
{
56 explicit SetCookieCallback(base::Thread
* run_in_thread
);
58 void Run(bool result
) {
63 bool result() { return result_
; }
69 class GetCookieStringCallback
: public CookieCallback
{
71 GetCookieStringCallback();
72 explicit GetCookieStringCallback(base::Thread
* run_in_thread
);
74 void Run(const std::string
& cookie
) {
79 const std::string
& cookie() { return cookie_
; }
85 class GetCookiesWithInfoCallback
: public CookieCallback
{
87 GetCookiesWithInfoCallback();
88 explicit GetCookiesWithInfoCallback(base::Thread
* run_in_thread
);
89 ~GetCookiesWithInfoCallback();
92 const std::string
& cookie_line
,
93 const std::vector
<CookieStore::CookieInfo
>& cookie_info
) {
94 cookie_line_
= cookie_line
;
95 cookie_info_
= cookie_info
;
99 const std::string
& cookie_line() { return cookie_line_
; }
100 const std::vector
<CookieStore::CookieInfo
>& cookie_info() {
105 std::string cookie_line_
;
106 std::vector
<CookieStore::CookieInfo
> cookie_info_
;
109 class DeleteCallback
: public CookieCallback
{
112 explicit DeleteCallback(base::Thread
* run_in_thread
);
114 void Run(int num_deleted
) {
115 num_deleted_
= num_deleted
;
119 int num_deleted() { return num_deleted_
; }
125 class DeleteCookieCallback
: public CookieCallback
{
127 DeleteCookieCallback();
128 explicit DeleteCookieCallback(base::Thread
* run_in_thread
);
137 #endif // NET_COOKIES_COOKIE_STORE_TEST_CALLBACKS_H_