1 // Copyright (c) 2012 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 CHROME_BROWSER_SYNC_GLUE_BACKEND_DATA_TYPE_CONFIGURER_H_ 6 #define CHROME_BROWSER_SYNC_GLUE_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 14 namespace browser_sync { 15 16 // The DataTypeConfigurer interface abstracts out the action of 17 // configuring a set of new data types and cleaning up after a set of 18 // removed data types. 19 class BackendDataTypeConfigurer { 20 public: 21 enum DataTypeConfigState { 22 CONFIGURE_ACTIVE, // Actively being configured. Data of such types 23 // will be downloaded if not present locally. 24 CONFIGURE_INACTIVE, // Already configured or to be configured in future. 25 // Data of such types is left as it is, no 26 // downloading or purging. 27 CONFIGURE_CLEAN, // Actively being configured but requiring unapply 28 // and GetUpdates first (e.g. for persistence errors). 29 DISABLED, // Not syncing. Disabled by user. 30 FATAL, // Not syncing due to unrecoverable error. 31 CRYPTO, // Not syncing due to a cryptographer error. 32 }; 33 typedef std::map<syncer::ModelType, DataTypeConfigState> 34 DataTypeConfigStateMap; 35 36 // Configures sync for data types in config_state_map according to the states. 37 // |ready_task| is called on the same thread as ConfigureDataTypes 38 // is called when configuration is done with the set of data types 39 // that succeeded/failed configuration (i.e., configuration succeeded iff 40 // the failed set is empty). 41 // 42 // TODO(akalin): Use a Delegate class with 43 // OnConfigureSuccess/OnConfigureFailure/OnConfigureRetry instead of 44 // a pair of callbacks. The awkward part is handling when 45 // SyncBackendHost calls ConfigureDataTypes on itself to configure 46 // Nigori. 47 virtual void ConfigureDataTypes( 48 syncer::ConfigureReason reason, 49 const DataTypeConfigStateMap& config_state_map, 50 const base::Callback<void(syncer::ModelTypeSet, 51 syncer::ModelTypeSet)>& ready_task, 52 const base::Callback<void()>& retry_callback) = 0; 53 54 // Return model types in |state_map| that match |state|. 55 static syncer::ModelTypeSet GetDataTypesInState( 56 DataTypeConfigState state, const DataTypeConfigStateMap& state_map); 57 58 // Set state of |types| in |state_map| to |state|. 59 static void SetDataTypesState(DataTypeConfigState state, 60 syncer::ModelTypeSet types, 61 DataTypeConfigStateMap* state_map); 62 63 protected: 64 virtual ~BackendDataTypeConfigurer() {} 65 }; 66 67 } // namespace browser_sync 68 69 #endif // CHROME_BROWSER_SYNC_GLUE_BACKEND_DATA_TYPE_CONFIGURER_H_ 70