Upstream version 9.38.198.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 sync_driver {
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 some or all types.
41     ABORTED,             // Start was aborted by calling Stop() before
42                          // all types were started.
43     UNRECOVERABLE_ERROR  // We got an unrecoverable error during startup.
44   };
45
46   // Note: |errors| is only filled when status is not OK.
47   struct ConfigureResult {
48     ConfigureResult();
49     ConfigureResult(ConfigureStatus status,
50                     syncer::ModelTypeSet requested_types);
51     ~ConfigureResult();
52
53     ConfigureStatus status;
54     syncer::ModelTypeSet requested_types;
55   };
56
57   virtual ~DataTypeManager() {}
58
59   // Convert a ConfigureStatus to string for debug purposes.
60   static std::string ConfigureStatusToString(ConfigureStatus status);
61
62   // Begins asynchronous configuration of data types.  Any currently
63   // running data types that are not in the desired_types set will be
64   // stopped.  Any stopped data types that are in the desired_types
65   // set will be started.  All other data types are left in their
66   // current state.  A SYNC_CONFIGURE_START notification will be sent
67   // to the UI thread when configuration is started and a
68   // SYNC_CONFIGURE_DONE notification will be sent (with a
69   // ConfigureResult detail) when configuration is complete.
70   //
71   // Note that you may call Configure() while configuration is in
72   // progress.  Configuration will be complete only when the
73   // desired_types supplied in the last call to Configure is achieved.
74   virtual void Configure(syncer::ModelTypeSet desired_types,
75                          syncer::ConfigureReason reason) = 0;
76
77   virtual void PurgeForMigration(syncer::ModelTypeSet undesired_types,
78                                  syncer::ConfigureReason reason) = 0;
79
80   // Synchronously stops all registered data types.  If called after
81   // Configure() is called but before it finishes, it will abort the
82   // configure and any data types that have been started will be
83   // stopped.
84   virtual void Stop() = 0;
85
86   // The current state of the data type manager.
87   virtual State state() const = 0;
88 };
89
90 }  // namespace sync_driver
91
92 #endif  // COMPONENTS_SYNC_DRIVER_DATA_TYPE_MANAGER_H__