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
3 // found in the LICENSE file.
5 #ifndef SYNC_ENGINE_MODEL_TYPE_REGISTRY_H_
6 #define SYNC_ENGINE_MODEL_TYPE_REGISTRY_H_
10 #include "base/basictypes.h"
11 #include "base/memory/scoped_ptr.h"
12 #include "base/memory/scoped_vector.h"
13 #include "sync/base/sync_export.h"
14 #include "sync/internal_api/public/base/model_type.h"
15 #include "sync/internal_api/public/engine/model_safe_worker.h"
16 #include "sync/internal_api/public/sessions/type_debug_info_observer.h"
22 } // namespace syncable
24 class CommitContributor;
25 class DirectoryCommitContributor;
26 class DirectoryUpdateHandler;
27 class DirectoryTypeDebugInfoEmitter;
28 class NonBlockingTypeProcessorCore;
29 class NonBlockingTypeProcessor;
32 typedef std::map<ModelType, UpdateHandler*> UpdateHandlerMap;
33 typedef std::map<ModelType, CommitContributor*> CommitContributorMap;
34 typedef std::map<ModelType, DirectoryTypeDebugInfoEmitter*>
35 DirectoryTypeDebugInfoEmitterMap;
37 // Keeps track of the sets of active update handlers and commit contributors.
38 class SYNC_EXPORT_PRIVATE ModelTypeRegistry {
40 // This alternative constructor does not support any directory types.
41 // It is used only in tests.
44 // Constructs a ModelTypeRegistry that supports directory types.
46 const std::vector<scoped_refptr<ModelSafeWorker> >& workers,
47 syncable::Directory* directory);
50 // Sets the set of enabled types.
51 void SetEnabledDirectoryTypes(const ModelSafeRoutingInfo& routing_info);
53 // Enables an off-thread type for syncing. Connects the given processor
54 // and its task_runner to the newly created processor core.
56 // Expects that the processor's ModelType is not currently enabled.
57 void InitializeNonBlockingType(
58 syncer::ModelType type,
59 scoped_refptr<base::SequencedTaskRunner> type_task_runner,
60 base::WeakPtr<NonBlockingTypeProcessor> processor);
62 // Disables the syncing of an off-thread type.
64 // Expects that the type is currently enabled.
65 // Deletes the processor core associated with the type.
66 void RemoveNonBlockingType(syncer::ModelType type);
68 // Gets the set of enabled types.
69 ModelTypeSet GetEnabledTypes() const;
72 UpdateHandlerMap* update_handler_map();
73 CommitContributorMap* commit_contributor_map();
74 DirectoryTypeDebugInfoEmitterMap* directory_type_debug_info_emitter_map();
76 void RegisterDirectoryTypeDebugInfoObserver(
77 syncer::TypeDebugInfoObserver* observer);
78 void UnregisterDirectoryTypeDebugInfoObserver(
79 syncer::TypeDebugInfoObserver* observer);
80 bool HasDirectoryTypeDebugInfoObserver(
81 syncer::TypeDebugInfoObserver* observer);
82 void RequestEmitDebugInfo();
85 ModelTypeSet GetEnabledNonBlockingTypes() const;
86 ModelTypeSet GetEnabledDirectoryTypes() const;
88 // Sets of handlers and contributors.
89 ScopedVector<DirectoryCommitContributor> directory_commit_contributors_;
90 ScopedVector<DirectoryUpdateHandler> directory_update_handlers_;
91 ScopedVector<DirectoryTypeDebugInfoEmitter>
92 directory_type_debug_info_emitters_;
94 ScopedVector<NonBlockingTypeProcessorCore> non_blocking_type_processor_cores_;
96 // Maps of UpdateHandlers and CommitContributors.
97 // They do not own any of the objects they point to.
98 UpdateHandlerMap update_handler_map_;
99 CommitContributorMap commit_contributor_map_;
101 // Map of DebugInfoEmitters for directory types.
102 // Non-blocking types handle debug info differently.
103 // Does not own its contents.
104 DirectoryTypeDebugInfoEmitterMap directory_type_debug_info_emitter_map_;
106 // The known ModelSafeWorkers.
107 std::map<ModelSafeGroup, scoped_refptr<ModelSafeWorker> > workers_map_;
109 // The directory. Not owned.
110 syncable::Directory* directory_;
112 // The set of enabled directory types.
113 ModelTypeSet enabled_directory_types_;
115 // The set of observers of per-type debug info.
117 // Each of the DirectoryTypeDebugInfoEmitters needs such a list. There's
118 // a lot of them, and their lifetimes are unpredictable, so it makes the
119 // book-keeping easier if we just store the list here. That way it's
120 // guaranteed to live as long as this sync backend.
121 ObserverList<TypeDebugInfoObserver> type_debug_info_observers_;
123 DISALLOW_COPY_AND_ASSIGN(ModelTypeRegistry);
126 } // namespace syncer
128 #endif // SYNC_ENGINE_MODEL_TYPE_REGISTRY_H_