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_FAILED_DATA_TYPES_HANDLER_H_ 6 #define COMPONENTS_SYNC_DRIVER_FAILED_DATA_TYPES_HANDLER_H_ 7 8 #include <string> 9 10 #include "components/sync_driver/data_type_manager.h" 11 12 namespace browser_sync { 13 14 // Class to keep track of data types that have encountered an error during sync. 15 class FailedDataTypesHandler { 16 public: 17 typedef std::map<syncer::ModelType, syncer::SyncError> TypeErrorMap; 18 19 explicit FailedDataTypesHandler(); 20 ~FailedDataTypesHandler(); 21 22 // Update the failed datatypes. Types will be added to their corresponding 23 // error map based on their |error_type()|. 24 bool UpdateFailedDataTypes(const TypeErrorMap& errors); 25 26 // Resets the current set of data type errors. 27 void Reset(); 28 29 // Resets the set of types with cryptographer errors. 30 void ResetCryptoErrors(); 31 32 // Resets those persistence errors that intersect with |purged_types|. 33 void ResetPersistenceErrorsFrom(syncer::ModelTypeSet purged_types); 34 35 // Removes |type| from the data_type_errors_ set. Returns true if the type 36 // was removed from the error set, false if the type did not have a data type 37 // error to begin with. 38 bool ResetDataTypeErrorFor(syncer::ModelType type); 39 40 // Removes |type| from the unread_errors_ set. Returns true if the type 41 // was removed from the error set, false if the type did not have an unready 42 // error to begin with. 43 bool ResetUnreadyErrorFor(syncer::ModelType type); 44 45 // Returns a list of all the errors this class has recorded. 46 TypeErrorMap GetAllErrors() const; 47 48 // Returns all types with failure errors. This includes, fatal, crypto, and 49 // unready types.` 50 syncer::ModelTypeSet GetFailedTypes() const; 51 52 // Returns the types that are failing due to unrecoverable or datatype errors. 53 syncer::ModelTypeSet GetFatalErrorTypes() const; 54 55 // Returns the types that are failing due to cryptographer errors. 56 syncer::ModelTypeSet GetCryptoErrorTypes() const; 57 58 // Returns the types that are failing due to persistence errors. 59 syncer::ModelTypeSet GetPersistenceErrorTypes() const; 60 61 // Returns the types that cannot be configured due to not being ready. 62 syncer::ModelTypeSet GetUnreadyErrorTypes() const; 63 64 private: 65 // Returns true if there are any types with errors. 66 bool AnyFailedDataType() const; 67 68 // List of data types that failed due to unrecoverable errors and should 69 // be disabled. 70 TypeErrorMap unrecoverable_errors_; 71 72 // List of data types that failed due to runtime errors and should be 73 // disabled. These are different from unrecoverable_errors_ in that 74 // ResetDataTypeError can remove them from this list. 75 TypeErrorMap data_type_errors_; 76 77 // List of data types that failed due to the cryptographer not being ready. 78 TypeErrorMap crypto_errors_; 79 80 // List of data types that failed because sync did not persist the newest 81 // version of their data. 82 TypeErrorMap persistence_errors_; 83 84 // List of data types that could not start due to not being ready. These can 85 // be marked as ready by calling ResetUnreadyErrorFor(..). 86 TypeErrorMap unready_errors_; 87 88 DISALLOW_COPY_AND_ASSIGN(FailedDataTypesHandler); 89 }; 90 91 } // namespace browser_sync 92 93 #endif // COMPONENTS_SYNC_DRIVER_FAILED_DATA_TYPES_HANDLER_H_ 94