data_type_status_table.h 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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. #ifndef COMPONENTS_SYNC_DRIVER_DATA_TYPE_STATUS_TABLE_H_
  5. #define COMPONENTS_SYNC_DRIVER_DATA_TYPE_STATUS_TABLE_H_
  6. #include <map>
  7. #include "components/sync/base/model_type.h"
  8. #include "components/sync/model/sync_error.h"
  9. namespace syncer {
  10. // Class to keep track of data types that have encountered an error during sync.
  11. class DataTypeStatusTable {
  12. public:
  13. using TypeErrorMap = std::map<ModelType, SyncError>;
  14. DataTypeStatusTable();
  15. DataTypeStatusTable(const DataTypeStatusTable& other);
  16. ~DataTypeStatusTable();
  17. // Copy and assign welcome.
  18. // Update the failed datatypes. Types will be added to their corresponding
  19. // error map based on their |error_type()|.
  20. void UpdateFailedDataTypes(const TypeErrorMap& errors);
  21. // Update an individual failed datatype. The type will be added to its
  22. // corresponding error map based on |error.error_type()|. Returns true if
  23. // there was an actual change.
  24. bool UpdateFailedDataType(ModelType type, const SyncError& error);
  25. // Resets the current set of data type errors.
  26. void Reset();
  27. // Resets the set of types with cryptographer errors.
  28. void ResetCryptoErrors();
  29. // Removes |type| from the data_type_errors_ set. Returns true if the type
  30. // was removed from the error set, false if the type did not have a data type
  31. // error to begin with.
  32. bool ResetDataTypePolicyErrorFor(ModelType type);
  33. // Removes |type| from the unread_errors_ set. Returns true if the type
  34. // was removed from the error set, false if the type did not have an unready
  35. // error to begin with.
  36. bool ResetUnreadyErrorFor(ModelType type);
  37. // Returns a list of all the errors this class has recorded.
  38. TypeErrorMap GetAllErrors() const;
  39. // Returns all types with failure errors. This includes, fatal, crypto, and
  40. // unready types.
  41. ModelTypeSet GetFailedTypes() const;
  42. // Returns the types that are failing due to datatype errors.
  43. ModelTypeSet GetFatalErrorTypes() const;
  44. // Returns the types that are failing due to cryptographer errors.
  45. ModelTypeSet GetCryptoErrorTypes() const;
  46. // Returns the types that cannot be configured due to not being ready.
  47. ModelTypeSet GetUnreadyErrorTypes() const;
  48. private:
  49. // List of data types that failed due to runtime errors and should be
  50. // disabled. ResetDataTypeError can remove them from this list.
  51. TypeErrorMap data_type_errors_;
  52. TypeErrorMap data_type_policy_errors_;
  53. // List of data types that failed due to the cryptographer not being ready.
  54. TypeErrorMap crypto_errors_;
  55. // List of data types that could not start due to not being ready. These can
  56. // be marked as ready by calling ResetUnreadyErrorFor(..).
  57. TypeErrorMap unready_errors_;
  58. };
  59. } // namespace syncer
  60. #endif // COMPONENTS_SYNC_DRIVER_DATA_TYPE_STATUS_TABLE_H_