Home | History | Annotate | Download | only in sync
      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
      3 // found in the LICENSE file.
      4 
      5 #ifndef CHROME_BROWSER_SYNC_BACKEND_MIGRATOR_H_
      6 #define CHROME_BROWSER_SYNC_BACKEND_MIGRATOR_H_
      7 
      8 #include "base/task.h"
      9 #include "chrome/browser/sync/profile_sync_service_observer.h"
     10 #include "chrome/browser/sync/syncable/model_type.h"
     11 #include "content/common/notification_observer.h"
     12 #include "content/common/notification_registrar.h"
     13 
     14 class ProfileSyncService;
     15 
     16 namespace browser_sync {
     17 
     18 class DataTypeManager;
     19 
     20 // A class to perform migration of a datatype pursuant to the 'MIGRATION_DONE'
     21 // code in the sync protocol definition (protocol/sync.proto).
     22 class BackendMigrator : public NotificationObserver,
     23                         public ProfileSyncServiceObserver {
     24  public:
     25   enum State {
     26     IDLE,
     27     WAITING_TO_START,   // Waiting for previous configuration to finish.
     28     DISABLING_TYPES,    // Exit criteria: SYNC_CONFIGURE_DONE for enabled
     29                         // types _excluding_ |to_migrate_|.
     30     WAITING_FOR_PURGE,  // Exit criteria: SyncCycleEnded for enabled types
     31                         // excluding |to_migrate|
     32     REENABLING_TYPES,   // Exit criteria: SYNC_CONFIGURE_DONE for enabled
     33                         // types.
     34   };
     35 
     36   BackendMigrator(ProfileSyncService* service, DataTypeManager* manager);
     37   virtual ~BackendMigrator();
     38 
     39   // Starts a sequence of events that will disable and reenable |types|.
     40   void MigrateTypes(const syncable::ModelTypeSet& types);
     41 
     42   // ProfileSyncServiceObserver implementation.
     43   virtual void OnStateChanged();
     44 
     45   // NotificationObserver implementation.
     46   virtual void Observe(NotificationType type,
     47                        const NotificationSource& source,
     48                        const NotificationDetails& details);
     49 
     50   State state() const;
     51 
     52  private:
     53   bool HasStartedMigrating() const;
     54 
     55   State state_;
     56   ProfileSyncService* service_;
     57   DataTypeManager* manager_;
     58   NotificationRegistrar registrar_;
     59 
     60   syncable::ModelTypeSet to_migrate_;
     61   bool restart_migration_;
     62 
     63   // We use this to gracefully re-start migrations.
     64   ScopedRunnableMethodFactory<BackendMigrator> method_factory_;
     65 
     66   DISALLOW_COPY_AND_ASSIGN(BackendMigrator);
     67 };
     68 
     69 }  // namespace browser_sync
     70 
     71 #endif  // CHROME_BROWSER_SYNC_BACKEND_MIGRATOR_H_
     72