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

Side by Side Diff: chrome/browser/sync/glue/ui_model_worker_unittest.cc

Issue 14046031: Worker changes to prepare for lock-free shutdown. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 8 months 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
OLDNEW
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 "base/bind.h" 5 #include "base/bind.h"
6 #include "base/bind_helpers.h" 6 #include "base/bind_helpers.h"
7 #include "base/callback.h" 7 #include "base/callback.h"
8 #include "base/memory/ref_counted.h" 8 #include "base/memory/ref_counted.h"
9 #include "base/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
10 #include "base/message_loop.h" 10 #include "base/message_loop.h"
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
45 // A faux-syncer that only interacts with its model safe worker. 45 // A faux-syncer that only interacts with its model safe worker.
46 class Syncer { 46 class Syncer {
47 public: 47 public:
48 explicit Syncer(UIModelWorker* worker) : worker_(worker) {} 48 explicit Syncer(UIModelWorker* worker) : worker_(worker) {}
49 ~Syncer() {} 49 ~Syncer() {}
50 50
51 void SyncShare(UIModelWorkerVisitor* visitor) { 51 void SyncShare(UIModelWorkerVisitor* visitor) {
52 // We wait until the callback is executed. So it is safe to use Unretained. 52 // We wait until the callback is executed. So it is safe to use Unretained.
53 syncer::WorkCallback c = base::Bind(&UIModelWorkerVisitor::DoWork, 53 syncer::WorkCallback c = base::Bind(&UIModelWorkerVisitor::DoWork,
54 base::Unretained(visitor)); 54 base::Unretained(visitor));
55 worker_->DoWorkAndWaitUntilDone(c); 55 worker_->HandleWork(c);
56 } 56 }
57 private: 57 private:
58 scoped_refptr<UIModelWorker> worker_; 58 scoped_refptr<UIModelWorker> worker_;
59 DISALLOW_COPY_AND_ASSIGN(Syncer); 59 DISALLOW_COPY_AND_ASSIGN(Syncer);
60 }; 60 };
61 61
62 // A callback run from the CoreThread to simulate terminating syncapi. 62 // A callback run from the CoreThread to simulate terminating syncapi.
63 void FakeSyncapiShutdownCallback(base::Thread* syncer_thread, 63 void FakeSyncapiShutdownCallback(base::Thread* syncer_thread,
64 UIModelWorker* worker, 64 UIModelWorker* worker,
65 base::WaitableEvent** jobs, 65 base::WaitableEvent** jobs,
(...skipping 16 matching lines...) Expand all
82 82
83 class SyncUIModelWorkerTest : public testing::Test { 83 class SyncUIModelWorkerTest : public testing::Test {
84 public: 84 public:
85 SyncUIModelWorkerTest() : faux_syncer_thread_("FauxSyncerThread"), 85 SyncUIModelWorkerTest() : faux_syncer_thread_("FauxSyncerThread"),
86 faux_core_thread_("FauxCoreThread") { } 86 faux_core_thread_("FauxCoreThread") { }
87 87
88 virtual void SetUp() { 88 virtual void SetUp() {
89 faux_syncer_thread_.Start(); 89 faux_syncer_thread_.Start();
90 ui_thread_.reset(new content::TestBrowserThread(BrowserThread::UI, 90 ui_thread_.reset(new content::TestBrowserThread(BrowserThread::UI,
91 &faux_ui_loop_)); 91 &faux_ui_loop_));
92 bmw_ = new UIModelWorker(); 92 bmw_ = new UIModelWorker(NULL);
93 syncer_.reset(new Syncer(bmw_.get())); 93 syncer_.reset(new Syncer(bmw_.get()));
94 } 94 }
95 95
96 Syncer* syncer() { return syncer_.get(); } 96 Syncer* syncer() { return syncer_.get(); }
97 UIModelWorker* bmw() { return bmw_.get(); } 97 UIModelWorker* bmw() { return bmw_.get(); }
98 base::Thread* core_thread() { return &faux_core_thread_; } 98 base::Thread* core_thread() { return &faux_core_thread_; }
99 base::Thread* syncer_thread() { return &faux_syncer_thread_; } 99 base::Thread* syncer_thread() { return &faux_syncer_thread_; }
100 private: 100 private:
101 MessageLoop faux_ui_loop_; 101 MessageLoop faux_ui_loop_;
102 scoped_ptr<content::TestBrowserThread> ui_thread_; 102 scoped_ptr<content::TestBrowserThread> ui_thread_;
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
203 203
204 // This is what gets the UI thread blocked until NotifyExitRequested, 204 // This is what gets the UI thread blocked until NotifyExitRequested,
205 // which is called when FakeSyncapiShutdownCallback runs and deletes the 205 // which is called when FakeSyncapiShutdownCallback runs and deletes the
206 // syncer. 206 // syncer.
207 bmw()->Stop(); 207 bmw()->Stop();
208 208
209 // Was the thread killed? 209 // Was the thread killed?
210 EXPECT_FALSE(syncer_thread()->IsRunning()); 210 EXPECT_FALSE(syncer_thread()->IsRunning());
211 core_thread()->Stop(); 211 core_thread()->Stop();
212 } 212 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698