Upstream version 5.34.104.0
[platform/framework/web/crosswalk.git] / src / components / sync_driver / data_type_manager.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_DATA_TYPE_MANAGER_H__
6 #define COMPONENTS_SYNC_DRIVER_DATA_TYPE_MANAGER_H__
7
8 #include <list>
9 #include <set>
10 #include <string>
11
12 #include "components/sync_driver/data_type_controller.h"
13 #include "sync/api/sync_error.h"
14 #include "sync/internal_api/public/base/model_type.h"
15 #include "sync/internal_api/public/configure_reason.h"
16
17 namespace browser_sync {
18
19 // This interface is for managing the start up and shut down life cycle
20 // of many different syncable data types.
21 class DataTypeManager {
22  public:
23   enum State {
24     STOPPED,           // No data types are currently running.
25     DOWNLOAD_PENDING,  // Not implemented yet: Waiting for the syncer to
26                        // complete the initial download of new data
27                        // types.
28
29     CONFIGURING,       // Data types are being started.
30     RETRYING,          // Retrying a pending reconfiguration.
31
32     CONFIGURED,        // All enabled data types are running.
33     STOPPING           // Data types are being stopped.
34   };
35
36   // Update NotifyDone() in data_type_manager_impl.cc if you update
37   // this.
38   enum ConfigureStatus {
39     UNKNOWN = -1,
40     OK,                  // Configuration finished without error.
41     PARTIAL_SUCCESS,     // Some data types had an error while starting up.
42     ABORTED,             // Start was aborted by calling Stop() before
43                          // all types were started.
44     UNRECOVERABLE_ERROR  // We got an unrecoverable error during startup.
45   };
46
47   // Note: |errors| is only filled when status is not OK.
48   struct ConfigureResult {
49     ConfigureResult();
50     ConfigureResult(ConfigureStatus status,
51                     syncer::ModelTypeSet requested_types);
52     ConfigureResult(ConfigureStatus status,
53                     syncer::ModelTypeSet requested_types,
54                     std::map<syncer::ModelType, syncer::SyncError>
55                         failed_data_types,
56                     syncer::ModelTypeSet unfinished_data_types,
57                     syncer::ModelTypeSet needs_crypto);
58     ~ConfigureResult();
59     ConfigureStatus status;
60     syncer::ModelTypeSet requested_types;
61
62     // These types encountered a failure in association.
63     std::map<syncer::ModelType, syncer::SyncError> failed_data_types;
64
65     // List of types that failed to finish loading/associating within our
66     // alloted time period(see |kAssociationTimeOutInSeconds|). We move
67     // forward here and allow these types to continue to load/associate in
68     // the background.
69     syncer::ModelTypeSet unfinished_data_types;
70
71     // Those types that are unable to start due to the cryptographer not being
72     // ready.
73     syncer::ModelTypeSet needs_crypto;
74   };
75
76   virtual ~DataTypeManager() {}
77
78   // Convert a ConfigureStatus to string for debug purposes.
79   static std::string ConfigureStatusToString(ConfigureStatus status);
80
81   // Begins asynchronous configuration of data types.  Any currently
82   // running data types that are not in the desired_types set will be
83   // stopped.  Any stopped data types that are in the desired_types
84   // set will be started.  All other data types are left in their
85   // current state.  A SYNC_CONFIGURE_START notification will be sent
86   // to the UI thread when configuration is started and a
87   // SYNC_CONFIGURE_DONE notification will be sent (with a
88   // ConfigureResult detail) when configuration is complete.
89   //
90   // Note that you may call Configure() while configuration is in
91   // progress.  Configuration will be complete only when the
92   // desired_types supplied in the last call to Configure is achieved.
93   virtual void Configure(syncer::ModelTypeSet desired_types,
94                          syncer::ConfigureReason reason) = 0;
95
96   virtual void PurgeForMigration(syncer::ModelTypeSet undesired_types,
97                                  syncer::ConfigureReason reason) = 0;
98
99   // Synchronously stops all registered data types.  If called after
100   // Configure() is called but before it finishes, it will abort the
101   // configure and any data types that have been started will be
102   // stopped.
103   virtual void Stop() = 0;
104
105   // The current state of the data type manager.
106   virtual State state() const = 0;
107 };
108
109 }  // namespace browser_sync
110
111 #endif  // COMPONENTS_SYNC_DRIVER_DATA_TYPE_MANAGER_H__