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