OLD | NEW |
1 // Copyright (c) 2011 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 #include "components/prefs/pref_member.h" | 5 #include "components/prefs/pref_member.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/location.h" | 8 #include "base/location.h" |
9 #include "base/single_thread_task_runner.h" | 9 #include "base/single_thread_task_runner.h" |
10 #include "base/synchronization/waitable_event.h" | 10 #include "base/synchronization/waitable_event.h" |
(...skipping 28 matching lines...) Expand all Loading... |
39 void Init(const std::string& pref_name, PrefService* prefs) { | 39 void Init(const std::string& pref_name, PrefService* prefs) { |
40 pref_.Init(pref_name, prefs); | 40 pref_.Init(pref_name, prefs); |
41 pref_.MoveToThread(pref_thread_.task_runner()); | 41 pref_.MoveToThread(pref_thread_.task_runner()); |
42 } | 42 } |
43 | 43 |
44 void Destroy() { | 44 void Destroy() { |
45 pref_.Destroy(); | 45 pref_.Destroy(); |
46 } | 46 } |
47 | 47 |
48 void FetchValue() { | 48 void FetchValue() { |
49 base::WaitableEvent event(true, false); | 49 base::WaitableEvent event(base::WaitableEvent::ResetPolicy::MANUAL, |
| 50 base::WaitableEvent::InitialState::NOT_SIGNALED); |
50 ASSERT_TRUE(pref_thread_.task_runner()->PostTask( | 51 ASSERT_TRUE(pref_thread_.task_runner()->PostTask( |
51 FROM_HERE, | 52 FROM_HERE, |
52 base::Bind(&GetPrefValueHelper::GetPrefValue, this, &event))); | 53 base::Bind(&GetPrefValueHelper::GetPrefValue, this, &event))); |
53 event.Wait(); | 54 event.Wait(); |
54 } | 55 } |
55 | 56 |
56 // The thread must be stopped on the main thread. GetPrefValueHelper being | 57 // The thread must be stopped on the main thread. GetPrefValueHelper being |
57 // ref-counted, the destructor can be called from any thread. | 58 // ref-counted, the destructor can be called from any thread. |
58 void StopThread() { | 59 void StopThread() { |
59 pref_thread_.Stop(); | 60 pref_thread_.Stop(); |
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
316 helper->FetchValue(); | 317 helper->FetchValue(); |
317 EXPECT_TRUE(helper->value()); | 318 EXPECT_TRUE(helper->value()); |
318 | 319 |
319 helper->Destroy(); | 320 helper->Destroy(); |
320 | 321 |
321 helper->FetchValue(); | 322 helper->FetchValue(); |
322 EXPECT_TRUE(helper->value()); | 323 EXPECT_TRUE(helper->value()); |
323 | 324 |
324 helper->StopThread(); | 325 helper->StopThread(); |
325 } | 326 } |
OLD | NEW |