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

Side by Side Diff: sync/internal_api/public/engine/model_safe_worker.h

Issue 10700180: [Sync] Add sync_export.h (Step 1 for componentizing sync) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address comments Created 8 years, 5 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) 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 SYNC_INTERNAL_API_PUBLIC_ENGINE_MODEL_SAFE_WORKER_H_ 5 #ifndef SYNC_INTERNAL_API_PUBLIC_ENGINE_MODEL_SAFE_WORKER_H_
6 #define SYNC_INTERNAL_API_PUBLIC_ENGINE_MODEL_SAFE_WORKER_H_ 6 #define SYNC_INTERNAL_API_PUBLIC_ENGINE_MODEL_SAFE_WORKER_H_
7 7
8 #include <map> 8 #include <map>
9 #include <string> 9 #include <string>
10 #include <vector> 10 #include <vector>
11 11
12 #include "base/callback.h" 12 #include "base/callback.h"
13 #include "base/memory/ref_counted.h" 13 #include "base/memory/ref_counted.h"
14 #include "sync/base/sync_export.h"
14 #include "sync/internal_api/public/base/model_type.h" 15 #include "sync/internal_api/public/base/model_type.h"
15 #include "sync/internal_api/public/base/model_type_payload_map.h" 16 #include "sync/internal_api/public/base/model_type_payload_map.h"
16 #include "sync/internal_api/public/util/syncer_error.h" 17 #include "sync/internal_api/public/util/syncer_error.h"
17 18
18 namespace base { 19 namespace base {
19 class DictionaryValue; 20 class DictionaryValue;
20 } // namespace 21 } // namespace
21 22
22 namespace syncer { 23 namespace syncer {
23 24
25 // TODO(akalin): Move the non-exported functions in this file to a
26 // private header.
27
24 typedef base::Callback<enum SyncerError(void)> WorkCallback; 28 typedef base::Callback<enum SyncerError(void)> WorkCallback;
25 29
26 enum ModelSafeGroup { 30 enum ModelSafeGroup {
27 GROUP_PASSIVE = 0, // Models that are just "passively" being synced; e.g. 31 GROUP_PASSIVE = 0, // Models that are just "passively" being synced; e.g.
28 // changes to these models don't need to be pushed to a 32 // changes to these models don't need to be pushed to a
29 // native model. 33 // native model.
30 GROUP_UI, // Models that live on UI thread and are being synced. 34 GROUP_UI, // Models that live on UI thread and are being synced.
31 GROUP_DB, // Models that live on DB thread and are being synced. 35 GROUP_DB, // Models that live on DB thread and are being synced.
32 GROUP_FILE, // Models that live on FILE thread and are being synced. 36 GROUP_FILE, // Models that live on FILE thread and are being synced.
33 GROUP_HISTORY, // Models that live on history thread and are being 37 GROUP_HISTORY, // Models that live on history thread and are being
34 // synced. 38 // synced.
35 GROUP_PASSWORD, // Models that live on the password thread and are 39 GROUP_PASSWORD, // Models that live on the password thread and are
36 // being synced. On windows and linux, this runs on the 40 // being synced. On windows and linux, this runs on the
37 // DB thread. 41 // DB thread.
38 MODEL_SAFE_GROUP_COUNT, 42 MODEL_SAFE_GROUP_COUNT,
39 }; 43 };
40 44
41 std::string ModelSafeGroupToString(ModelSafeGroup group); 45 SYNC_EXPORT std::string ModelSafeGroupToString(ModelSafeGroup group);
42 46
43 // The Syncer uses a ModelSafeWorker for all tasks that could potentially 47 // The Syncer uses a ModelSafeWorker for all tasks that could potentially
44 // modify syncable entries (e.g under a WriteTransaction). The ModelSafeWorker 48 // modify syncable entries (e.g under a WriteTransaction). The ModelSafeWorker
45 // only knows how to do one thing, and that is take some work (in a fully 49 // only knows how to do one thing, and that is take some work (in a fully
46 // pre-bound callback) and have it performed (as in Run()) from a thread which 50 // pre-bound callback) and have it performed (as in Run()) from a thread which
47 // is guaranteed to be "model-safe", where "safe" refers to not allowing us to 51 // is guaranteed to be "model-safe", where "safe" refers to not allowing us to
48 // cause an embedding application model to fall out of sync with the 52 // cause an embedding application model to fall out of sync with the
49 // syncable::Directory due to a race. 53 // syncable::Directory due to a race.
50 class ModelSafeWorker : public base::RefCountedThreadSafe<ModelSafeWorker> { 54 class SYNC_EXPORT ModelSafeWorker
55 : public base::RefCountedThreadSafe<ModelSafeWorker> {
51 public: 56 public:
52 // Any time the Syncer performs model modifications (e.g employing a 57 // Any time the Syncer performs model modifications (e.g employing a
53 // WriteTransaction), it should be done by this method to ensure it is done 58 // WriteTransaction), it should be done by this method to ensure it is done
54 // from a model-safe thread. 59 // from a model-safe thread.
55 virtual SyncerError DoWorkAndWaitUntilDone(const WorkCallback& work) = 0; 60 virtual SyncerError DoWorkAndWaitUntilDone(const WorkCallback& work) = 0;
56 61
57 virtual ModelSafeGroup GetModelSafeGroup() = 0; 62 virtual ModelSafeGroup GetModelSafeGroup() = 0;
58 63
59 protected: 64 protected:
60 virtual ~ModelSafeWorker(); 65 virtual ~ModelSafeWorker();
61 66
62 private: 67 private:
63 friend class base::RefCountedThreadSafe<ModelSafeWorker>; 68 friend class base::RefCountedThreadSafe<ModelSafeWorker>;
64 }; 69 };
65 70
66 // A map that details which ModelSafeGroup each syncer::ModelType 71 // A map that details which ModelSafeGroup each syncer::ModelType
67 // belongs to. Routing info can change in response to the user enabling / 72 // belongs to. Routing info can change in response to the user enabling /
68 // disabling sync for certain types, as well as model association completions. 73 // disabling sync for certain types, as well as model association completions.
69 typedef std::map<syncer::ModelType, ModelSafeGroup> 74 typedef std::map<syncer::ModelType, ModelSafeGroup>
70 ModelSafeRoutingInfo; 75 ModelSafeRoutingInfo;
71 76
72 // Caller takes ownership of return value. 77 // Caller takes ownership of return value.
73 base::DictionaryValue* ModelSafeRoutingInfoToValue( 78 base::DictionaryValue* ModelSafeRoutingInfoToValue(
74 const ModelSafeRoutingInfo& routing_info); 79 const ModelSafeRoutingInfo& routing_info);
75 80
76 std::string ModelSafeRoutingInfoToString( 81 SYNC_EXPORT std::string ModelSafeRoutingInfoToString(
77 const ModelSafeRoutingInfo& routing_info); 82 const ModelSafeRoutingInfo& routing_info);
78 83
79 // Make a ModelTypePayloadMap for all the enabled types in a 84 // Make a ModelTypePayloadMap for all the enabled types in a
80 // ModelSafeRoutingInfo using a default payload. 85 // ModelSafeRoutingInfo using a default payload.
81 syncer::ModelTypePayloadMap ModelSafeRoutingInfoToPayloadMap( 86 syncer::ModelTypePayloadMap ModelSafeRoutingInfoToPayloadMap(
82 const ModelSafeRoutingInfo& routes, 87 const ModelSafeRoutingInfo& routes,
83 const std::string& payload); 88 const std::string& payload);
84 89
85 syncer::ModelTypeSet GetRoutingInfoTypes( 90 SYNC_EXPORT syncer::ModelTypeSet GetRoutingInfoTypes(
86 const ModelSafeRoutingInfo& routing_info); 91 const ModelSafeRoutingInfo& routing_info);
87 92
88 ModelSafeGroup GetGroupForModelType(const syncer::ModelType type, 93 SYNC_EXPORT ModelSafeGroup GetGroupForModelType(
89 const ModelSafeRoutingInfo& routes); 94 const syncer::ModelType type,
95 const ModelSafeRoutingInfo& routes);
90 96
91 } // namespace syncer 97 } // namespace syncer
92 98
93 #endif // SYNC_INTERNAL_API_PUBLIC_ENGINE_MODEL_SAFE_WORKER_H_ 99 #endif // SYNC_INTERNAL_API_PUBLIC_ENGINE_MODEL_SAFE_WORKER_H_
OLDNEW
« no previous file with comments | « sync/internal_api/public/base/model_type_payload_map.h ('k') | sync/internal_api/public/engine/passive_model_worker.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698