| OLD | NEW |
| 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 #ifndef CHROME_BROWSER_SYNC_GLUE_UI_MODEL_WORKER_H_ | 5 #ifndef CHROME_BROWSER_SYNC_GLUE_UI_MODEL_WORKER_H_ |
| 6 #define CHROME_BROWSER_SYNC_GLUE_UI_MODEL_WORKER_H_ | 6 #define CHROME_BROWSER_SYNC_GLUE_UI_MODEL_WORKER_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include "base/callback.h" | 9 #include "base/callback.h" |
| 10 #include "base/synchronization/condition_variable.h" | 10 #include "base/synchronization/condition_variable.h" |
| 11 #include "base/synchronization/lock.h" | 11 #include "base/synchronization/lock.h" |
| 12 #include "base/task.h" | 12 #include "base/task.h" |
| 13 #include "chrome/browser/sync/engine/model_safe_worker.h" | 13 #include "chrome/browser/sync/engine/model_safe_worker.h" |
| 14 #include "chrome/browser/sync/sessions/unrecoverable_error_info.h" |
| 14 | 15 |
| 15 namespace base { | 16 namespace base { |
| 16 class WaitableEvent; | 17 class WaitableEvent; |
| 17 } | 18 } |
| 18 | 19 |
| 19 class MessageLoop; | 20 class MessageLoop; |
| 20 | 21 |
| 21 namespace browser_sync { | 22 namespace browser_sync { |
| 22 | 23 |
| 23 // A ModelSafeWorker for UI models (e.g. bookmarks) that accepts work requests | 24 // A ModelSafeWorker for UI models (e.g. bookmarks) that accepts work requests |
| 24 // from the syncapi that need to be fulfilled from the MessageLoop home to the | 25 // from the syncapi that need to be fulfilled from the MessageLoop home to the |
| 25 // native model. | 26 // native model. |
| 26 // | 27 // |
| 27 // Lifetime note: Instances of this class will generally be owned by the | 28 // Lifetime note: Instances of this class will generally be owned by the |
| 28 // SyncerThread. When the SyncerThread _object_ is destroyed, the | 29 // SyncerThread. When the SyncerThread _object_ is destroyed, the |
| 29 // UIModelWorker will be destroyed. The SyncerThread object is destroyed | 30 // UIModelWorker will be destroyed. The SyncerThread object is destroyed |
| 30 // after the actual syncer pthread has exited. | 31 // after the actual syncer pthread has exited. |
| 31 class UIModelWorker : public browser_sync::ModelSafeWorker { | 32 class UIModelWorker : public browser_sync::ModelSafeWorker { |
| 32 public: | 33 public: |
| 33 UIModelWorker(); | 34 UIModelWorker(); |
| 34 virtual ~UIModelWorker(); | 35 virtual ~UIModelWorker(); |
| 35 | 36 |
| 36 // A simple task to signal a waitable event after Run()ning a Closure. | 37 // A simple task to signal a waitable event after Run()ning a Closure. |
| 37 class CallDoWorkAndSignalTask : public Task { | 38 class CallDoWorkAndSignalTask : public Task { |
| 38 public: | 39 public: |
| 39 CallDoWorkAndSignalTask(Callback0::Type* work, | 40 CallDoWorkAndSignalTask( |
| 40 base::WaitableEvent* work_done, | 41 Callback1<sessions::UnrecoverableErrorInfo*>::Type* work, |
| 41 UIModelWorker* scheduler) | 42 base::WaitableEvent* work_done, |
| 42 : work_(work), work_done_(work_done), scheduler_(scheduler) { | 43 UIModelWorker* scheduler, |
| 44 sessions::UnrecoverableErrorInfo* error_info) |
| 45 : work_(work), work_done_(work_done), scheduler_(scheduler), |
| 46 error_info_(error_info) { |
| 43 } | 47 } |
| 44 virtual ~CallDoWorkAndSignalTask() { } | 48 virtual ~CallDoWorkAndSignalTask() { } |
| 45 | 49 |
| 46 // Task implementation. | 50 // Task implementation. |
| 47 virtual void Run(); | 51 virtual void Run(); |
| 48 | 52 |
| 49 private: | 53 private: |
| 50 // Task data - a closure and a waitable event to signal after the work has | 54 // Task data - a closure and a waitable event to signal after the work has |
| 51 // been done. | 55 // been done. |
| 52 Callback0::Type* work_; | 56 Callback1<sessions::UnrecoverableErrorInfo*>::Type* work_; |
| 53 base::WaitableEvent* work_done_; | 57 base::WaitableEvent* work_done_; |
| 54 | 58 |
| 55 // The UIModelWorker responsible for scheduling us. | 59 // The UIModelWorker responsible for scheduling us. |
| 56 UIModelWorker* const scheduler_; | 60 UIModelWorker* const scheduler_; |
| 57 | 61 |
| 62 sessions::UnrecoverableErrorInfo* error_info_; |
| 63 |
| 58 DISALLOW_COPY_AND_ASSIGN(CallDoWorkAndSignalTask); | 64 DISALLOW_COPY_AND_ASSIGN(CallDoWorkAndSignalTask); |
| 59 }; | 65 }; |
| 60 | 66 |
| 61 // Called by the UI thread on shutdown of the sync service. Blocks until | 67 // Called by the UI thread on shutdown of the sync service. Blocks until |
| 62 // the UIModelWorker has safely met termination conditions, namely that | 68 // the UIModelWorker has safely met termination conditions, namely that |
| 63 // no task scheduled by CallDoWorkFromModelSafeThreadAndWait remains un- | 69 // no task scheduled by CallDoWorkFromModelSafeThreadAndWait remains un- |
| 64 // processed and that syncapi will not schedule any further work for us to do. | 70 // processed and that syncapi will not schedule any further work for us to do. |
| 65 void Stop(); | 71 void Stop(); |
| 66 | 72 |
| 67 // ModelSafeWorker implementation. Called on syncapi SyncerThread. | 73 // ModelSafeWorker implementation. Called on syncapi SyncerThread. |
| 68 virtual void DoWorkAndWaitUntilDone(Callback0::Type* work); | 74 virtual sessions::UnrecoverableErrorInfo DoWorkAndWaitUntilDone( |
| 75 Callback1<sessions::UnrecoverableErrorInfo*>::Type* work) OVERRIDE; |
| 69 virtual ModelSafeGroup GetModelSafeGroup(); | 76 virtual ModelSafeGroup GetModelSafeGroup(); |
| 70 | 77 |
| 71 // Upon receiving this idempotent call, the ModelSafeWorker can | 78 // Upon receiving this idempotent call, the ModelSafeWorker can |
| 72 // assume no work will ever be scheduled again from now on. If it has any work | 79 // assume no work will ever be scheduled again from now on. If it has any work |
| 73 // that it has not yet completed, it must make sure to run it as soon as | 80 // that it has not yet completed, it must make sure to run it as soon as |
| 74 // possible as the Syncer is trying to shut down. Called from the CoreThread. | 81 // possible as the Syncer is trying to shut down. Called from the CoreThread. |
| 75 void OnSyncerShutdownComplete(); | 82 void OnSyncerShutdownComplete(); |
| 76 | 83 |
| 77 // Callback from |pending_work_| to notify us that it has been run. | 84 // Callback from |pending_work_| to notify us that it has been run. |
| 78 // Called on ui loop. | 85 // Called on ui loop. |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 122 // SyncerThread has terminated. We only care about (1) when we are in Stop(), | 129 // SyncerThread has terminated. We only care about (1) when we are in Stop(), |
| 123 // because we have to manually Run() the task. | 130 // because we have to manually Run() the task. |
| 124 base::ConditionVariable syncapi_event_; | 131 base::ConditionVariable syncapi_event_; |
| 125 | 132 |
| 126 DISALLOW_COPY_AND_ASSIGN(UIModelWorker); | 133 DISALLOW_COPY_AND_ASSIGN(UIModelWorker); |
| 127 }; | 134 }; |
| 128 | 135 |
| 129 } // namespace browser_sync | 136 } // namespace browser_sync |
| 130 | 137 |
| 131 #endif // CHROME_BROWSER_SYNC_GLUE_UI_MODEL_WORKER_H_ | 138 #endif // CHROME_BROWSER_SYNC_GLUE_UI_MODEL_WORKER_H_ |
| OLD | NEW |