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.
5 #ifndef COMPONENTS_SYNC_DRIVER_FAILED_DATA_TYPES_HANDLER_H_
6 #define COMPONENTS_SYNC_DRIVER_FAILED_DATA_TYPES_HANDLER_H_
10 #include "components/sync_driver/data_type_manager.h"
12 namespace sync_driver {
14 // Class to keep track of data types that have encountered an error during sync.
15 class FailedDataTypesHandler {
17 typedef std::map<syncer::ModelType, syncer::SyncError> TypeErrorMap;
19 explicit FailedDataTypesHandler();
20 ~FailedDataTypesHandler();
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);
26 // Resets the current set of data type errors.
29 // Resets the set of types with cryptographer errors.
30 void ResetCryptoErrors();
32 // Resets those persistence errors that intersect with |purged_types|.
33 void ResetPersistenceErrorsFrom(syncer::ModelTypeSet purged_types);
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);
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);
45 // Returns a list of all the errors this class has recorded.
46 TypeErrorMap GetAllErrors() const;
48 // Returns all types with failure errors. This includes, fatal, crypto, and
50 syncer::ModelTypeSet GetFailedTypes() const;
52 // Returns the types that are failing due to unrecoverable or datatype errors.
53 syncer::ModelTypeSet GetFatalErrorTypes() const;
55 // Returns the types that are failing due to cryptographer errors.
56 syncer::ModelTypeSet GetCryptoErrorTypes() const;
58 // Returns the types that are failing due to persistence errors.
59 syncer::ModelTypeSet GetPersistenceErrorTypes() const;
61 // Returns the types that cannot be configured due to not being ready.
62 syncer::ModelTypeSet GetUnreadyErrorTypes() const;
64 // Returns the types that triggered the unrecoverable error.
65 syncer::ModelTypeSet GetUnrecoverableErrorTypes() const;
67 // Returns the current unrecoverable error, if there is one.
68 syncer::SyncError GetUnrecoverableError() const;
71 // Returns true if there are any types with errors.
72 bool AnyFailedDataType() const;
74 // The current unrecoverable errors. Only one unrecoverable error can be
75 // active at a time, but it may apply to more than one type.
76 TypeErrorMap unrecoverable_errors_;
78 // List of data types that failed due to runtime errors and should be
79 // disabled. These are different from unrecoverable_errors_ in that
80 // ResetDataTypeError can remove them from this list.
81 TypeErrorMap data_type_errors_;
83 // List of data types that failed due to the cryptographer not being ready.
84 TypeErrorMap crypto_errors_;
86 // List of data types that failed because sync did not persist the newest
87 // version of their data.
88 TypeErrorMap persistence_errors_;
90 // List of data types that could not start due to not being ready. These can
91 // be marked as ready by calling ResetUnreadyErrorFor(..).
92 TypeErrorMap unready_errors_;
94 DISALLOW_COPY_AND_ASSIGN(FailedDataTypesHandler);
97 } // namespace sync_driver
99 #endif // COMPONENTS_SYNC_DRIVER_FAILED_DATA_TYPES_HANDLER_H_