1. Token CRCs are not handled correctly. This adds the corrected Whispernet binary...
[chromium-blink-merge.git] / chrome / browser / sync / backend_migrator.h
blob64bce1a2234c1b6a9d8c46276e4ad80a2e2ab1e0
1 // Copyright (c) 2012 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_
8 #include "base/compiler_specific.h"
9 #include "base/memory/weak_ptr.h"
10 #include "base/observer_list.h"
11 #include "components/sync_driver/data_type_manager.h"
12 #include "content/public/browser/notification_observer.h"
13 #include "content/public/browser/notification_registrar.h"
14 #include "sync/internal_api/public/base/model_type.h"
16 class ProfileSyncService;
18 namespace syncer {
19 struct UserShare;
20 } // namespace syncer
22 namespace browser_sync {
24 // Interface for anything that wants to know when the migrator's state
25 // changes.
26 class MigrationObserver {
27 public:
28 virtual void OnMigrationStateChange() = 0;
30 protected:
31 virtual ~MigrationObserver();
34 // A class to perform migration of a datatype pursuant to the 'MIGRATION_DONE'
35 // code in the sync protocol definition (protocol/sync.proto).
36 class BackendMigrator {
37 public:
38 enum State {
39 IDLE,
40 WAITING_TO_START, // Waiting for previous configuration to finish.
41 DISABLING_TYPES, // Exit criteria: SYNC_CONFIGURE_DONE for
42 // enabled types _excluding_ |to_migrate_| and
43 // empty download progress markers for types
44 // in |to_migrate_|.
45 REENABLING_TYPES, // Exit criteria: SYNC_CONFIGURE_DONE for enabled
46 // types.
49 // TODO(akalin): Remove the dependency on |user_share|.
50 BackendMigrator(const std::string& name,
51 syncer::UserShare* user_share,
52 ProfileSyncService* service,
53 sync_driver::DataTypeManager* manager,
54 const base::Closure &migration_done_callback);
55 virtual ~BackendMigrator();
57 // Starts a sequence of events that will disable and reenable |types|.
58 void MigrateTypes(syncer::ModelTypeSet types);
60 void AddMigrationObserver(MigrationObserver* observer);
61 bool HasMigrationObserver(const MigrationObserver* observer) const;
62 void RemoveMigrationObserver(MigrationObserver* observer);
64 State state() const;
66 // Called from ProfileSyncService to notify us of configure done.
67 // Note: We receive these notificiations only when our state is not IDLE.
68 void OnConfigureDone(
69 const sync_driver::DataTypeManager::ConfigureResult& result);
71 // Returns the types that are currently pending migration (if any).
72 syncer::ModelTypeSet GetPendingMigrationTypesForTest() const;
74 private:
75 void ChangeState(State new_state);
77 // Must be called only in state WAITING_TO_START. If ready to
78 // start, meaning the data type manager is configured, calls
79 // RestartMigration() and returns true. Otherwise, does nothing and
80 // returns false.
81 bool TryStart();
83 // Restarts migration, interrupting any existing migration.
84 void RestartMigration();
86 // Called by OnConfigureDone().
87 void OnConfigureDoneImpl(
88 const sync_driver::DataTypeManager::ConfigureResult& result);
90 const std::string name_;
91 syncer::UserShare* user_share_;
92 ProfileSyncService* service_;
93 sync_driver::DataTypeManager* manager_;
95 State state_;
97 ObserverList<MigrationObserver> migration_observers_;
99 syncer::ModelTypeSet to_migrate_;
101 base::Closure migration_done_callback_;
103 base::WeakPtrFactory<BackendMigrator> weak_ptr_factory_;
105 DISALLOW_COPY_AND_ASSIGN(BackendMigrator);
108 } // namespace browser_sync
110 #endif // CHROME_BROWSER_SYNC_BACKEND_MIGRATOR_H_