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

Unified 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: Address more comments Created 9 years, 4 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | chrome/browser/sync/backend_migrator.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/sync/backend_migrator.h
diff --git a/chrome/browser/sync/backend_migrator.h b/chrome/browser/sync/backend_migrator.h
index d3314aa94f0ff19674a04de6f9aac5c147a33683..d1c409d6d93b405ad50bc5e426de9c76d11da4da 100644
--- a/chrome/browser/sync/backend_migrator.h
+++ b/chrome/browser/sync/backend_migrator.h
@@ -5,63 +5,101 @@
#ifndef CHROME_BROWSER_SYNC_BACKEND_MIGRATOR_H_
#define CHROME_BROWSER_SYNC_BACKEND_MIGRATOR_H_
+#include "base/compiler_specific.h"
+#include "base/memory/weak_ptr.h"
+#include "base/observer_list.h"
#include "base/task.h"
-#include "chrome/browser/sync/profile_sync_service_observer.h"
+#include "chrome/browser/sync/glue/data_type_manager.h"
#include "chrome/browser/sync/syncable/model_type.h"
#include "content/common/notification_observer.h"
#include "content/common/notification_registrar.h"
class ProfileSyncService;
+namespace sync_api {
+struct UserShare;
+} // namespace sync_api
+
namespace browser_sync {
-class DataTypeManager;
+// Interface for anything that wants to know when the migrator's state
+// changes.
+class MigrationObserver {
+ public:
+ virtual void OnMigrationStateChange() = 0;
+
+ protected:
+ virtual ~MigrationObserver();
+};
// A class to perform migration of a datatype pursuant to the 'MIGRATION_DONE'
// code in the sync protocol definition (protocol/sync.proto).
-class BackendMigrator : public NotificationObserver,
- public ProfileSyncServiceObserver {
+class BackendMigrator : public NotificationObserver {
public:
enum State {
IDLE,
WAITING_TO_START, // Waiting for previous configuration to finish.
- DISABLING_TYPES, // Exit criteria: SYNC_CONFIGURE_DONE for enabled
- // types _excluding_ |to_migrate_|.
- WAITING_FOR_PURGE, // Exit criteria: SyncCycleEnded for enabled types
- // excluding |to_migrate|
+ DISABLING_TYPES, // Exit criteria: SYNC_CONFIGURE_DONE for
+ // enabled types _excluding_ |to_migrate_| and
+ // empty download progress markers for types
+ // in |to_migrate_|.
REENABLING_TYPES, // Exit criteria: SYNC_CONFIGURE_DONE for enabled
// types.
};
- BackendMigrator(ProfileSyncService* service, DataTypeManager* manager);
+ // TODO(akalin): Remove the dependency on |user_share|.
+ BackendMigrator(const std::string& name,
+ sync_api::UserShare* user_share,
+ ProfileSyncService* service,
+ DataTypeManager* manager);
virtual ~BackendMigrator();
// Starts a sequence of events that will disable and reenable |types|.
void MigrateTypes(const syncable::ModelTypeSet& types);
- // ProfileSyncServiceObserver implementation.
- virtual void OnStateChanged();
+ void AddMigrationObserver(MigrationObserver* observer);
+ bool HasMigrationObserver(MigrationObserver* observer) const;
+ void RemoveMigrationObserver(MigrationObserver* observer);
// NotificationObserver implementation.
virtual void Observe(int type,
const NotificationSource& source,
- const NotificationDetails& details);
+ const NotificationDetails& details) OVERRIDE;
State state() const;
+ // Returns the types that are currently pending migration (if any).
+ syncable::ModelTypeSet GetPendingMigrationTypesForTest() const;
+
private:
- bool HasStartedMigrating() const;
+ void ChangeState(State new_state);
- State state_;
+ // Must be called only in state WAITING_TO_START. If ready to
+ // start, meaning the data type manager is configured, calls
+ // RestartMigration() and returns true. Otherwise, does nothing and
+ // returns false.
+ bool TryStart();
+
+ // Restarts migration, interrupting any existing migration.
+ void RestartMigration();
+
+ // Called by Observe().
+ void OnConfigureDone(const DataTypeManager::ConfigureResult& result);
+
+ const std::string name_;
+ sync_api::UserShare* user_share_;
ProfileSyncService* service_;
DataTypeManager* manager_;
+
+ State state_;
+
NotificationRegistrar registrar_;
+ ObserverList<MigrationObserver> migration_observers_;
+
syncable::ModelTypeSet to_migrate_;
- bool restart_migration_;
- // We use this to gracefully re-start migrations.
- ScopedRunnableMethodFactory<BackendMigrator> method_factory_;
+ base::WeakPtrFactory<BackendMigrator> weak_ptr_factory_;
DISALLOW_COPY_AND_ASSIGN(BackendMigrator);
};
« no previous file with comments | « no previous file | chrome/browser/sync/backend_migrator.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698