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

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: Cleanup 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
19 namespace sync_api {
20 struct UserShare;
21 } // namespace sync_api
22
16 namespace browser_sync { 23 namespace browser_sync {
17 24
18 class DataTypeManager; 25 // Interface for anything that wants to know when the migrator's state
26 // changes.
27 class MigrationObserver {
28 public:
29 virtual void OnMigrationStateChange() = 0;
30
31 protected:
32 virtual ~MigrationObserver();
33 };
19 34
20 // A class to perform migration of a datatype pursuant to the 'MIGRATION_DONE' 35 // A class to perform migration of a datatype pursuant to the 'MIGRATION_DONE'
21 // code in the sync protocol definition (protocol/sync.proto). 36 // code in the sync protocol definition (protocol/sync.proto).
22 class BackendMigrator : public NotificationObserver, 37 class BackendMigrator : public NotificationObserver {
23 public ProfileSyncServiceObserver {
24 public: 38 public:
25 enum State { 39 enum State {
26 IDLE, 40 IDLE,
27 WAITING_TO_START, // Waiting for previous configuration to finish. 41 WAITING_TO_START, // Waiting for previous configuration to finish.
28 DISABLING_TYPES, // Exit criteria: SYNC_CONFIGURE_DONE for enabled 42 DISABLING_TYPES, // Exit criteria: SYNC_CONFIGURE_DONE for
29 // types _excluding_ |to_migrate_|. 43 // enabled types _excluding_ |to_migrate_| and
30 WAITING_FOR_PURGE, // Exit criteria: SyncCycleEnded for enabled types 44 // empty download progress markers for types
31 // excluding |to_migrate| 45 // in |to_migrate_|.
32 REENABLING_TYPES, // Exit criteria: SYNC_CONFIGURE_DONE for enabled 46 REENABLING_TYPES, // Exit criteria: SYNC_CONFIGURE_DONE for enabled
33 // types. 47 // types.
34 }; 48 };
35 49
36 BackendMigrator(ProfileSyncService* service, DataTypeManager* manager); 50 BackendMigrator(const std::string& name,
51 sync_api::UserShare* user_share,
52 ProfileSyncService* service,
53 DataTypeManager* manager);
37 virtual ~BackendMigrator(); 54 virtual ~BackendMigrator();
38 55
39 // Starts a sequence of events that will disable and reenable |types|. 56 // Starts a sequence of events that will disable and reenable |types|.
40 void MigrateTypes(const syncable::ModelTypeSet& types); 57 void MigrateTypes(const syncable::ModelTypeSet& types);
41 58
42 // ProfileSyncServiceObserver implementation. 59 void AddMigrationObserver(MigrationObserver* observer);
43 virtual void OnStateChanged(); 60 void RemoveMigrationObserver(MigrationObserver* observer);
44 61
45 // NotificationObserver implementation. 62 // NotificationObserver implementation.
46 virtual void Observe(int type, 63 virtual void Observe(int type,
47 const NotificationSource& source, 64 const NotificationSource& source,
48 const NotificationDetails& details); 65 const NotificationDetails& details) OVERRIDE;
49 66
50 State state() const; 67 State state() const;
51 68
69 // Returns the types that are currently pending migration (if any).
70 syncable::ModelTypeSet GetPendingMigrationTypesForTest() const;
71
52 private: 72 private:
53 bool HasStartedMigrating() const; 73 void ChangeState(State new_state);
74
75 // Must be called only in state WAITING_TO_START. If ready to
76 // start, meaning the data type manager is configured, calls
77 // RestartMigration() and returns true. Otherwise, does nothing and
78 // returns false.
79 bool TryStart();
80
81 // Restarts migration, interrupting any existing migration.
82 void RestartMigration();
83
84 // Called by Observe().
85 void OnConfigureDone(const DataTypeManager::ConfigureResult& result);
86
87 const std::string name_;
88 sync_api::UserShare* user_share_;
89 ProfileSyncService* service_;
90 DataTypeManager* manager_;
54 91
55 State state_; 92 State state_;
56 ProfileSyncService* service_; 93
57 DataTypeManager* manager_;
58 NotificationRegistrar registrar_; 94 NotificationRegistrar registrar_;
59 95
96 ObserverList<MigrationObserver> migration_observers_;
97
60 syncable::ModelTypeSet to_migrate_; 98 syncable::ModelTypeSet to_migrate_;
61 bool restart_migration_;
62 99
63 // We use this to gracefully re-start migrations. 100 base::WeakPtrFactory<BackendMigrator> weak_ptr_factory_;
64 ScopedRunnableMethodFactory<BackendMigrator> method_factory_;
65 101
66 DISALLOW_COPY_AND_ASSIGN(BackendMigrator); 102 DISALLOW_COPY_AND_ASSIGN(BackendMigrator);
67 }; 103 };
68 104
69 } // namespace browser_sync 105 } // namespace browser_sync
70 106
71 #endif // CHROME_BROWSER_SYNC_BACKEND_MIGRATOR_H_ 107 #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/backend_migrator.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698