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.
5 #ifndef COMPONENTS_SYNC_DRIVER_DATA_TYPE_MANAGER_H__
6 #define COMPONENTS_SYNC_DRIVER_DATA_TYPE_MANAGER_H__
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"
17 namespace browser_sync {
19 // This interface is for managing the start up and shut down life cycle
20 // of many different syncable data types.
21 class DataTypeManager {
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
29 CONFIGURING, // Data types are being started.
30 RETRYING, // Retrying a pending reconfiguration.
32 CONFIGURED, // All enabled data types are running.
33 STOPPING // Data types are being stopped.
36 // Update NotifyDone() in data_type_manager_impl.cc if you update
38 enum ConfigureStatus {
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.
47 // Note: |errors| is only filled when status is not OK.
48 struct 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>
56 syncer::ModelTypeSet unfinished_data_types,
57 syncer::ModelTypeSet needs_crypto);
59 ConfigureStatus status;
60 syncer::ModelTypeSet requested_types;
62 // These types encountered a failure in association.
63 std::map<syncer::ModelType, syncer::SyncError> failed_data_types;
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
69 syncer::ModelTypeSet unfinished_data_types;
71 // Those types that are unable to start due to the cryptographer not being
73 syncer::ModelTypeSet needs_crypto;
76 virtual ~DataTypeManager() {}
78 // Convert a ConfigureStatus to string for debug purposes.
79 static std::string ConfigureStatusToString(ConfigureStatus status);
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.
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;
96 virtual void PurgeForMigration(syncer::ModelTypeSet undesired_types,
97 syncer::ConfigureReason reason) = 0;
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
103 virtual void Stop() = 0;
105 // The current state of the data type manager.
106 virtual State state() const = 0;
109 } // namespace browser_sync
111 #endif // COMPONENTS_SYNC_DRIVER_DATA_TYPE_MANAGER_H__