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