1 // Copyright (c) 2012 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 CHROME_BROWSER_SYNC_GLUE_DATA_TYPE_MANAGER_H__ 6 #define CHROME_BROWSER_SYNC_GLUE_DATA_TYPE_MANAGER_H__ 7 8 #include <list> 9 #include <set> 10 #include <string> 11 12 #include "chrome/browser/sync/glue/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 waiting_to_start, 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 start association with in our alloted 66 // time period(see kDataTypeLoadWaitTimeInSeconds). We move 67 // forward here and allow these types to continue loading in the 68 // background. When these types are loaded DataTypeManager will 69 // be informed and another configured cycle will be started. 70 syncer::ModelTypeSet waiting_to_start; 71 72 // Those types that are unable to start due to the cryptographer not being 73 // ready. 74 syncer::ModelTypeSet needs_crypto; 75 }; 76 77 virtual ~DataTypeManager() {} 78 79 // Convert a ConfigureStatus to string for debug purposes. 80 static std::string ConfigureStatusToString(ConfigureStatus status); 81 82 // Begins asynchronous configuration of data types. Any currently 83 // running data types that are not in the desired_types set will be 84 // stopped. Any stopped data types that are in the desired_types 85 // set will be started. All other data types are left in their 86 // current state. A SYNC_CONFIGURE_START notification will be sent 87 // to the UI thread when configuration is started and a 88 // SYNC_CONFIGURE_DONE notification will be sent (with a 89 // ConfigureResult detail) when configuration is complete. 90 // 91 // Note that you may call Configure() while configuration is in 92 // progress. Configuration will be complete only when the 93 // desired_types supplied in the last call to Configure is achieved. 94 virtual void Configure(syncer::ModelTypeSet desired_types, 95 syncer::ConfigureReason reason) = 0; 96 97 virtual void PurgeForMigration(syncer::ModelTypeSet undesired_types, 98 syncer::ConfigureReason reason) = 0; 99 100 // Synchronously stops all registered data types. If called after 101 // Configure() is called but before it finishes, it will abort the 102 // configure and any data types that have been started will be 103 // stopped. 104 virtual void Stop() = 0; 105 106 // The current state of the data type manager. 107 virtual State state() const = 0; 108 }; 109 110 } // namespace browser_sync 111 112 #endif // CHROME_BROWSER_SYNC_GLUE_DATA_TYPE_MANAGER_H__ 113