| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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" | 8 #include "base/compiler_specific.h" |
| 9 #include "base/memory/weak_ptr.h" | 9 #include "base/memory/weak_ptr.h" |
| 10 #include "base/observer_list.h" | 10 #include "base/observer_list.h" |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 class MigrationObserver { | 26 class MigrationObserver { |
| 27 public: | 27 public: |
| 28 virtual void OnMigrationStateChange() = 0; | 28 virtual void OnMigrationStateChange() = 0; |
| 29 | 29 |
| 30 protected: | 30 protected: |
| 31 virtual ~MigrationObserver(); | 31 virtual ~MigrationObserver(); |
| 32 }; | 32 }; |
| 33 | 33 |
| 34 // A class to perform migration of a datatype pursuant to the 'MIGRATION_DONE' | 34 // A class to perform migration of a datatype pursuant to the 'MIGRATION_DONE' |
| 35 // code in the sync protocol definition (protocol/sync.proto). | 35 // code in the sync protocol definition (protocol/sync.proto). |
| 36 class BackendMigrator : public content::NotificationObserver { | 36 class BackendMigrator { |
| 37 public: | 37 public: |
| 38 enum State { | 38 enum State { |
| 39 IDLE, | 39 IDLE, |
| 40 WAITING_TO_START, // Waiting for previous configuration to finish. | 40 WAITING_TO_START, // Waiting for previous configuration to finish. |
| 41 DISABLING_TYPES, // Exit criteria: SYNC_CONFIGURE_DONE for | 41 DISABLING_TYPES, // Exit criteria: SYNC_CONFIGURE_DONE for |
| 42 // enabled types _excluding_ |to_migrate_| and | 42 // enabled types _excluding_ |to_migrate_| and |
| 43 // empty download progress markers for types | 43 // empty download progress markers for types |
| 44 // in |to_migrate_|. | 44 // in |to_migrate_|. |
| 45 REENABLING_TYPES, // Exit criteria: SYNC_CONFIGURE_DONE for enabled | 45 REENABLING_TYPES, // Exit criteria: SYNC_CONFIGURE_DONE for enabled |
| 46 // types. | 46 // types. |
| 47 }; | 47 }; |
| 48 | 48 |
| 49 // TODO(akalin): Remove the dependency on |user_share|. | 49 // TODO(akalin): Remove the dependency on |user_share|. |
| 50 BackendMigrator(const std::string& name, | 50 BackendMigrator(const std::string& name, |
| 51 sync_api::UserShare* user_share, | 51 sync_api::UserShare* user_share, |
| 52 ProfileSyncService* service, | 52 ProfileSyncService* service, |
| 53 DataTypeManager* manager); | 53 DataTypeManager* manager); |
| 54 virtual ~BackendMigrator(); | 54 virtual ~BackendMigrator(); |
| 55 | 55 |
| 56 // Starts a sequence of events that will disable and reenable |types|. | 56 // Starts a sequence of events that will disable and reenable |types|. |
| 57 void MigrateTypes(syncable::ModelTypeSet types); | 57 void MigrateTypes(syncable::ModelTypeSet types); |
| 58 | 58 |
| 59 void AddMigrationObserver(MigrationObserver* observer); | 59 void AddMigrationObserver(MigrationObserver* observer); |
| 60 bool HasMigrationObserver(MigrationObserver* observer) const; | 60 bool HasMigrationObserver(MigrationObserver* observer) const; |
| 61 void RemoveMigrationObserver(MigrationObserver* observer); | 61 void RemoveMigrationObserver(MigrationObserver* observer); |
| 62 | 62 |
| 63 // content::NotificationObserver implementation. | 63 State state() const; |
| 64 virtual void Observe(int type, | |
| 65 const content::NotificationSource& source, | |
| 66 const content::NotificationDetails& details) OVERRIDE; | |
| 67 | 64 |
| 68 State state() const; | 65 // Called from ProfileSyncService to notify us of configure done. |
| 66 // Note: We receive these notificiations only when our state is not IDLE. |
| 67 void OnConfigureDone(const DataTypeManager::ConfigureResult& result); |
| 69 | 68 |
| 70 // Returns the types that are currently pending migration (if any). | 69 // Returns the types that are currently pending migration (if any). |
| 71 syncable::ModelTypeSet GetPendingMigrationTypesForTest() const; | 70 syncable::ModelTypeSet GetPendingMigrationTypesForTest() const; |
| 72 | 71 |
| 73 private: | 72 private: |
| 74 void ChangeState(State new_state); | 73 void ChangeState(State new_state); |
| 75 | 74 |
| 76 // Must be called only in state WAITING_TO_START. If ready to | 75 // Must be called only in state WAITING_TO_START. If ready to |
| 77 // start, meaning the data type manager is configured, calls | 76 // start, meaning the data type manager is configured, calls |
| 78 // RestartMigration() and returns true. Otherwise, does nothing and | 77 // RestartMigration() and returns true. Otherwise, does nothing and |
| 79 // returns false. | 78 // returns false. |
| 80 bool TryStart(); | 79 bool TryStart(); |
| 81 | 80 |
| 82 // Restarts migration, interrupting any existing migration. | 81 // Restarts migration, interrupting any existing migration. |
| 83 void RestartMigration(); | 82 void RestartMigration(); |
| 84 | 83 |
| 85 // Called by Observe(). | 84 // Called by OnConfigureDone(). |
| 86 void OnConfigureDone(const DataTypeManager::ConfigureResult& result); | 85 void OnConfigureDoneImpl(const DataTypeManager::ConfigureResult& result); |
| 87 | 86 |
| 88 const std::string name_; | 87 const std::string name_; |
| 89 sync_api::UserShare* user_share_; | 88 sync_api::UserShare* user_share_; |
| 90 ProfileSyncService* service_; | 89 ProfileSyncService* service_; |
| 91 DataTypeManager* manager_; | 90 DataTypeManager* manager_; |
| 92 | 91 |
| 93 State state_; | 92 State state_; |
| 94 | 93 |
| 95 content::NotificationRegistrar registrar_; | |
| 96 | |
| 97 ObserverList<MigrationObserver> migration_observers_; | 94 ObserverList<MigrationObserver> migration_observers_; |
| 98 | 95 |
| 99 syncable::ModelTypeSet to_migrate_; | 96 syncable::ModelTypeSet to_migrate_; |
| 100 | 97 |
| 101 base::WeakPtrFactory<BackendMigrator> weak_ptr_factory_; | 98 base::WeakPtrFactory<BackendMigrator> weak_ptr_factory_; |
| 102 | 99 |
| 103 DISALLOW_COPY_AND_ASSIGN(BackendMigrator); | 100 DISALLOW_COPY_AND_ASSIGN(BackendMigrator); |
| 104 }; | 101 }; |
| 105 | 102 |
| 106 } // namespace browser_sync | 103 } // namespace browser_sync |
| 107 | 104 |
| 108 #endif // CHROME_BROWSER_SYNC_BACKEND_MIGRATOR_H_ | 105 #endif // CHROME_BROWSER_SYNC_BACKEND_MIGRATOR_H_ |
| OLD | NEW |