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

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

Issue 8366030: Introduce the plumbing necessary to report Unrecoverable error from model safe workers. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: For try jobs. Created 9 years, 1 month 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) 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/bind.h"
5 #include "base/callback.h" 6 #include "base/callback.h"
6 #include "base/memory/ref_counted.h" 7 #include "base/memory/ref_counted.h"
7 #include "base/memory/scoped_ptr.h" 8 #include "base/memory/scoped_ptr.h"
8 #include "base/message_loop.h" 9 #include "base/message_loop.h"
9 #include "base/synchronization/waitable_event.h" 10 #include "base/synchronization/waitable_event.h"
10 #include "base/threading/thread.h" 11 #include "base/threading/thread.h"
11 #include "chrome/browser/sync/glue/ui_model_worker.h" 12 #include "chrome/browser/sync/glue/ui_model_worker.h"
13 #include "chrome/browser/sync/util/unrecoverable_error_info.h"
12 #include "content/browser/browser_thread.h" 14 #include "content/browser/browser_thread.h"
13 #include "testing/gtest/include/gtest/gtest.h" 15 #include "testing/gtest/include/gtest/gtest.h"
14 16
15 using browser_sync::UIModelWorker; 17 using browser_sync::UIModelWorker;
18 using browser_sync::UnrecoverableErrorInfo;
16 19
17 // Various boilerplate, primarily for the StopWithPendingWork test. 20 // Various boilerplate, primarily for the StopWithPendingWork test.
18 21
19 class UIModelWorkerVisitor { 22 class UIModelWorkerVisitor {
20 public: 23 public:
21 UIModelWorkerVisitor(base::WaitableEvent* was_run, 24 UIModelWorkerVisitor(base::WaitableEvent* was_run,
22 bool quit_loop) 25 bool quit_loop)
23 : quit_loop_when_run_(quit_loop), 26 : quit_loop_when_run_(quit_loop),
24 was_run_(was_run) { } 27 was_run_(was_run) { }
25 virtual ~UIModelWorkerVisitor() { } 28 virtual ~UIModelWorkerVisitor() { }
26 29
27 virtual void DoWork() { 30 virtual UnrecoverableErrorInfo DoWork() {
28 EXPECT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::UI)); 31 EXPECT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::UI));
29 was_run_->Signal(); 32 was_run_->Signal();
30 if (quit_loop_when_run_) 33 if (quit_loop_when_run_)
31 MessageLoop::current()->Quit(); 34 MessageLoop::current()->Quit();
35 return UnrecoverableErrorInfo();
32 } 36 }
33 37
34 private: 38 private:
35 bool quit_loop_when_run_; 39 bool quit_loop_when_run_;
36 base::WaitableEvent* was_run_; 40 base::WaitableEvent* was_run_;
37 DISALLOW_COPY_AND_ASSIGN(UIModelWorkerVisitor); 41 DISALLOW_COPY_AND_ASSIGN(UIModelWorkerVisitor);
38 }; 42 };
39 43
40 // A faux-syncer that only interacts with its model safe worker. 44 // A faux-syncer that only interacts with its model safe worker.
41 class Syncer { 45 class Syncer {
42 public: 46 public:
43 explicit Syncer(UIModelWorker* worker) : worker_(worker) {} 47 explicit Syncer(UIModelWorker* worker) : worker_(worker) {}
44 ~Syncer() {} 48 ~Syncer() {}
45 49
46 void SyncShare(UIModelWorkerVisitor* visitor) { 50 void SyncShare(UIModelWorkerVisitor* visitor) {
47 scoped_ptr<Callback0::Type> c(NewCallback(visitor, 51 // We wait until the callback is executed. So it is safe to use Unretained.
48 &UIModelWorkerVisitor::DoWork)); 52 browser_sync::WorkCallback c = base::Bind(&UIModelWorkerVisitor::DoWork,
49 worker_->DoWorkAndWaitUntilDone(c.get()); 53 base::Unretained(visitor));
54 worker_->DoWorkAndWaitUntilDone(c);
50 } 55 }
51 private: 56 private:
52 scoped_refptr<UIModelWorker> worker_; 57 scoped_refptr<UIModelWorker> worker_;
53 DISALLOW_COPY_AND_ASSIGN(Syncer); 58 DISALLOW_COPY_AND_ASSIGN(Syncer);
54 }; 59 };
55 60
56 // A task run from the SyncerThread to "sync share", ie tell the Syncer to 61 // A task run from the SyncerThread to "sync share", ie tell the Syncer to
57 // ask its ModelSafeWorker to do something. 62 // ask its ModelSafeWorker to do something.
58 class FakeSyncShareTask : public Task { 63 class FakeSyncShareTask : public Task {
59 public: 64 public:
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
217 new FakeSyncShareTask(syncer(), fox3.get())); 222 new FakeSyncShareTask(syncer(), fox3.get()));
218 223
219 // This is what gets the UI thread blocked until NotifyExitRequested, 224 // This is what gets the UI thread blocked until NotifyExitRequested,
220 // which is called when FakeSyncapiShutdownTask runs and deletes the syncer. 225 // which is called when FakeSyncapiShutdownTask runs and deletes the syncer.
221 bmw()->Stop(); 226 bmw()->Stop();
222 227
223 // Was the thread killed? 228 // Was the thread killed?
224 EXPECT_FALSE(syncer_thread()->IsRunning()); 229 EXPECT_FALSE(syncer_thread()->IsRunning());
225 core_thread()->Stop(); 230 core_thread()->Stop();
226 } 231 }
OLDNEW
« no previous file with comments | « chrome/browser/sync/glue/ui_model_worker.cc ('k') | chrome/browser/sync/util/unrecoverable_error_info.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698