| OLD | NEW |
| 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 #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/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 // from the syncapi that need to be fulfilled from the MessageLoop home to the | 21 // from the syncapi that need to be fulfilled from the MessageLoop home to the |
| 22 // native model. | 22 // native model. |
| 23 // | 23 // |
| 24 // Lifetime note: Instances of this class will generally be owned by the | 24 // Lifetime note: Instances of this class will generally be owned by the |
| 25 // SyncerThread. When the SyncerThread _object_ is destroyed, the | 25 // SyncerThread. When the SyncerThread _object_ is destroyed, the |
| 26 // UIModelWorker will be destroyed. The SyncerThread object is destroyed | 26 // UIModelWorker will be destroyed. The SyncerThread object is destroyed |
| 27 // after the actual syncer pthread has exited. | 27 // after the actual syncer pthread has exited. |
| 28 class UIModelWorker : public browser_sync::ModelSafeWorker { | 28 class UIModelWorker : public browser_sync::ModelSafeWorker { |
| 29 public: | 29 public: |
| 30 UIModelWorker(); | 30 UIModelWorker(); |
| 31 virtual ~UIModelWorker(); | |
| 32 | 31 |
| 33 // Called by the UI thread on shutdown of the sync service. Blocks until | 32 // Called by the UI thread on shutdown of the sync service. Blocks until |
| 34 // the UIModelWorker has safely met termination conditions, namely that | 33 // the UIModelWorker has safely met termination conditions, namely that |
| 35 // no task scheduled by CallDoWorkFromModelSafeThreadAndWait remains un- | 34 // no task scheduled by CallDoWorkFromModelSafeThreadAndWait remains un- |
| 36 // processed and that syncapi will not schedule any further work for us to do. | 35 // processed and that syncapi will not schedule any further work for us to do. |
| 37 void Stop(); | 36 void Stop(); |
| 38 | 37 |
| 39 // ModelSafeWorker implementation. Called on syncapi SyncerThread. | 38 // ModelSafeWorker implementation. Called on syncapi SyncerThread. |
| 40 virtual SyncerError DoWorkAndWaitUntilDone( | 39 virtual SyncerError DoWorkAndWaitUntilDone( |
| 41 const WorkCallback& work) OVERRIDE; | 40 const WorkCallback& work) OVERRIDE; |
| (...skipping 19 matching lines...) Expand all Loading... |
| 61 // the SyncerThread has terminated and doesn't need us anymore. Since the | 60 // the SyncerThread has terminated and doesn't need us anymore. Since the |
| 62 // UI MessageLoop is not running at this point, we manually process any | 61 // UI MessageLoop is not running at this point, we manually process any |
| 63 // last pending_task_ that the Syncer throws at us, effectively dedicating | 62 // last pending_task_ that the Syncer throws at us, effectively dedicating |
| 64 // the UI thread to terminating the Syncer. | 63 // the UI thread to terminating the Syncer. |
| 65 RUNNING_MANUAL_SHUTDOWN_PUMP, | 64 RUNNING_MANUAL_SHUTDOWN_PUMP, |
| 66 // We have come to a complete stop, no scheduled work remains, and no work | 65 // We have come to a complete stop, no scheduled work remains, and no work |
| 67 // will be scheduled from now until our destruction. | 66 // will be scheduled from now until our destruction. |
| 68 STOPPED, | 67 STOPPED, |
| 69 }; | 68 }; |
| 70 | 69 |
| 70 virtual ~UIModelWorker(); |
| 71 |
| 71 // This is set by the UI thread, but is not explicitly thread safe, so only | 72 // This is set by the UI thread, but is not explicitly thread safe, so only |
| 72 // read this value from other threads when you know it is absolutely safe. | 73 // read this value from other threads when you know it is absolutely safe. |
| 73 State state_; | 74 State state_; |
| 74 | 75 |
| 75 // We keep a reference to any task we have scheduled so we can gracefully | 76 // We keep a reference to any task we have scheduled so we can gracefully |
| 76 // force them to run if the syncer is trying to shutdown. | 77 // force them to run if the syncer is trying to shutdown. |
| 77 base::Closure pending_work_; | 78 base::Closure pending_work_; |
| 78 | 79 |
| 79 // Set by the SyncCoreThread when Syncapi shutdown has completed and the | 80 // Set by the SyncCoreThread when Syncapi shutdown has completed and the |
| 80 // SyncerThread has terminated, so no more work will be scheduled. Read by | 81 // SyncerThread has terminated, so no more work will be scheduled. Read by |
| (...skipping 14 matching lines...) Expand all Loading... |
| 95 // SyncerThread has terminated. We only care about (1) when we are in Stop(), | 96 // SyncerThread has terminated. We only care about (1) when we are in Stop(), |
| 96 // because we have to manually Run() the task. | 97 // because we have to manually Run() the task. |
| 97 base::ConditionVariable syncapi_event_; | 98 base::ConditionVariable syncapi_event_; |
| 98 | 99 |
| 99 DISALLOW_COPY_AND_ASSIGN(UIModelWorker); | 100 DISALLOW_COPY_AND_ASSIGN(UIModelWorker); |
| 100 }; | 101 }; |
| 101 | 102 |
| 102 } // namespace browser_sync | 103 } // namespace browser_sync |
| 103 | 104 |
| 104 #endif // CHROME_BROWSER_SYNC_GLUE_UI_MODEL_WORKER_H_ | 105 #endif // CHROME_BROWSER_SYNC_GLUE_UI_MODEL_WORKER_H_ |
| OLD | NEW |