Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 #include "net/cookies/cookie_store_test_callbacks.h" | 5 #include "net/cookies/cookie_store_test_callbacks.h" |
| 6 | 6 |
| 7 #include "base/location.h" | 7 #include "base/location.h" |
| 8 #include "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
| 9 #include "base/single_thread_task_runner.h" | 9 #include "base/single_thread_task_runner.h" |
| 10 #include "base/threading/thread.h" | 10 #include "base/threading/thread.h" |
| 11 #include "testing/gtest/include/gtest/gtest.h" | 11 #include "testing/gtest/include/gtest/gtest.h" |
| 12 | 12 |
| 13 namespace net { | 13 namespace net { |
| 14 | 14 |
| 15 CookieCallback::CookieCallback(base::Thread* run_in_thread) | 15 CookieCallback::CookieCallback(base::Thread* run_in_thread) |
| 16 : did_run_(false), | 16 : did_run_(false), |
| 17 run_in_thread_(run_in_thread), | 17 run_in_thread_(run_in_thread), |
| 18 run_in_loop_(NULL), | 18 run_in_loop_(NULL), |
| 19 parent_loop_(base::MessageLoop::current()), | 19 loop_to_quit_(new base::RunLoop) {} |
| 20 loop_to_quit_(base::MessageLoop::current()) {} | |
| 21 | 20 |
| 22 CookieCallback::CookieCallback() | 21 CookieCallback::CookieCallback() |
| 23 : did_run_(false), | 22 : did_run_(false), |
| 24 run_in_thread_(NULL), | 23 run_in_thread_(NULL), |
| 25 run_in_loop_(base::MessageLoop::current()), | 24 run_in_loop_(base::MessageLoop::current()), |
| 26 parent_loop_(NULL), | 25 loop_to_quit_(new base::RunLoop) {} |
|
mmenke
2016/01/27 16:55:42
nit: Can just replace this with:
CookieCallback:
xunjieli
2016/01/27 18:35:02
Hmm.. Not sure if I understand. I don't think I c
mmenke
2016/01/27 18:52:17
No, I'm suggest defining this constructor in terms
xunjieli
2016/01/27 18:54:53
The other constructor takes in a base::Thread, not
mmenke
2016/01/27 21:36:25
Oops...sorry about that.
| |
| 27 loop_to_quit_(base::MessageLoop::current()) {} | 26 |
| 27 CookieCallback::~CookieCallback() {} | |
| 28 | 28 |
| 29 void CookieCallback::CallbackEpilogue() { | 29 void CookieCallback::CallbackEpilogue() { |
| 30 base::MessageLoop* expected_loop = NULL; | 30 base::MessageLoop* expected_loop = NULL; |
| 31 if (run_in_thread_) { | 31 if (run_in_thread_) { |
| 32 DCHECK(!run_in_loop_); | 32 DCHECK(!run_in_loop_); |
| 33 expected_loop = run_in_thread_->message_loop(); | 33 expected_loop = run_in_thread_->message_loop(); |
| 34 } else if (run_in_loop_) { | 34 } else if (run_in_loop_) { |
| 35 expected_loop = run_in_loop_; | 35 expected_loop = run_in_loop_; |
| 36 } | 36 } |
| 37 ASSERT_TRUE(expected_loop != NULL); | 37 ASSERT_TRUE(expected_loop != NULL); |
| 38 | 38 |
| 39 did_run_ = true; | 39 did_run_ = true; |
| 40 EXPECT_EQ(expected_loop, base::MessageLoop::current()); | 40 EXPECT_EQ(expected_loop, base::MessageLoop::current()); |
| 41 loop_to_quit_->task_runner()->PostTask( | 41 loop_to_quit_->Quit(); |
| 42 FROM_HERE, base::MessageLoop::QuitWhenIdleClosure()); | 42 } |
| 43 | |
| 44 void CookieCallback::WaitUntilDone() { | |
| 45 loop_to_quit_->Run(); | |
| 43 } | 46 } |
| 44 | 47 |
| 45 StringResultCookieCallback::StringResultCookieCallback() {} | 48 StringResultCookieCallback::StringResultCookieCallback() {} |
| 46 StringResultCookieCallback::StringResultCookieCallback( | 49 StringResultCookieCallback::StringResultCookieCallback( |
| 47 base::Thread* run_in_thread) | 50 base::Thread* run_in_thread) |
| 48 : CookieCallback(run_in_thread) {} | 51 : CookieCallback(run_in_thread) {} |
| 49 | 52 |
| 50 NoResultCookieCallback::NoResultCookieCallback() {} | 53 NoResultCookieCallback::NoResultCookieCallback() {} |
| 51 NoResultCookieCallback::NoResultCookieCallback(base::Thread* run_in_thread) | 54 NoResultCookieCallback::NoResultCookieCallback(base::Thread* run_in_thread) |
| 52 : CookieCallback(run_in_thread) {} | 55 : CookieCallback(run_in_thread) {} |
| 53 | 56 |
| 54 GetCookieListCallback::GetCookieListCallback() {} | 57 GetCookieListCallback::GetCookieListCallback() {} |
| 55 GetCookieListCallback::GetCookieListCallback(base::Thread* run_in_thread) | 58 GetCookieListCallback::GetCookieListCallback(base::Thread* run_in_thread) |
| 56 : CookieCallback(run_in_thread) {} | 59 : CookieCallback(run_in_thread) {} |
| 57 | 60 |
| 58 GetCookieListCallback::~GetCookieListCallback() {} | 61 GetCookieListCallback::~GetCookieListCallback() {} |
| 59 | 62 |
| 60 void GetCookieListCallback::Run(const CookieList& cookies) { | 63 void GetCookieListCallback::Run(const CookieList& cookies) { |
| 61 cookies_ = cookies; | 64 cookies_ = cookies; |
| 62 CallbackEpilogue(); | 65 CallbackEpilogue(); |
| 63 } | 66 } |
| 64 | 67 |
| 65 } // namespace net | 68 } // namespace net |
| OLD | NEW |