| Index: components/sync/engine/model_safe_worker.h
|
| diff --git a/components/sync/engine/model_safe_worker.h b/components/sync/engine/model_safe_worker.h
|
| index 2a075ac80c0fcc1248c91e59774b1b0802df983b..869bbae47db3afecc6113bb56688495164663f60 100644
|
| --- a/components/sync/engine/model_safe_worker.h
|
| +++ b/components/sync/engine/model_safe_worker.h
|
| @@ -8,13 +8,11 @@
|
| #include <map>
|
| #include <memory>
|
| #include <string>
|
| -#include <vector>
|
|
|
| -#include "base/callback.h"
|
| +#include "base/callback_forward.h"
|
| +#include "base/macros.h"
|
| #include "base/memory/ref_counted.h"
|
| -#include "base/message_loop/message_loop.h"
|
| -#include "base/single_thread_task_runner.h"
|
| -#include "base/synchronization/lock.h"
|
| +#include "base/synchronization/atomic_flag.h"
|
| #include "components/sync/base/model_type.h"
|
| #include "components/sync/base/syncer_error.h"
|
|
|
| @@ -46,13 +44,6 @@ enum ModelSafeGroup {
|
|
|
| std::string ModelSafeGroupToString(ModelSafeGroup group);
|
|
|
| -// WorkerLoopDestructionObserver is notified when the thread where it works
|
| -// is going to be destroyed.
|
| -class WorkerLoopDestructionObserver {
|
| - public:
|
| - virtual void OnWorkerLoopDestroyed(ModelSafeGroup group) = 0;
|
| -};
|
| -
|
| // The Syncer uses a ModelSafeWorker for all tasks that could potentially
|
| // modify syncable entries (e.g under a WriteTransaction). The ModelSafeWorker
|
| // only knows how to do one thing, and that is take some work (in a fully
|
| @@ -60,23 +51,9 @@ class WorkerLoopDestructionObserver {
|
| // is guaranteed to be "model-safe", where "safe" refers to not allowing us to
|
| // cause an embedding application model to fall out of sync with the
|
| // syncable::Directory due to a race. Each ModelSafeWorker is affiliated with
|
| -// a thread and does actual work on that thread. On the destruction of that
|
| -// thread, the affiliated worker is effectively disabled to do more
|
| -// work and will notify its observer.
|
| -class ModelSafeWorker : public base::RefCountedThreadSafe<ModelSafeWorker>,
|
| - public base::MessageLoop::DestructionObserver {
|
| +// a thread and does actual work on that thread.
|
| +class ModelSafeWorker : public base::RefCountedThreadSafe<ModelSafeWorker> {
|
| public:
|
| - // Subclass should implement to observe destruction of the loop where
|
| - // it actually does work. Called on UI thread immediately after worker is
|
| - // created.
|
| - virtual void RegisterForLoopDestruction() = 0;
|
| -
|
| - // Called on sync loop from SyncBackendRegistrar::ShutDown(). Post task to
|
| - // working loop to stop observing loop destruction and invoke
|
| - // |unregister_done_callback|.
|
| - virtual void UnregisterForLoopDestruction(
|
| - base::Callback<void(ModelSafeGroup)> unregister_done_callback);
|
| -
|
| // If not stopped, call DoWorkAndWaitUntilDoneImpl() to do work. Otherwise
|
| // return CANNOT_DO_WORK.
|
| SyncerError DoWorkAndWaitUntilDone(const WorkCallback& work);
|
| @@ -87,12 +64,9 @@ class ModelSafeWorker : public base::RefCountedThreadSafe<ModelSafeWorker>,
|
|
|
| virtual ModelSafeGroup GetModelSafeGroup() = 0;
|
|
|
| - // MessageLoop::DestructionObserver implementation.
|
| - void WillDestroyCurrentMessageLoop() override;
|
| -
|
| protected:
|
| - explicit ModelSafeWorker(WorkerLoopDestructionObserver* observer);
|
| - ~ModelSafeWorker() override;
|
| + ModelSafeWorker();
|
| + virtual ~ModelSafeWorker();
|
|
|
| // Any time the Syncer performs model modifications (e.g employing a
|
| // WriteTransaction), it should be done by this method to ensure it is done
|
| @@ -102,35 +76,13 @@ class ModelSafeWorker : public base::RefCountedThreadSafe<ModelSafeWorker>,
|
| // Return true if the worker was stopped. Thread safe.
|
| bool IsStopped();
|
|
|
| - // Subclass should call this in RegisterForLoopDestruction() from the loop
|
| - // where work is done.
|
| - void SetWorkingLoopToCurrent();
|
| -
|
| private:
|
| friend class base::RefCountedThreadSafe<ModelSafeWorker>;
|
|
|
| - void UnregisterForLoopDestructionAsync(
|
| - base::Callback<void(ModelSafeGroup)> unregister_done_callback);
|
| -
|
| - // Whether the worker should/can do more work. Set when sync is disabled or
|
| - // when the worker's working thread is to be destroyed.
|
| - base::Lock stopped_lock_;
|
| - bool stopped_;
|
| -
|
| - // Notified when working thread of the worker is to be destroyed.
|
| - WorkerLoopDestructionObserver* observer_;
|
| -
|
| - // Remember working loop for posting task to unregister destruction
|
| - // observation from sync thread when shutting down sync.
|
| - base::Lock working_task_runner_lock_;
|
| - scoped_refptr<base::SingleThreadTaskRunner> working_task_runner_;
|
| + // Whether the worker should do more work. Set when sync is disabled.
|
| + base::AtomicFlag stopped_;
|
|
|
| - // Callback passed with UnregisterForLoopDestruction. Normally this
|
| - // remains unset/unused and is stored only if |working_task_runner_| isn't
|
| - // initialized by the time UnregisterForLoopDestruction is called.
|
| - // It is safe to copy and thread safe.
|
| - // See comments in model_safe_worker.cc for more details.
|
| - base::Callback<void(ModelSafeGroup)> unregister_done_callback_;
|
| + DISALLOW_COPY_AND_ASSIGN(ModelSafeWorker);
|
| };
|
|
|
| // A map that details which ModelSafeGroup each ModelType
|
|
|