Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(300)

Side by Side Diff: base/prefs/public/pref_member_unittest.cc

Issue 11624023: Fix flakyness in PrefMemberTest::MoveToThread (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "base/prefs/public/pref_member.h" 5 #include "base/prefs/public/pref_member.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/message_loop.h" 8 #include "base/message_loop.h"
9 #include "base/synchronization/waitable_event.h" 9 #include "base/synchronization/waitable_event.h"
10 #include "base/threading/thread.h" 10 #include "base/threading/thread.h"
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
49 49
50 void FetchValue() { 50 void FetchValue() {
51 base::WaitableEvent event(true, false); 51 base::WaitableEvent event(true, false);
52 ASSERT_TRUE( 52 ASSERT_TRUE(
53 pref_thread_.message_loop_proxy()->PostTask( 53 pref_thread_.message_loop_proxy()->PostTask(
54 FROM_HERE, 54 FROM_HERE,
55 base::Bind(&GetPrefValueHelper::GetPrefValue, this, &event))); 55 base::Bind(&GetPrefValueHelper::GetPrefValue, this, &event)));
56 event.Wait(); 56 event.Wait();
57 } 57 }
58 58
59 // The thread must be stopped on the main thread. GetPrefValueHelper being
60 // ref-counted, the destructor can be called from any thread.
61 void StopThread() {
62 pref_thread_.Stop();
63 }
64
59 bool value() { return value_; } 65 bool value() { return value_; }
60 66
61 private: 67 private:
62 friend class base::RefCountedThreadSafe<GetPrefValueHelper>; 68 friend class base::RefCountedThreadSafe<GetPrefValueHelper>;
63 ~GetPrefValueHelper() {} 69 ~GetPrefValueHelper() {}
64 70
65 void GetPrefValue(base::WaitableEvent* event) { 71 void GetPrefValue(base::WaitableEvent* event) {
66 value_ = pref_.GetValue(); 72 value_ = pref_.GetValue();
67 event->Signal(); 73 event->Signal();
68 } 74 }
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after
306 312
307 prefs.SetBoolean(kBoolPref, true); 313 prefs.SetBoolean(kBoolPref, true);
308 314
309 helper->FetchValue(); 315 helper->FetchValue();
310 EXPECT_TRUE(helper->value()); 316 EXPECT_TRUE(helper->value());
311 317
312 helper->Destroy(); 318 helper->Destroy();
313 319
314 helper->FetchValue(); 320 helper->FetchValue();
315 EXPECT_TRUE(helper->value()); 321 EXPECT_TRUE(helper->value());
322
323 helper->StopThread();
316 } 324 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698