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

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

Issue 9036003: Avoid useless SYNC_CYCLE_CONTINUATION sync cycle (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 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
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/bind.h" 7 #include "base/bind.h"
8 #include "base/bind_helpers.h" 8 #include "base/bind_helpers.h"
9 #include "base/message_loop.h" 9 #include "base/message_loop.h"
10 #include "base/synchronization/waitable_event.h" 10 #include "base/synchronization/waitable_event.h"
11 #include "base/third_party/dynamic_annotations/dynamic_annotations.h" 11 #include "base/third_party/dynamic_annotations/dynamic_annotations.h"
12 #include "content/public/browser/browser_thread.h" 12 #include "content/public/browser/browser_thread.h"
13 13
14 using content::BrowserThread; 14 using content::BrowserThread;
15 15
16 namespace browser_sync { 16 namespace browser_sync {
17 17
18 namespace { 18 namespace {
19 19
20 void CallDoWorkAndSignalCallback(const WorkCallback& work, 20 void CallDoWorkAndSignalCallback(const WorkCallback& work,
21 base::WaitableEvent* work_done, 21 base::WaitableEvent* work_done,
22 UIModelWorker* const scheduler, 22 UIModelWorker* const scheduler,
23 UnrecoverableErrorInfo* error_info) { 23 SyncerError* error_info) {
24 if (work.is_null()) { 24 if (work.is_null()) {
25 // This can happen during tests or cases where there are more than just the 25 // This can happen during tests or cases where there are more than just the
26 // default UIModelWorker in existence and it gets destroyed before 26 // default UIModelWorker in existence and it gets destroyed before
27 // the main UI loop has terminated. There is no easy way to assert the 27 // the main UI loop has terminated. There is no easy way to assert the
28 // loop is running / not running at the moment, so we just provide cancel 28 // loop is running / not running at the moment, so we just provide cancel
29 // semantics here and short-circuit. 29 // semantics here and short-circuit.
30 // TODO(timsteele): Maybe we should have the message loop destruction 30 // TODO(timsteele): Maybe we should have the message loop destruction
31 // observer fire when the loop has ended, just a bit before it 31 // observer fire when the loop has ended, just a bit before it
32 // actually gets destroyed. 32 // actually gets destroyed.
33 return; 33 return;
34 } 34 }
35 *error_info = work.Run(); 35 *error_info = work.Run();
36 36
37 // Notify the UIModelWorker that scheduled us that we have run 37 // Notify the UIModelWorker that scheduled us that we have run
38 // successfully. 38 // successfully.
39 scheduler->OnTaskCompleted(); 39 scheduler->OnTaskCompleted();
40 work_done->Signal(); // Unblock the syncer thread that scheduled us. 40 work_done->Signal(); // Unblock the syncer thread that scheduled us.
41 } 41 }
42 42
43 } // namespace 43 } // namespace
44 44
45 UnrecoverableErrorInfo UIModelWorker::DoWorkAndWaitUntilDone( 45 SyncerError UIModelWorker::DoWorkAndWaitUntilDone(
46 const WorkCallback& work) { 46 const WorkCallback& work) {
47 // In most cases, this method is called in WORKING state. It is possible this 47 // In most cases, this method is called in WORKING state. It is possible this
48 // gets called when we are in the RUNNING_MANUAL_SHUTDOWN_PUMP state, because 48 // gets called when we are in the RUNNING_MANUAL_SHUTDOWN_PUMP state, because
49 // the UI loop has initiated shutdown but the syncer hasn't got the memo yet. 49 // the UI loop has initiated shutdown but the syncer hasn't got the memo yet.
50 // This is fine, the work will get scheduled and run normally or run by our 50 // This is fine, the work will get scheduled and run normally or run by our
51 // code handling this case in Stop(). Note there _no_ way we can be in here 51 // code handling this case in Stop(). Note there _no_ way we can be in here
52 // with state_ = STOPPED, so it is safe to read / compare in this case. 52 // with state_ = STOPPED, so it is safe to read / compare in this case.
53 CHECK_NE(ANNOTATE_UNPROTECTED_READ(state_), STOPPED); 53 CHECK_NE(ANNOTATE_UNPROTECTED_READ(state_), STOPPED);
54 UnrecoverableErrorInfo error_info; 54 SyncerError error_info;
55 if (BrowserThread::CurrentlyOn(BrowserThread::UI)) { 55 if (BrowserThread::CurrentlyOn(BrowserThread::UI)) {
56 DLOG(WARNING) << "DoWorkAndWaitUntilDone called from " 56 DLOG(WARNING) << "DoWorkAndWaitUntilDone called from "
57 << "ui_loop_. Probably a nested invocation?"; 57 << "ui_loop_. Probably a nested invocation?";
58 return work.Run(); 58 return work.Run();
59 } 59 }
60 60
61 // Create an unsignaled event to wait on. 61 // Create an unsignaled event to wait on.
62 base::WaitableEvent work_done(false, false); 62 base::WaitableEvent work_done(false, false);
63 { 63 {
64 // We lock only to avoid PostTask'ing a NULL pending_work_ (because it 64 // We lock only to avoid PostTask'ing a NULL pending_work_ (because it
65 // could get Run() in Stop() and call OnTaskCompleted before we post). 65 // could get Run() in Stop() and call OnTaskCompleted before we post).
66 // The task is owned by the message loop as per usual. 66 // The task is owned by the message loop as per usual.
67 base::AutoLock lock(lock_); 67 base::AutoLock lock(lock_);
68 DCHECK(pending_work_.is_null()); 68 DCHECK(pending_work_.is_null());
69 UnrecoverableErrorInfo error_info;
70 pending_work_ = base::Bind(&CallDoWorkAndSignalCallback, work, &work_done, 69 pending_work_ = base::Bind(&CallDoWorkAndSignalCallback, work, &work_done,
71 base::Unretained(this), &error_info); 70 base::Unretained(this), &error_info);
72 if (!BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, pending_work_)) { 71 if (!BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, pending_work_)) {
73 LOG(WARNING) << "Could not post work to UI loop."; 72 LOG(WARNING) << "Could not post work to UI loop.";
74 pending_work_.Reset(); 73 pending_work_.Reset();
75 syncapi_event_.Signal(); 74 syncapi_event_.Signal();
76 return error_info; 75 return error_info;
77 } 76 }
78 } 77 }
79 syncapi_event_.Signal(); // Notify that the syncapi produced work for us. 78 syncapi_event_.Signal(); // Notify that the syncapi produced work for us.
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
126 125
127 state_ = STOPPED; 126 state_ = STOPPED;
128 } 127 }
129 128
130 ModelSafeGroup UIModelWorker::GetModelSafeGroup() { 129 ModelSafeGroup UIModelWorker::GetModelSafeGroup() {
131 return GROUP_UI; 130 return GROUP_UI;
132 } 131 }
133 132
134 133
135 } // namespace browser_sync 134 } // namespace browser_sync
OLDNEW
« no previous file with comments | « chrome/browser/sync/glue/ui_model_worker.h ('k') | chrome/browser/sync/glue/ui_model_worker_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698