[email protected] | b0d7aa36 | 2012-02-03 18:19:15 | [diff] [blame] | 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. | ||||
4 | |||||
[email protected] | 63ee33bd | 2012-03-15 09:29:58 | [diff] [blame] | 5 | #include "net/cookies/cookie_store_test_callbacks.h" |
[email protected] | b0d7aa36 | 2012-02-03 18:19:15 | [diff] [blame] | 6 | |
skyostil | 4891b25b | 2015-06-11 11:43:45 | [diff] [blame] | 7 | #include "base/location.h" |
Alexander Timin | 4f9c35c | 2018-11-01 20:15:20 | [diff] [blame] | 8 | #include "base/message_loop/message_loop.h" |
skyostil | 4891b25b | 2015-06-11 11:43:45 | [diff] [blame] | 9 | #include "base/single_thread_task_runner.h" |
[email protected] | b0d7aa36 | 2012-02-03 18:19:15 | [diff] [blame] | 10 | #include "base/threading/thread.h" |
Alexander Timin | 0439ffe | 2018-10-30 18:10:00 | [diff] [blame] | 11 | #include "base/threading/thread_task_runner_handle.h" |
[email protected] | b0d7aa36 | 2012-02-03 18:19:15 | [diff] [blame] | 12 | #include "testing/gtest/include/gtest/gtest.h" |
13 | |||||
14 | namespace net { | ||||
15 | |||||
16 | CookieCallback::CookieCallback(base::Thread* run_in_thread) | ||||
Alexander Timin | 0439ffe | 2018-10-30 18:10:00 | [diff] [blame] | 17 | : run_in_thread_(run_in_thread) {} |
[email protected] | b0d7aa36 | 2012-02-03 18:19:15 | [diff] [blame] | 18 | |
19 | CookieCallback::CookieCallback() | ||||
Alexander Timin | 0439ffe | 2018-10-30 18:10:00 | [diff] [blame] | 20 | : run_in_thread_(NULL), |
21 | run_in_task_runner_(base::ThreadTaskRunnerHandle::Get()) {} | ||||
xunjieli | b2bec81 | 2016-01-27 23:08:09 | [diff] [blame] | 22 | |
Chris Watkins | 68b1503 | 2017-12-01 03:07:13 | [diff] [blame] | 23 | CookieCallback::~CookieCallback() = default; |
[email protected] | b0d7aa36 | 2012-02-03 18:19:15 | [diff] [blame] | 24 | |
25 | void CookieCallback::CallbackEpilogue() { | ||||
Alexander Timin | 0439ffe | 2018-10-30 18:10:00 | [diff] [blame] | 26 | scoped_refptr<base::SingleThreadTaskRunner> expected_task_runner; |
[email protected] | b0d7aa36 | 2012-02-03 18:19:15 | [diff] [blame] | 27 | if (run_in_thread_) { |
Alexander Timin | 0439ffe | 2018-10-30 18:10:00 | [diff] [blame] | 28 | DCHECK(!run_in_task_runner_); |
29 | expected_task_runner = run_in_thread_->task_runner(); | ||||
30 | } else if (run_in_task_runner_) { | ||||
31 | expected_task_runner = run_in_task_runner_; | ||||
[email protected] | b0d7aa36 | 2012-02-03 18:19:15 | [diff] [blame] | 32 | } |
Alexander Timin | 0439ffe | 2018-10-30 18:10:00 | [diff] [blame] | 33 | ASSERT_TRUE(expected_task_runner); |
[email protected] | b0d7aa36 | 2012-02-03 18:19:15 | [diff] [blame] | 34 | |
Alexander Timin | 0439ffe | 2018-10-30 18:10:00 | [diff] [blame] | 35 | EXPECT_TRUE(expected_task_runner->BelongsToCurrentThread()); |
xunjieli | b2bec81 | 2016-01-27 23:08:09 | [diff] [blame] | 36 | loop_to_quit_.Quit(); |
37 | } | ||||
38 | |||||
39 | void CookieCallback::WaitUntilDone() { | ||||
40 | loop_to_quit_.Run(); | ||||
[email protected] | b0d7aa36 | 2012-02-03 18:19:15 | [diff] [blame] | 41 | } |
42 | |||||
Chris Watkins | 68b1503 | 2017-12-01 03:07:13 | [diff] [blame] | 43 | NoResultCookieCallback::NoResultCookieCallback() = default; |
[email protected] | f6c58823 | 2013-05-22 12:43:40 | [diff] [blame] | 44 | NoResultCookieCallback::NoResultCookieCallback(base::Thread* run_in_thread) |
[email protected] | b0d7aa36 | 2012-02-03 18:19:15 | [diff] [blame] | 45 | : CookieCallback(run_in_thread) {} |
46 | |||||
Chris Watkins | 68b1503 | 2017-12-01 03:07:13 | [diff] [blame] | 47 | GetCookieListCallback::GetCookieListCallback() = default; |
mmenke | 9fa44f2d | 2016-01-22 23:36:39 | [diff] [blame] | 48 | GetCookieListCallback::GetCookieListCallback(base::Thread* run_in_thread) |
49 | : CookieCallback(run_in_thread) {} | ||||
50 | |||||
Chris Watkins | 68b1503 | 2017-12-01 03:07:13 | [diff] [blame] | 51 | GetCookieListCallback::~GetCookieListCallback() = default; |
mmenke | 9fa44f2d | 2016-01-22 23:36:39 | [diff] [blame] | 52 | |
Aaron Tagliaboschi | a4c64b5 | 2019-01-25 03:28:49 | [diff] [blame] | 53 | void GetCookieListCallback::Run(const CookieList& cookies, |
54 | const CookieStatusList& excluded_cookies) { | ||||
mmenke | 9fa44f2d | 2016-01-22 23:36:39 | [diff] [blame] | 55 | cookies_ = cookies; |
Aaron Tagliaboschi | 29033b7f | 2019-01-31 19:58:20 | [diff] [blame^] | 56 | excluded_cookies_ = excluded_cookies; |
mmenke | 9fa44f2d | 2016-01-22 23:36:39 | [diff] [blame] | 57 | CallbackEpilogue(); |
58 | } | ||||
59 | |||||
[email protected] | b0d7aa36 | 2012-02-03 18:19:15 | [diff] [blame] | 60 | } // namespace net |