OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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_ENGINE_MODEL_TYPE_REGISTRY_H_ | 5 #ifndef SYNC_ENGINE_MODEL_TYPE_REGISTRY_H_ |
6 #define SYNC_ENGINE_MODEL_TYPE_REGISTRY_H_ | 6 #define SYNC_ENGINE_MODEL_TYPE_REGISTRY_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
12 #include "base/memory/scoped_vector.h" | 12 #include "base/memory/scoped_vector.h" |
13 #include "base/memory/weak_ptr.h" | 13 #include "base/memory/weak_ptr.h" |
14 #include "sync/base/sync_export.h" | 14 #include "sync/base/sync_export.h" |
15 #include "sync/engine/directory_cryptographer_provider.h" | |
16 #include "sync/engine/nudge_handler.h" | 15 #include "sync/engine/nudge_handler.h" |
17 #include "sync/internal_api/public/base/model_type.h" | 16 #include "sync/internal_api/public/base/model_type.h" |
18 #include "sync/internal_api/public/engine/model_safe_worker.h" | 17 #include "sync/internal_api/public/engine/model_safe_worker.h" |
19 #include "sync/internal_api/public/non_blocking_sync_common.h" | |
20 #include "sync/internal_api/public/sessions/type_debug_info_observer.h" | 18 #include "sync/internal_api/public/sessions/type_debug_info_observer.h" |
21 #include "sync/internal_api/public/sync_context.h" | 19 #include "sync/internal_api/public/sync_context.h" |
22 | 20 |
23 namespace syncer { | 21 namespace syncer { |
24 | 22 |
25 namespace syncable { | 23 namespace syncable { |
26 class Directory; | 24 class Directory; |
27 } // namespace syncable | 25 } // namespace syncable |
28 | 26 |
29 class CommitContributor; | 27 class CommitContributor; |
30 class DirectoryCommitContributor; | 28 class DirectoryCommitContributor; |
31 class DirectoryUpdateHandler; | 29 class DirectoryUpdateHandler; |
32 class DirectoryTypeDebugInfoEmitter; | 30 class DirectoryTypeDebugInfoEmitter; |
33 class ModelTypeSyncWorkerImpl; | 31 class ModelTypeSyncWorkerImpl; |
34 class ModelTypeSyncProxyImpl; | 32 class ModelTypeSyncProxyImpl; |
35 class UpdateHandler; | 33 class UpdateHandler; |
| 34 struct DataTypeState; |
36 | 35 |
37 typedef std::map<ModelType, UpdateHandler*> UpdateHandlerMap; | 36 typedef std::map<ModelType, UpdateHandler*> UpdateHandlerMap; |
38 typedef std::map<ModelType, CommitContributor*> CommitContributorMap; | 37 typedef std::map<ModelType, CommitContributor*> CommitContributorMap; |
39 typedef std::map<ModelType, DirectoryTypeDebugInfoEmitter*> | 38 typedef std::map<ModelType, DirectoryTypeDebugInfoEmitter*> |
40 DirectoryTypeDebugInfoEmitterMap; | 39 DirectoryTypeDebugInfoEmitterMap; |
41 | 40 |
42 // Keeps track of the sets of active update handlers and commit contributors. | 41 // Keeps track of the sets of active update handlers and commit contributors. |
43 class SYNC_EXPORT_PRIVATE ModelTypeRegistry : public SyncContext { | 42 class SYNC_EXPORT_PRIVATE ModelTypeRegistry : public SyncContext { |
44 public: | 43 public: |
45 // Constructs a ModelTypeRegistry that supports directory types. | 44 // Constructs a ModelTypeRegistry that supports directory types. |
46 ModelTypeRegistry(const std::vector<scoped_refptr<ModelSafeWorker> >& workers, | 45 ModelTypeRegistry(const std::vector<scoped_refptr<ModelSafeWorker> >& workers, |
47 syncable::Directory* directory, | 46 syncable::Directory* directory, |
48 NudgeHandler* nudge_handler); | 47 NudgeHandler* nudge_handler); |
49 virtual ~ModelTypeRegistry(); | 48 virtual ~ModelTypeRegistry(); |
50 | 49 |
51 // Sets the set of enabled types. | 50 // Sets the set of enabled types. |
52 void SetEnabledDirectoryTypes(const ModelSafeRoutingInfo& routing_info); | 51 void SetEnabledDirectoryTypes(const ModelSafeRoutingInfo& routing_info); |
53 | 52 |
54 // Enables an off-thread type for syncing. Connects the given proxy | 53 // Enables an off-thread type for syncing. Connects the given proxy |
55 // and its task_runner to the newly created worker. | 54 // and its task_runner to the newly created worker. |
56 // | 55 // |
57 // Expects that the proxy's ModelType is not currently enabled. | 56 // Expects that the proxy's ModelType is not currently enabled. |
58 virtual void ConnectSyncTypeToWorker( | 57 virtual void ConnectSyncTypeToWorker( |
59 syncer::ModelType type, | 58 syncer::ModelType type, |
60 const DataTypeState& data_type_state, | 59 const DataTypeState& data_type_state, |
61 const syncer::UpdateResponseDataList& saved_pending_updates, | |
62 const scoped_refptr<base::SequencedTaskRunner>& type_task_runner, | 60 const scoped_refptr<base::SequencedTaskRunner>& type_task_runner, |
63 const base::WeakPtr<ModelTypeSyncProxyImpl>& proxy) OVERRIDE; | 61 const base::WeakPtr<ModelTypeSyncProxyImpl>& proxy) OVERRIDE; |
64 | 62 |
65 // Disables the syncing of an off-thread type. | 63 // Disables the syncing of an off-thread type. |
66 // | 64 // |
67 // Expects that the type is currently enabled. | 65 // Expects that the type is currently enabled. |
68 // Deletes the worker associated with the type. | 66 // Deletes the worker associated with the type. |
69 virtual void DisconnectSyncWorker(syncer::ModelType type) OVERRIDE; | 67 virtual void DisconnectSyncWorker(syncer::ModelType type) OVERRIDE; |
70 | 68 |
71 // Gets the set of enabled types. | 69 // Gets the set of enabled types. |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
107 // Non-blocking types handle debug info differently. | 105 // Non-blocking types handle debug info differently. |
108 // Does not own its contents. | 106 // Does not own its contents. |
109 DirectoryTypeDebugInfoEmitterMap directory_type_debug_info_emitter_map_; | 107 DirectoryTypeDebugInfoEmitterMap directory_type_debug_info_emitter_map_; |
110 | 108 |
111 // The known ModelSafeWorkers. | 109 // The known ModelSafeWorkers. |
112 std::map<ModelSafeGroup, scoped_refptr<ModelSafeWorker> > workers_map_; | 110 std::map<ModelSafeGroup, scoped_refptr<ModelSafeWorker> > workers_map_; |
113 | 111 |
114 // The directory. Not owned. | 112 // The directory. Not owned. |
115 syncable::Directory* directory_; | 113 syncable::Directory* directory_; |
116 | 114 |
117 // Provides access to the Directory's cryptographer. | |
118 DirectoryCryptographerProvider cryptographer_provider_; | |
119 | |
120 // The NudgeHandler. Not owned. | 115 // The NudgeHandler. Not owned. |
121 NudgeHandler* nudge_handler_; | 116 NudgeHandler* nudge_handler_; |
122 | 117 |
123 // The set of enabled directory types. | 118 // The set of enabled directory types. |
124 ModelTypeSet enabled_directory_types_; | 119 ModelTypeSet enabled_directory_types_; |
125 | 120 |
126 // The set of observers of per-type debug info. | 121 // The set of observers of per-type debug info. |
127 // | 122 // |
128 // Each of the DirectoryTypeDebugInfoEmitters needs such a list. There's | 123 // Each of the DirectoryTypeDebugInfoEmitters needs such a list. There's |
129 // a lot of them, and their lifetimes are unpredictable, so it makes the | 124 // a lot of them, and their lifetimes are unpredictable, so it makes the |
130 // book-keeping easier if we just store the list here. That way it's | 125 // book-keeping easier if we just store the list here. That way it's |
131 // guaranteed to live as long as this sync backend. | 126 // guaranteed to live as long as this sync backend. |
132 ObserverList<TypeDebugInfoObserver> type_debug_info_observers_; | 127 ObserverList<TypeDebugInfoObserver> type_debug_info_observers_; |
133 | 128 |
134 base::WeakPtrFactory<ModelTypeRegistry> weak_ptr_factory_; | 129 base::WeakPtrFactory<ModelTypeRegistry> weak_ptr_factory_; |
135 | 130 |
136 DISALLOW_COPY_AND_ASSIGN(ModelTypeRegistry); | 131 DISALLOW_COPY_AND_ASSIGN(ModelTypeRegistry); |
137 }; | 132 }; |
138 | 133 |
139 } // namespace syncer | 134 } // namespace syncer |
140 | 135 |
141 #endif // SYNC_ENGINE_MODEL_TYPE_REGISTRY_H_ | 136 #endif // SYNC_ENGINE_MODEL_TYPE_REGISTRY_H_ |
OLD | NEW |