Speech refactoring: Reimplemented SpeechRecognitionManagerImpl as a FSM. (CL1.7)
[chromium-blink-merge.git] / net / cookies / cookie_store_test_callbacks.h
blobd201d3264369b469b4cb945af3f75c031c2c40f5
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_
7 #pragma once
9 #include <string>
10 #include <vector>
12 #include "net/cookies/cookie_store.h"
14 class MessageLoop;
16 namespace base {
17 class Thread;
20 namespace net {
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_; }
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);
35 // Constructs a callback that expects to be called in current thread and will
36 // send a QUIT to the constructing thread.
37 CookieCallback();
39 // Tests whether the current thread was the caller's thread.
40 // Sends a QUIT to the constructing thread.
41 void CallbackEpilogue();
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_;
51 // Callback implementations for the asynchronous CookieStore methods.
53 class SetCookieCallback : public CookieCallback {
54 public:
55 SetCookieCallback();
56 explicit SetCookieCallback(base::Thread* run_in_thread);
58 void Run(bool result) {
59 result_ = result;
60 CallbackEpilogue();
63 bool result() { return result_; }
65 private:
66 bool result_;
69 class GetCookieStringCallback : public CookieCallback {
70 public:
71 GetCookieStringCallback();
72 explicit GetCookieStringCallback(base::Thread* run_in_thread);
74 void Run(const std::string& cookie) {
75 cookie_ = cookie;
76 CallbackEpilogue();
79 const std::string& cookie() { return cookie_; }
81 private:
82 std::string cookie_;
85 class GetCookiesWithInfoCallback : public CookieCallback {
86 public:
87 GetCookiesWithInfoCallback();
88 explicit GetCookiesWithInfoCallback(base::Thread* run_in_thread);
89 ~GetCookiesWithInfoCallback();
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();
99 const std::string& cookie_line() { return cookie_line_; }
100 const std::vector<CookieStore::CookieInfo>& cookie_info() {
101 return cookie_info_;
104 private:
105 std::string cookie_line_;
106 std::vector<CookieStore::CookieInfo> cookie_info_;
109 class DeleteCallback : public CookieCallback {
110 public:
111 DeleteCallback();
112 explicit DeleteCallback(base::Thread* run_in_thread);
114 void Run(int num_deleted) {
115 num_deleted_ = num_deleted;
116 CallbackEpilogue();
119 int num_deleted() { return num_deleted_; }
121 private:
122 int num_deleted_;
125 class DeleteCookieCallback : public CookieCallback {
126 public:
127 DeleteCookieCallback();
128 explicit DeleteCookieCallback(base::Thread* run_in_thread);
130 void Run() {
131 CallbackEpilogue();
135 } // namespace net
137 #endif // NET_COOKIES_COOKIE_STORE_TEST_CALLBACKS_H_