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

Side by Side Diff: chrome/browser/sync/glue/ui_model_worker.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 review. Created 9 years, 2 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) 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 "chrome/browser/sync/glue/ui_model_worker.h" 5 #include "chrome/browser/sync/glue/ui_model_worker.h"
6 6
7 #include "base/message_loop.h" 7 #include "base/message_loop.h"
8 #include "base/third_party/dynamic_annotations/dynamic_annotations.h" 8 #include "base/third_party/dynamic_annotations/dynamic_annotations.h"
9 #include "base/synchronization/waitable_event.h" 9 #include "base/synchronization/waitable_event.h"
10 #include "content/browser/browser_thread.h" 10 #include "content/browser/browser_thread.h"
11 11
12 namespace browser_sync { 12 namespace browser_sync {
13 using sessions::UnrecoverableErrorInfo;
13 14
14 void UIModelWorker::DoWorkAndWaitUntilDone(Callback0::Type* work) { 15 UnrecoverableErrorInfo UIModelWorker::DoWorkAndWaitUntilDone(
16 Callback1<sessions::UnrecoverableErrorInfo*>::Type* work) {
15 // In most cases, this method is called in WORKING state. It is possible this 17 // In most cases, this method is called in WORKING state. It is possible this
16 // gets called when we are in the RUNNING_MANUAL_SHUTDOWN_PUMP state, because 18 // gets called when we are in the RUNNING_MANUAL_SHUTDOWN_PUMP state, because
17 // the UI loop has initiated shutdown but the syncer hasn't got the memo yet. 19 // the UI loop has initiated shutdown but the syncer hasn't got the memo yet.
18 // This is fine, the work will get scheduled and run normally or run by our 20 // This is fine, the work will get scheduled and run normally or run by our
19 // code handling this case in Stop(). Note there _no_ way we can be in here 21 // code handling this case in Stop(). Note there _no_ way we can be in here
20 // with state_ = STOPPED, so it is safe to read / compare in this case. 22 // with state_ = STOPPED, so it is safe to read / compare in this case.
21 CHECK_NE(ANNOTATE_UNPROTECTED_READ(state_), STOPPED); 23 CHECK_NE(ANNOTATE_UNPROTECTED_READ(state_), STOPPED);
22 24 UnrecoverableErrorInfo error_info;
23 if (BrowserThread::CurrentlyOn(BrowserThread::UI)) { 25 if (BrowserThread::CurrentlyOn(BrowserThread::UI)) {
24 DLOG(WARNING) << "DoWorkAndWaitUntilDone called from " 26 DLOG(WARNING) << "DoWorkAndWaitUntilDone called from "
25 << "ui_loop_. Probably a nested invocation?"; 27 << "ui_loop_. Probably a nested invocation?";
26 work->Run(); 28 work->Run(&error_info);
27 return; 29 return error_info;
28 } 30 }
29 31
30 // Create an unsignaled event to wait on. 32 // Create an unsignaled event to wait on.
31 base::WaitableEvent work_done(false, false); 33 base::WaitableEvent work_done(false, false);
32 { 34 {
33 // We lock only to avoid PostTask'ing a NULL pending_work_ (because it 35 // We lock only to avoid PostTask'ing a NULL pending_work_ (because it
34 // could get Run() in Stop() and call OnTaskCompleted before we post). 36 // could get Run() in Stop() and call OnTaskCompleted before we post).
35 // The task is owned by the message loop as per usual. 37 // The task is owned by the message loop as per usual.
36 base::AutoLock lock(lock_); 38 base::AutoLock lock(lock_);
37 DCHECK(!pending_work_); 39 DCHECK(!pending_work_);
38 pending_work_ = new CallDoWorkAndSignalTask(work, &work_done, this); 40 UnrecoverableErrorInfo error_info;
41 pending_work_ = new CallDoWorkAndSignalTask(work, &work_done, this,
42 &error_info);
39 if (!BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, pending_work_)) { 43 if (!BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, pending_work_)) {
40 LOG(WARNING) << "Could not post work to UI loop."; 44 LOG(WARNING) << "Could not post work to UI loop.";
41 pending_work_ = NULL; 45 pending_work_ = NULL;
42 syncapi_event_.Signal(); 46 syncapi_event_.Signal();
43 return; 47 return error_info;
44 } 48 }
45 } 49 }
46 syncapi_event_.Signal(); // Notify that the syncapi produced work for us. 50 syncapi_event_.Signal(); // Notify that the syncapi produced work for us.
47 work_done.Wait(); 51 work_done.Wait();
52 return error_info;
48 } 53 }
49 54
50 UIModelWorker::UIModelWorker() 55 UIModelWorker::UIModelWorker()
51 : state_(WORKING), 56 : state_(WORKING),
52 pending_work_(NULL), 57 pending_work_(NULL),
53 syncapi_has_shutdown_(false), 58 syncapi_has_shutdown_(false),
54 syncapi_event_(&lock_) { 59 syncapi_event_(&lock_) {
55 } 60 }
56 61
57 UIModelWorker::~UIModelWorker() { 62 UIModelWorker::~UIModelWorker() {
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
103 // This can happen during tests or cases where there are more than just the 108 // This can happen during tests or cases where there are more than just the
104 // default UIModelWorker in existence and it gets destroyed before 109 // default UIModelWorker in existence and it gets destroyed before
105 // the main UI loop has terminated. There is no easy way to assert the 110 // the main UI loop has terminated. There is no easy way to assert the
106 // loop is running / not running at the moment, so we just provide cancel 111 // loop is running / not running at the moment, so we just provide cancel
107 // semantics here and short-circuit. 112 // semantics here and short-circuit.
108 // TODO(timsteele): Maybe we should have the message loop destruction 113 // TODO(timsteele): Maybe we should have the message loop destruction
109 // observer fire when the loop has ended, just a bit before it 114 // observer fire when the loop has ended, just a bit before it
110 // actually gets destroyed. 115 // actually gets destroyed.
111 return; 116 return;
112 } 117 }
113 work_->Run(); 118 work_->Run(error_info_);
114 119
115 // Sever ties with work_ to allow the sanity-checking above that we don't 120 // Sever ties with work_ to allow the sanity-checking above that we don't
116 // get run twice. 121 // get run twice.
117 work_ = NULL; 122 work_ = NULL;
118 123
119 // Notify the UIModelWorker that scheduled us that we have run 124 // Notify the UIModelWorker that scheduled us that we have run
120 // successfully. 125 // successfully.
121 scheduler_->OnTaskCompleted(); 126 scheduler_->OnTaskCompleted();
122 work_done_->Signal(); // Unblock the syncer thread that scheduled us. 127 work_done_->Signal(); // Unblock the syncer thread that scheduled us.
123 } 128 }
124 129
125 } // namespace browser_sync 130 } // namespace browser_sync
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698