| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CHROME_BROWSER_SYNC_BACKEND_MIGRATOR_H_ | 5 #ifndef CHROME_BROWSER_SYNC_BACKEND_MIGRATOR_H_ |
| 6 #define CHROME_BROWSER_SYNC_BACKEND_MIGRATOR_H_ | 6 #define CHROME_BROWSER_SYNC_BACKEND_MIGRATOR_H_ |
| 7 | 7 |
| 8 #include "base/compiler_specific.h" |
| 9 #include "base/memory/weak_ptr.h" |
| 8 #include "base/task.h" | 10 #include "base/task.h" |
| 9 #include "chrome/browser/sync/profile_sync_service_observer.h" | 11 #include "chrome/browser/sync/glue/data_type_manager.h" |
| 10 #include "chrome/browser/sync/syncable/model_type.h" | 12 #include "chrome/browser/sync/syncable/model_type.h" |
| 11 #include "content/common/notification_observer.h" | 13 #include "content/common/notification_observer.h" |
| 12 #include "content/common/notification_registrar.h" | 14 #include "content/common/notification_registrar.h" |
| 13 | 15 |
| 14 class ProfileSyncService; | 16 class ProfileSyncService; |
| 15 | 17 |
| 16 namespace browser_sync { | 18 namespace browser_sync { |
| 17 | 19 |
| 18 class DataTypeManager; | |
| 19 | |
| 20 // A class to perform migration of a datatype pursuant to the 'MIGRATION_DONE' | 20 // A class to perform migration of a datatype pursuant to the 'MIGRATION_DONE' |
| 21 // code in the sync protocol definition (protocol/sync.proto). | 21 // code in the sync protocol definition (protocol/sync.proto). |
| 22 class BackendMigrator : public NotificationObserver, | 22 class BackendMigrator : public NotificationObserver { |
| 23 public ProfileSyncServiceObserver { | |
| 24 public: | 23 public: |
| 25 enum State { | 24 enum State { |
| 26 IDLE, | 25 IDLE, |
| 27 WAITING_TO_START, // Waiting for previous configuration to finish. | 26 WAITING_TO_START, // Waiting for previous configuration to finish. |
| 28 DISABLING_TYPES, // Exit criteria: SYNC_CONFIGURE_DONE for enabled | 27 DISABLING_TYPES, // Exit criteria: SYNC_CONFIGURE_DONE for |
| 29 // types _excluding_ |to_migrate_|. | 28 // enabled types _excluding_ |to_migrate_| and |
| 30 WAITING_FOR_PURGE, // Exit criteria: SyncCycleEnded for enabled types | 29 // empty download progress markers for types |
| 31 // excluding |to_migrate| | 30 // in |to_migrate_|. |
| 32 REENABLING_TYPES, // Exit criteria: SYNC_CONFIGURE_DONE for enabled | 31 REENABLING_TYPES, // Exit criteria: SYNC_CONFIGURE_DONE for enabled |
| 33 // types. | 32 // types. |
| 34 }; | 33 }; |
| 35 | 34 |
| 36 BackendMigrator(ProfileSyncService* service, DataTypeManager* manager); | 35 BackendMigrator(ProfileSyncService* service, DataTypeManager* manager); |
| 37 virtual ~BackendMigrator(); | 36 virtual ~BackendMigrator(); |
| 38 | 37 |
| 39 // Starts a sequence of events that will disable and reenable |types|. | 38 // Starts a sequence of events that will disable and reenable |types|. |
| 40 void MigrateTypes(const syncable::ModelTypeSet& types); | 39 void MigrateTypes(const syncable::ModelTypeSet& types); |
| 41 | 40 |
| 42 // ProfileSyncServiceObserver implementation. | |
| 43 virtual void OnStateChanged(); | |
| 44 | |
| 45 // NotificationObserver implementation. | 41 // NotificationObserver implementation. |
| 46 virtual void Observe(int type, | 42 virtual void Observe(int type, |
| 47 const NotificationSource& source, | 43 const NotificationSource& source, |
| 48 const NotificationDetails& details); | 44 const NotificationDetails& details) OVERRIDE; |
| 49 | 45 |
| 50 State state() const; | 46 State state() const; |
| 51 | 47 |
| 52 private: | 48 private: |
| 53 bool HasStartedMigrating() const; | 49 // Must be called only in state WAITING_TO_START. If ready to |
| 50 // start, meaning the data type manager is configured, calls |
| 51 // RestartMigration() and returns true. Otherwise, does nothing and |
| 52 // returns false. |
| 53 bool TryStart(); |
| 54 |
| 55 // Restarts migration, interrupting any existing migration. |
| 56 void RestartMigration(); |
| 57 |
| 58 // Called by Observe(). |
| 59 void OnConfigureDone(const DataTypeManager::ConfigureResult& result); |
| 54 | 60 |
| 55 State state_; | 61 State state_; |
| 56 ProfileSyncService* service_; | 62 ProfileSyncService* service_; |
| 57 DataTypeManager* manager_; | 63 DataTypeManager* manager_; |
| 58 NotificationRegistrar registrar_; | 64 NotificationRegistrar registrar_; |
| 59 | 65 |
| 60 syncable::ModelTypeSet to_migrate_; | 66 syncable::ModelTypeSet to_migrate_; |
| 61 bool restart_migration_; | |
| 62 | 67 |
| 63 // We use this to gracefully re-start migrations. | 68 base::WeakPtrFactory<BackendMigrator> weak_ptr_factory_; |
| 64 ScopedRunnableMethodFactory<BackendMigrator> method_factory_; | |
| 65 | 69 |
| 66 DISALLOW_COPY_AND_ASSIGN(BackendMigrator); | 70 DISALLOW_COPY_AND_ASSIGN(BackendMigrator); |
| 67 }; | 71 }; |
| 68 | 72 |
| 69 } // namespace browser_sync | 73 } // namespace browser_sync |
| 70 | 74 |
| 71 #endif // CHROME_BROWSER_SYNC_BACKEND_MIGRATOR_H_ | 75 #endif // CHROME_BROWSER_SYNC_BACKEND_MIGRATOR_H_ |
| OLD | NEW |