Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(25)

Side by Side Diff: chrome/browser/sync/backend_migrator.h

Issue 7655055: [Sync] Make BackendMigrator not wait for full sync cycles (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix mac test Created 9 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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"
10 #include "base/observer_list.h"
8 #include "base/task.h" 11 #include "base/task.h"
9 #include "chrome/browser/sync/profile_sync_service_observer.h" 12 #include "chrome/browser/sync/glue/data_type_manager.h"
10 #include "chrome/browser/sync/syncable/model_type.h" 13 #include "chrome/browser/sync/syncable/model_type.h"
11 #include "content/common/notification_observer.h" 14 #include "content/common/notification_observer.h"
12 #include "content/common/notification_registrar.h" 15 #include "content/common/notification_registrar.h"
13 16
14 class ProfileSyncService; 17 class ProfileSyncService;
15 18
16 namespace browser_sync { 19 namespace browser_sync {
17 20
18 class DataTypeManager; 21 // Interface for anything that wants to know when the migrator's state
22 // changes.
23 class MigrationObserver {
24 public:
25 virtual void OnMigrationStateChange() = 0;
26
27 protected:
28 virtual ~MigrationObserver();
29 };
19 30
20 // A class to perform migration of a datatype pursuant to the 'MIGRATION_DONE' 31 // A class to perform migration of a datatype pursuant to the 'MIGRATION_DONE'
21 // code in the sync protocol definition (protocol/sync.proto). 32 // code in the sync protocol definition (protocol/sync.proto).
22 class BackendMigrator : public NotificationObserver, 33 class BackendMigrator : public NotificationObserver {
23 public ProfileSyncServiceObserver {
24 public: 34 public:
25 enum State { 35 enum State {
26 IDLE, 36 IDLE,
27 WAITING_TO_START, // Waiting for previous configuration to finish. 37 WAITING_TO_START, // Waiting for previous configuration to finish.
28 DISABLING_TYPES, // Exit criteria: SYNC_CONFIGURE_DONE for enabled 38 DISABLING_TYPES, // Exit criteria: SYNC_CONFIGURE_DONE for
29 // types _excluding_ |to_migrate_|. 39 // enabled types _excluding_ |to_migrate_| and
30 WAITING_FOR_PURGE, // Exit criteria: SyncCycleEnded for enabled types 40 // empty download progress markers for types
31 // excluding |to_migrate| 41 // in |to_migrate_|.
32 REENABLING_TYPES, // Exit criteria: SYNC_CONFIGURE_DONE for enabled 42 REENABLING_TYPES, // Exit criteria: SYNC_CONFIGURE_DONE for enabled
33 // types. 43 // types.
34 }; 44 };
35 45
36 BackendMigrator(ProfileSyncService* service, DataTypeManager* manager); 46 BackendMigrator(const std::string& name,
47 ProfileSyncService* service, DataTypeManager* manager);
37 virtual ~BackendMigrator(); 48 virtual ~BackendMigrator();
38 49
39 // Starts a sequence of events that will disable and reenable |types|. 50 // Starts a sequence of events that will disable and reenable |types|.
40 void MigrateTypes(const syncable::ModelTypeSet& types); 51 void MigrateTypes(const syncable::ModelTypeSet& types);
41 52
42 // ProfileSyncServiceObserver implementation. 53 void AddMigrationObserver(MigrationObserver* observer);
43 virtual void OnStateChanged(); 54 void RemoveMigrationObserver(MigrationObserver* observer);
44 55
45 // NotificationObserver implementation. 56 // NotificationObserver implementation.
46 virtual void Observe(int type, 57 virtual void Observe(int type,
47 const NotificationSource& source, 58 const NotificationSource& source,
48 const NotificationDetails& details); 59 const NotificationDetails& details) OVERRIDE;
49 60
50 State state() const; 61 State state() const;
51 62
63 // Returns the types that are currently pending migration (if any).
64 syncable::ModelTypeSet GetPendingMigrationTypesForTest() const;
65
52 private: 66 private:
53 bool HasStartedMigrating() const; 67 void ChangeState(State new_state);
54 68
69 // Must be called only in state WAITING_TO_START. If ready to
70 // start, meaning the data type manager is configured, calls
71 // RestartMigration() and returns true. Otherwise, does nothing and
72 // returns false.
73 bool TryStart();
74
75 // Restarts migration, interrupting any existing migration.
76 void RestartMigration();
77
78 // Called by Observe().
79 void OnConfigureDone(const DataTypeManager::ConfigureResult& result);
80
81 const std::string name_;
55 State state_; 82 State state_;
56 ProfileSyncService* service_; 83 ProfileSyncService* service_;
57 DataTypeManager* manager_; 84 DataTypeManager* manager_;
58 NotificationRegistrar registrar_; 85 NotificationRegistrar registrar_;
59 86
87 ObserverList<MigrationObserver> migration_observers_;
88
60 syncable::ModelTypeSet to_migrate_; 89 syncable::ModelTypeSet to_migrate_;
61 bool restart_migration_;
62 90
63 // We use this to gracefully re-start migrations. 91 base::WeakPtrFactory<BackendMigrator> weak_ptr_factory_;
64 ScopedRunnableMethodFactory<BackendMigrator> method_factory_;
65 92
66 DISALLOW_COPY_AND_ASSIGN(BackendMigrator); 93 DISALLOW_COPY_AND_ASSIGN(BackendMigrator);
67 }; 94 };
68 95
69 } // namespace browser_sync 96 } // namespace browser_sync
70 97
71 #endif // CHROME_BROWSER_SYNC_BACKEND_MIGRATOR_H_ 98 #endif // CHROME_BROWSER_SYNC_BACKEND_MIGRATOR_H_
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/sync/backend_migrator.cc » ('j') | chrome/browser/sync/glue/data_type_manager_impl.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698