Disable input view by default.
[chromium-blink-merge.git] / net / cookies / cookie_store_test_callbacks.h
blobc8308e1bc391089020651f0191e08bcca3cb91e1
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_
8 #include <string>
9 #include <vector>
11 #include "net/cookies/cookie_store.h"
13 namespace base {
14 class MessageLoop;
15 class Thread;
18 namespace net {
20 // Defines common behaviour for the callbacks from GetCookies, SetCookies, etc.
21 // Asserts that the current thread is the expected invocation thread, sends a
22 // quit to the thread in which it was constructed.
23 class CookieCallback {
24 public:
25 // Indicates whether the callback has been called.
26 bool did_run() { return did_run_; }
28 protected:
29 // Constructs a callback that expects to be called in the given thread and
30 // will, upon execution, send a QUIT to the constructing thread.
31 explicit CookieCallback(base::Thread* run_in_thread);
33 // Constructs a callback that expects to be called in current thread and will
34 // send a QUIT to the constructing thread.
35 CookieCallback();
37 // Tests whether the current thread was the caller's thread.
38 // Sends a QUIT to the constructing thread.
39 void CallbackEpilogue();
41 private:
42 bool did_run_;
43 base::Thread* run_in_thread_;
44 base::MessageLoop* run_in_loop_;
45 base::MessageLoop* parent_loop_;
46 base::MessageLoop* loop_to_quit_;
49 // Callback implementations for the asynchronous CookieStore methods.
51 class BoolResultCookieCallback : public CookieCallback {
52 public:
53 BoolResultCookieCallback();
54 explicit BoolResultCookieCallback(base::Thread* run_in_thread);
56 void Run(bool result) {
57 result_ = result;
58 CallbackEpilogue();
61 bool result() { return result_; }
63 private:
64 bool result_;
67 class StringResultCookieCallback : public CookieCallback {
68 public:
69 StringResultCookieCallback();
70 explicit StringResultCookieCallback(base::Thread* run_in_thread);
72 void Run(const std::string& result) {
73 result_ = result;
74 CallbackEpilogue();
77 const std::string& result() { return result_; }
79 private:
80 std::string result_;
83 class IntResultCookieCallback : public CookieCallback {
84 public:
85 IntResultCookieCallback();
86 explicit IntResultCookieCallback(base::Thread* run_in_thread);
88 void Run(int result) {
89 result_ = result;
90 CallbackEpilogue();
93 int result() { return result_; }
95 private:
96 int result_;
99 class NoResultCookieCallback : public CookieCallback {
100 public:
101 NoResultCookieCallback();
102 explicit NoResultCookieCallback(base::Thread* run_in_thread);
104 void Run() {
105 CallbackEpilogue();
109 } // namespace net
111 #endif // NET_COOKIES_COOKIE_STORE_TEST_CALLBACKS_H_