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