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. 4 5 #ifndef COMPONENTS_SYNC_DRIVER_BACKEND_DATA_TYPE_CONFIGURER_H_ 6 #define COMPONENTS_SYNC_DRIVER_BACKEND_DATA_TYPE_CONFIGURER_H_ 7 8 #include <map> 9 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" 14 15 namespace sync_driver { 16 17 class ChangeProcessor; 18 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. 36 }; 37 typedef std::map<syncer::ModelType, DataTypeConfigState> 38 DataTypeConfigStateMap; 39 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 // 46 // TODO(akalin): Use a Delegate class with 47 // OnConfigureSuccess/OnConfigureFailure/OnConfigureRetry instead of 48 // a pair of callbacks. The awkward part is handling when 49 // SyncBackendHost calls ConfigureDataTypes on itself to configure 50 // Nigori. 51 virtual void ConfigureDataTypes( 52 syncer::ConfigureReason reason, 53 const DataTypeConfigStateMap& config_state_map, 54 const base::Callback<void(syncer::ModelTypeSet, 55 syncer::ModelTypeSet)>& ready_task, 56 const base::Callback<void()>& retry_callback) = 0; 57 58 // Return model types in |state_map| that match |state|. 59 static syncer::ModelTypeSet GetDataTypesInState( 60 DataTypeConfigState state, const DataTypeConfigStateMap& state_map); 61 62 // Activates change processing for the given data type. This must 63 // be called synchronously with the data type's model association so 64 // no changes are dropped between model association and change 65 // processor activation. 66 virtual void ActivateDataType( 67 syncer::ModelType type, syncer::ModelSafeGroup group, 68 ChangeProcessor* change_processor) = 0; 69 70 // Deactivates change processing for the given data type. 71 virtual void DeactivateDataType(syncer::ModelType type) = 0; 72 73 // Set state of |types| in |state_map| to |state|. 74 static void SetDataTypesState(DataTypeConfigState state, 75 syncer::ModelTypeSet types, 76 DataTypeConfigStateMap* state_map); 77 78 protected: ~BackendDataTypeConfigurer()79 virtual ~BackendDataTypeConfigurer() {} 80 }; 81 82 } // namespace sync_driver 83 84 #endif // COMPONENTS_SYNC_DRIVER_BACKEND_DATA_TYPE_CONFIGURER_H_ 85