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

Side by Side Diff: chrome/browser/sync/engine/model_safe_worker.h

Issue 553015: Support for multiple sync ModelSafeWorkers.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 10 years, 11 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2009 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_ENGINE_MODEL_SAFE_WORKER_H_ 5 #ifndef CHROME_BROWSER_SYNC_ENGINE_MODEL_SAFE_WORKER_H_
6 #define CHROME_BROWSER_SYNC_ENGINE_MODEL_SAFE_WORKER_H_ 6 #define CHROME_BROWSER_SYNC_ENGINE_MODEL_SAFE_WORKER_H_
7 7
8 #include <map>
9 #include <vector>
10
11 #include "chrome/browser/sync/syncable/model_type.h"
8 #include "chrome/browser/sync/util/closure.h" 12 #include "chrome/browser/sync/util/closure.h"
9 #include "chrome/browser/sync/util/sync_types.h" 13 #include "chrome/browser/sync/util/sync_types.h"
10 14
11 namespace browser_sync { 15 namespace browser_sync {
12 16
17 enum ModelSafeGroup {
18 GROUP_PASSIVE = 0, // Models that are just "passively" being synced; e.g.
19 // changes to these models don't need to be pushed to a
20 // native model.
21 GROUP_UI, // Models that live on UI thread and are being synced.
22 GROUP_DB, // Models that live on DB thread and are being synced.
23 MODEL_SAFE_GROUP_COUNT,
24 };
25
13 // The Syncer uses a ModelSafeWorker for all tasks that could potentially 26 // The Syncer uses a ModelSafeWorker for all tasks that could potentially
14 // modify syncable entries (e.g under a WriteTransaction). The ModelSafeWorker 27 // modify syncable entries (e.g under a WriteTransaction). The ModelSafeWorker
15 // only knows how to do one thing, and that is take some work (in a fully 28 // only knows how to do one thing, and that is take some work (in a fully
16 // pre-bound callback) and have it performed (as in Run()) from a thread which 29 // pre-bound callback) and have it performed (as in Run()) from a thread which
17 // is guaranteed to be "model-safe", where "safe" refers to not allowing us to 30 // is guaranteed to be "model-safe", where "safe" refers to not allowing us to
18 // cause an embedding application model to fall out of sync with the 31 // cause an embedding application model to fall out of sync with the
19 // syncable::Directory due to a race. 32 // syncable::Directory due to a race.
20 class ModelSafeWorker { 33 class ModelSafeWorker {
21 public: 34 public:
22 ModelSafeWorker() { } 35 ModelSafeWorker() { }
23 virtual ~ModelSafeWorker() { } 36 virtual ~ModelSafeWorker() { }
24 37
25 // Any time the Syncer performs model modifications (e.g employing a 38 // Any time the Syncer performs model modifications (e.g employing a
26 // WriteTransaction), it should be done by this method to ensure it is done 39 // WriteTransaction), it should be done by this method to ensure it is done
27 // from a model-safe thread. 40 // from a model-safe thread.
28 //
29 // TODO(timsteele): For now this is non-reentrant, meaning the work being
30 // done should be at a high enough level in the stack that
31 // DoWorkAndWaitUntilDone won't be called again by invoking Run() on |work|.
32 // This is not strictly necessary; it may be best to call
33 // DoWorkAndWaitUntilDone at lower levels, such as within ApplyUpdates, but
34 // this is sufficient to simplify and test out our dispatching approach.
35 virtual void DoWorkAndWaitUntilDone(Closure* work) { 41 virtual void DoWorkAndWaitUntilDone(Closure* work) {
36 work->Run(); // By default, do the work on the current thread. 42 work->Run(); // For GROUP_PASSIVE, we do the work on the current thread.
43 }
44
45 virtual ModelSafeGroup GetModelSafeGroup() {
46 return GROUP_PASSIVE;
37 } 47 }
38 48
39 private: 49 private:
40 DISALLOW_COPY_AND_ASSIGN(ModelSafeWorker); 50 DISALLOW_COPY_AND_ASSIGN(ModelSafeWorker);
41 }; 51 };
42 52
53 // A map that details which ModelSafeGroup each syncable::ModelType
54 // belongs to. Routing info can change in response to the user enabling /
55 // disabling sync for certain types, as well as model association completions.
56 typedef std::map<syncable::ModelType, ModelSafeGroup>
57 ModelSafeRoutingInfo;
58
59 // Maintain the up-to-date state regarding which ModelSafeWorkers exist and
60 // which types get routed to which worker. When a sync session begins, it will
61 // snapshot the state at that instant, and will use that for the entire
62 // session. This means if a model becomes synced (or unsynced) by the user
63 // during a sync session, that session will complete and be unaware of this
64 // change -- it will only get picked up for the next session.
65 // TODO(tim): That's really the only way I can make sense of it in the Syncer
66 // HOWEVER, it is awkward for running ModelAssociation. We need to make sure
67 // we don't run such a thing until an active session wraps up.
68 class ModelSafeWorkerRegistrar {
69 public:
70 ModelSafeWorkerRegistrar() { }
71 // Get the current list of active ModelSafeWorkers. Should be threadsafe.
72 virtual void GetWorkers(std::vector<ModelSafeWorker*>* out) = 0;
73
74 // Get the current routing information for all model types.
75 virtual void GetModelSafeRoutingInfo(ModelSafeRoutingInfo* out) = 0;
76 protected:
77 virtual ~ModelSafeWorkerRegistrar() {}
78 private:
79 DISALLOW_COPY_AND_ASSIGN(ModelSafeWorkerRegistrar);
80 };
81
43 } // namespace browser_sync 82 } // namespace browser_sync
44 83
45 #endif // CHROME_BROWSER_SYNC_ENGINE_MODEL_SAFE_WORKER_H_ 84 #endif // CHROME_BROWSER_SYNC_ENGINE_MODEL_SAFE_WORKER_H_
OLDNEW
« no previous file with comments | « chrome/browser/sync/engine/model_changing_syncer_command.cc ('k') | chrome/browser/sync/engine/process_updates_command.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698