[Sync] Componentize UIModelWorker.
[chromium-blink-merge.git] / components / sync_driver / backend_data_type_configurer.h
blobdec42bb34df53b162066848483d1719818fc64ea
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 COMPONENTS_SYNC_DRIVER_BACKEND_DATA_TYPE_CONFIGURER_H_
6 #define COMPONENTS_SYNC_DRIVER_BACKEND_DATA_TYPE_CONFIGURER_H_
8 #include <map>
10 #include "base/callback.h"
11 #include "sync/internal_api/public/base/model_type.h"
12 #include "sync/internal_api/public/configure_reason.h"
13 #include "sync/internal_api/public/engine/model_safe_worker.h"
15 namespace sync_driver {
17 class ChangeProcessor;
19 // The DataTypeConfigurer interface abstracts out the action of
20 // configuring a set of new data types and cleaning up after a set of
21 // removed data types.
22 class BackendDataTypeConfigurer {
23 public:
24 enum DataTypeConfigState {
25 CONFIGURE_ACTIVE, // Actively being configured. Data of such types
26 // will be downloaded if not present locally.
27 CONFIGURE_INACTIVE, // Already configured or to be configured in future.
28 // Data of such types is left as it is, no
29 // downloading or purging.
30 CONFIGURE_CLEAN, // Actively being configured but requiring unapply
31 // and GetUpdates first (e.g. for persistence errors).
32 DISABLED, // Not syncing. Disabled by user.
33 FATAL, // Not syncing due to unrecoverable error.
34 CRYPTO, // Not syncing due to a cryptographer error.
35 UNREADY, // Not syncing due to transient error.
37 typedef std::map<syncer::ModelType, DataTypeConfigState>
38 DataTypeConfigStateMap;
40 // Configures sync for data types in config_state_map according to the states.
41 // |ready_task| is called on the same thread as ConfigureDataTypes
42 // is called when configuration is done with the set of data types
43 // that succeeded/failed configuration (i.e., configuration succeeded iff
44 // the failed set is empty).
45 // Returns: the set of types that are already configured and are ready to
46 // start.
48 // TODO(akalin): Use a Delegate class with
49 // OnConfigureSuccess/OnConfigureFailure/OnConfigureRetry instead of
50 // a pair of callbacks. The awkward part is handling when
51 // SyncBackendHost calls ConfigureDataTypes on itself to configure
52 // Nigori.
53 virtual syncer::ModelTypeSet ConfigureDataTypes(
54 syncer::ConfigureReason reason,
55 const DataTypeConfigStateMap& config_state_map,
56 const base::Callback<void(syncer::ModelTypeSet, syncer::ModelTypeSet)>&
57 ready_task,
58 const base::Callback<void()>& retry_callback) = 0;
60 // Return model types in |state_map| that match |state|.
61 static syncer::ModelTypeSet GetDataTypesInState(
62 DataTypeConfigState state, const DataTypeConfigStateMap& state_map);
64 // Activates change processing for the given data type. This must
65 // be called synchronously with the data type's model association so
66 // no changes are dropped between model association and change
67 // processor activation.
68 virtual void ActivateDataType(
69 syncer::ModelType type, syncer::ModelSafeGroup group,
70 ChangeProcessor* change_processor) = 0;
72 // Deactivates change processing for the given data type.
73 virtual void DeactivateDataType(syncer::ModelType type) = 0;
75 // Set state of |types| in |state_map| to |state|.
76 static void SetDataTypesState(DataTypeConfigState state,
77 syncer::ModelTypeSet types,
78 DataTypeConfigStateMap* state_map);
80 protected:
81 virtual ~BackendDataTypeConfigurer() {}
84 } // namespace sync_driver
86 #endif // COMPONENTS_SYNC_DRIVER_BACKEND_DATA_TYPE_CONFIGURER_H_