OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 // Provides a temporary redirection while clients are updated to use the new |
| 6 // path. |
| 7 |
5 #ifndef NET_BASE_COOKIE_STORE_TEST_CALLBACKS_H_ | 8 #ifndef NET_BASE_COOKIE_STORE_TEST_CALLBACKS_H_ |
6 #define NET_BASE_COOKIE_STORE_TEST_CALLBACKS_H_ | 9 #define NET_BASE_COOKIE_STORE_TEST_CALLBACKS_H_ |
7 #pragma once | 10 #pragma once |
8 | 11 |
9 #include <string> | 12 #include "net/cookies/cookie_store_test_callbacks.h" |
10 #include <vector> | |
11 | |
12 #include "net/base/cookie_store.h" | |
13 | |
14 class MessageLoop; | |
15 | |
16 namespace base { | |
17 class Thread; | |
18 } | |
19 | |
20 namespace net { | |
21 | |
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 { | |
26 public: | |
27 // Indicates whether the callback has been called. | |
28 bool did_run() { return did_run_; } | |
29 | |
30 protected: | |
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); | |
34 | |
35 // Constructs a callback that expects to be called in current thread and will | |
36 // send a QUIT to the constructing thread. | |
37 CookieCallback(); | |
38 | |
39 // Tests whether the current thread was the caller's thread. | |
40 // Sends a QUIT to the constructing thread. | |
41 void CallbackEpilogue(); | |
42 | |
43 private: | |
44 bool did_run_; | |
45 base::Thread* run_in_thread_; | |
46 MessageLoop* run_in_loop_; | |
47 MessageLoop* parent_loop_; | |
48 MessageLoop* loop_to_quit_; | |
49 }; | |
50 | |
51 // Callback implementations for the asynchronous CookieStore methods. | |
52 | |
53 class SetCookieCallback : public CookieCallback { | |
54 public: | |
55 SetCookieCallback(); | |
56 explicit SetCookieCallback(base::Thread* run_in_thread); | |
57 | |
58 void Run(bool result) { | |
59 result_ = result; | |
60 CallbackEpilogue(); | |
61 } | |
62 | |
63 bool result() { return result_; } | |
64 | |
65 private: | |
66 bool result_; | |
67 }; | |
68 | |
69 class GetCookieStringCallback : public CookieCallback { | |
70 public: | |
71 GetCookieStringCallback(); | |
72 explicit GetCookieStringCallback(base::Thread* run_in_thread); | |
73 | |
74 void Run(const std::string& cookie) { | |
75 cookie_ = cookie; | |
76 CallbackEpilogue(); | |
77 } | |
78 | |
79 const std::string& cookie() { return cookie_; } | |
80 | |
81 private: | |
82 std::string cookie_; | |
83 }; | |
84 | |
85 class GetCookiesWithInfoCallback : public CookieCallback { | |
86 public: | |
87 GetCookiesWithInfoCallback(); | |
88 explicit GetCookiesWithInfoCallback(base::Thread* run_in_thread); | |
89 ~GetCookiesWithInfoCallback(); | |
90 | |
91 void Run( | |
92 const std::string& cookie_line, | |
93 const std::vector<CookieStore::CookieInfo>& cookie_info) { | |
94 cookie_line_ = cookie_line; | |
95 cookie_info_ = cookie_info; | |
96 CallbackEpilogue(); | |
97 } | |
98 | |
99 const std::string& cookie_line() { return cookie_line_; } | |
100 const std::vector<CookieStore::CookieInfo>& cookie_info() { | |
101 return cookie_info_; | |
102 } | |
103 | |
104 private: | |
105 std::string cookie_line_; | |
106 std::vector<CookieStore::CookieInfo> cookie_info_; | |
107 }; | |
108 | |
109 class DeleteCallback : public CookieCallback { | |
110 public: | |
111 DeleteCallback(); | |
112 explicit DeleteCallback(base::Thread* run_in_thread); | |
113 | |
114 void Run(int num_deleted) { | |
115 num_deleted_ = num_deleted; | |
116 CallbackEpilogue(); | |
117 } | |
118 | |
119 int num_deleted() { return num_deleted_; } | |
120 | |
121 private: | |
122 int num_deleted_; | |
123 }; | |
124 | |
125 class DeleteCookieCallback : public CookieCallback { | |
126 public: | |
127 DeleteCookieCallback(); | |
128 explicit DeleteCookieCallback(base::Thread* run_in_thread); | |
129 | |
130 void Run() { | |
131 CallbackEpilogue(); | |
132 } | |
133 }; | |
134 | |
135 } // namespace net | |
136 | 13 |
137 #endif // NET_BASE_COOKIE_STORE_TEST_CALLBACKS_H_ | 14 #endif // NET_BASE_COOKIE_STORE_TEST_CALLBACKS_H_ |
OLD | NEW |