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.
5 #ifndef CHROME_BROWSER_SYNC_BACKEND_MIGRATOR_H_
6 #define CHROME_BROWSER_SYNC_BACKEND_MIGRATOR_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"
14 class ProfileSyncService
;
16 namespace browser_sync
{
18 class DataTypeManager
;
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
{
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
36 BackendMigrator(ProfileSyncService
* service
, DataTypeManager
* manager
);
37 virtual ~BackendMigrator();
39 // Starts a sequence of events that will disable and reenable |types|.
40 void MigrateTypes(const syncable::ModelTypeSet
& types
);
42 // ProfileSyncServiceObserver implementation.
43 virtual void OnStateChanged();
45 // NotificationObserver implementation.
46 virtual void Observe(NotificationType type
,
47 const NotificationSource
& source
,
48 const NotificationDetails
& details
);
53 bool HasStartedMigrating() const;
56 ProfileSyncService
* service_
;
57 DataTypeManager
* manager_
;
58 NotificationRegistrar registrar_
;
60 syncable::ModelTypeSet to_migrate_
;
61 bool restart_migration_
;
63 // We use this to gracefully re-start migrations.
64 ScopedRunnableMethodFactory
<BackendMigrator
> method_factory_
;
66 DISALLOW_COPY_AND_ASSIGN(BackendMigrator
);
69 } // namespace browser_sync
71 #endif // CHROME_BROWSER_SYNC_BACKEND_MIGRATOR_H_