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

Side by Side Diff: components/sync/engine/ui_model_worker.h

Issue 2820623002: Revert of [Sync] Refactor ModelSafeWorker::DoWorkAndWaitUntilDone() to avoid code duplication. (Closed)
Patch Set: Created 3 years, 8 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
OLDNEW
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 COMPONENTS_SYNC_ENGINE_UI_MODEL_WORKER_H_ 5 #ifndef COMPONENTS_SYNC_ENGINE_UI_MODEL_WORKER_H_
6 #define COMPONENTS_SYNC_ENGINE_UI_MODEL_WORKER_H_ 6 #define COMPONENTS_SYNC_ENGINE_UI_MODEL_WORKER_H_
7 7
8 #include "base/macros.h" 8 #include "base/macros.h"
9 #include "base/memory/ref_counted.h" 9 #include "base/memory/ref_counted.h"
10 #include "base/sequence_checker.h"
10 #include "base/single_thread_task_runner.h" 11 #include "base/single_thread_task_runner.h"
12 #include "base/synchronization/waitable_event.h"
11 #include "components/sync/engine/model_safe_worker.h" 13 #include "components/sync/engine/model_safe_worker.h"
12 14
13 namespace syncer { 15 namespace syncer {
14 16
15 // A ModelSafeWorker for UI models (e.g. bookmarks) that 17 // A ModelSafeWorker for UI models (e.g. bookmarks) that
16 // accepts work requests from the syncapi that need to be fulfilled 18 // accepts work requests from the syncapi that need to be fulfilled
17 // from the MessageLoop home to the native model. 19 // from the MessageLoop home to the native model.
18 class UIModelWorker : public ModelSafeWorker { 20 class UIModelWorker : public ModelSafeWorker {
19 public: 21 public:
20 explicit UIModelWorker(scoped_refptr<base::SingleThreadTaskRunner> ui_thread); 22 explicit UIModelWorker(scoped_refptr<base::SingleThreadTaskRunner> ui_thread);
21 23
22 // ModelSafeWorker implementation. 24 // ModelSafeWorker implementation.
25 void RequestStop() override;
23 ModelSafeGroup GetModelSafeGroup() override; 26 ModelSafeGroup GetModelSafeGroup() override;
24 bool IsOnModelThread() override; 27 bool IsOnModelThread() override;
25 28
29 protected:
30 SyncerError DoWorkAndWaitUntilDoneImpl(const WorkCallback& work) override;
31
26 private: 32 private:
27 ~UIModelWorker() override; 33 ~UIModelWorker() override;
28 34
29 void ScheduleWork(base::OnceClosure work) override;
30
31 // A reference to the UI thread's task runner. 35 // A reference to the UI thread's task runner.
32 const scoped_refptr<base::SingleThreadTaskRunner> ui_thread_; 36 const scoped_refptr<base::SingleThreadTaskRunner> ui_thread_;
33 37
38 // Signaled when a task posted by DoWorkAndWaitUntilDoneImpl() is deleted,
39 // i.e. after it runs or when it is abandoned. Reset at the beginning of every
40 // DoWorkAndWaitUntilDoneImpl() call.
41 base::WaitableEvent work_done_or_abandoned_;
42
43 // Signaled from RequestStop(). When this is signaled,
44 // DoWorkAndWaitUntilDoneImpl() returns immediately. This is needed to prevent
45 // the UI thread from joining the sync thread while it is waiting for a
46 // WorkCallback to run on the UI thread. See crbug.com/663600.
47 base::WaitableEvent stop_requested_;
48
49 // Verifies that calls to DoWorkAndWaitUntilDoneImpl() are sequenced.
50 base::SequenceChecker sequence_checker_;
51
34 DISALLOW_COPY_AND_ASSIGN(UIModelWorker); 52 DISALLOW_COPY_AND_ASSIGN(UIModelWorker);
35 }; 53 };
36 54
37 } // namespace syncer 55 } // namespace syncer
38 56
39 #endif // COMPONENTS_SYNC_ENGINE_UI_MODEL_WORKER_H_ 57 #endif // COMPONENTS_SYNC_ENGINE_UI_MODEL_WORKER_H_
OLDNEW
« no previous file with comments | « components/sync/engine/passive_model_worker.cc ('k') | components/sync/engine/ui_model_worker.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698