Upstream version 10.38.222.0
[platform/framework/web/crosswalk.git] / src / components / sync_driver / failed_data_types_handler.h
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 sync_driver {
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   // Returns the types that triggered the unrecoverable error.
65   syncer::ModelTypeSet GetUnrecoverableErrorTypes() const;
66
67   // Returns the current unrecoverable error, if there is one.
68   syncer::SyncError GetUnrecoverableError() const;
69
70  private:
71   // Returns true if there are any types with errors.
72   bool AnyFailedDataType() const;
73
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_;
77
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_;
82
83   // List of data types that failed due to the cryptographer not being ready.
84   TypeErrorMap crypto_errors_;
85
86   // List of data types that failed because sync did not persist the newest
87   // version of their data.
88   TypeErrorMap persistence_errors_;
89
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_;
93
94   DISALLOW_COPY_AND_ASSIGN(FailedDataTypesHandler);
95 };
96
97 }  // namespace sync_driver
98
99 #endif  // COMPONENTS_SYNC_DRIVER_FAILED_DATA_TYPES_HANDLER_H_