Upstream version 10.39.225.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 "components/sync_driver/data_type_status_table.h"
14 #include "sync/api/sync_error.h"
15 #include "sync/internal_api/public/base/model_type.h"
16 #include "sync/internal_api/public/configure_reason.h"
17
18 namespace sync_driver {
19
20 // This interface is for managing the start up and shut down life cycle
21 // of many different syncable data types.
22 class DataTypeManager {
23  public:
24   enum State {
25     STOPPED,           // No data types are currently running.
26     DOWNLOAD_PENDING,  // Not implemented yet: Waiting for the syncer to
27                        // complete the initial download of new data
28                        // types.
29
30     CONFIGURING,       // Data types are being started.
31     RETRYING,          // Retrying a pending reconfiguration.
32
33     CONFIGURED,        // All enabled data types are running.
34     STOPPING           // Data types are being stopped.
35   };
36
37   // Update NotifyDone() in data_type_manager_impl.cc if you update
38   // this.
39   enum ConfigureStatus {
40     UNKNOWN = -1,
41     OK,                  // Configuration finished some or all types.
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();
53
54     ConfigureStatus status;
55     syncer::ModelTypeSet requested_types;
56     DataTypeStatusTable data_type_status_table;
57   };
58
59   virtual ~DataTypeManager() {}
60
61   // Convert a ConfigureStatus to string for debug purposes.
62   static std::string ConfigureStatusToString(ConfigureStatus status);
63
64   // Begins asynchronous configuration of data types.  Any currently
65   // running data types that are not in the desired_types set will be
66   // stopped.  Any stopped data types that are in the desired_types
67   // set will be started.  All other data types are left in their
68   // current state.  A SYNC_CONFIGURE_START notification will be sent
69   // to the UI thread when configuration is started and a
70   // SYNC_CONFIGURE_DONE notification will be sent (with a
71   // ConfigureResult detail) when configuration is complete.
72   //
73   // Note that you may call Configure() while configuration is in
74   // progress.  Configuration will be complete only when the
75   // desired_types supplied in the last call to Configure is achieved.
76   virtual void Configure(syncer::ModelTypeSet desired_types,
77                          syncer::ConfigureReason reason) = 0;
78
79   // Resets the error state for |type| and triggers a reconfiguration if
80   // necessary.
81   virtual void ReenableType(syncer::ModelType type) = 0;
82
83   // Resets all data type error state.
84   virtual void ResetDataTypeErrors() = 0;
85
86   virtual void PurgeForMigration(syncer::ModelTypeSet undesired_types,
87                                  syncer::ConfigureReason reason) = 0;
88
89   // Synchronously stops all registered data types.  If called after
90   // Configure() is called but before it finishes, it will abort the
91   // configure and any data types that have been started will be
92   // stopped.
93   virtual void Stop() = 0;
94
95   // The current state of the data type manager.
96   virtual State state() const = 0;
97 };
98
99 }  // namespace sync_driver
100
101 #endif  // COMPONENTS_SYNC_DRIVER_DATA_TYPE_MANAGER_H__