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

Side by Side Diff: components/sync_driver/backend_migrator.h

Issue 2203673002: [Sync] Move //components/sync_driver to //components/sync/driver. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@sd-a
Patch Set: Full change rebased on static lib. Created 4 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 unified diff | Download patch
OLDNEW
(Empty)
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.
4
5 #ifndef COMPONENTS_SYNC_DRIVER_BACKEND_MIGRATOR_H_
6 #define COMPONENTS_SYNC_DRIVER_BACKEND_MIGRATOR_H_
7
8 #include <string>
9
10 #include "base/compiler_specific.h"
11 #include "base/macros.h"
12 #include "base/memory/weak_ptr.h"
13 #include "base/observer_list.h"
14 #include "components/sync/base/model_type.h"
15 #include "components/sync_driver/data_type_manager.h"
16
17 namespace syncer {
18 struct UserShare;
19 } // namespace syncer
20
21 namespace sync_driver {
22 class SyncService;
23 }
24
25 namespace browser_sync {
26
27 // Interface for anything that wants to know when the migrator's state
28 // changes.
29 class MigrationObserver {
30 public:
31 virtual void OnMigrationStateChange() = 0;
32
33 protected:
34 virtual ~MigrationObserver();
35 };
36
37 // A class to perform migration of a datatype pursuant to the 'MIGRATION_DONE'
38 // code in the sync protocol definition (protocol/sync.proto).
39 class BackendMigrator {
40 public:
41 enum State {
42 IDLE,
43 WAITING_TO_START, // Waiting for previous configuration to finish.
44 DISABLING_TYPES, // Exit criteria: SYNC_CONFIGURE_DONE for
45 // enabled types _excluding_ |to_migrate_| and
46 // empty download progress markers for types
47 // in |to_migrate_|.
48 REENABLING_TYPES, // Exit criteria: SYNC_CONFIGURE_DONE for enabled
49 // types.
50 };
51
52 // TODO(akalin): Remove the dependency on |user_share|.
53 BackendMigrator(const std::string& name,
54 syncer::UserShare* user_share,
55 sync_driver::SyncService* service,
56 sync_driver::DataTypeManager* manager,
57 const base::Closure &migration_done_callback);
58 virtual ~BackendMigrator();
59
60 // Starts a sequence of events that will disable and reenable |types|.
61 void MigrateTypes(syncer::ModelTypeSet types);
62
63 void AddMigrationObserver(MigrationObserver* observer);
64 bool HasMigrationObserver(const MigrationObserver* observer) const;
65 void RemoveMigrationObserver(MigrationObserver* observer);
66
67 State state() const;
68
69 // Called from ProfileSyncService to notify us of configure done.
70 // Note: We receive these notificiations only when our state is not IDLE.
71 void OnConfigureDone(
72 const sync_driver::DataTypeManager::ConfigureResult& result);
73
74 // Returns the types that are currently pending migration (if any).
75 syncer::ModelTypeSet GetPendingMigrationTypesForTest() const;
76
77 private:
78 void ChangeState(State new_state);
79
80 // Must be called only in state WAITING_TO_START. If ready to
81 // start, meaning the data type manager is configured, calls
82 // RestartMigration() and returns true. Otherwise, does nothing and
83 // returns false.
84 bool TryStart();
85
86 // Restarts migration, interrupting any existing migration.
87 void RestartMigration();
88
89 // Called by OnConfigureDone().
90 void OnConfigureDoneImpl(
91 const sync_driver::DataTypeManager::ConfigureResult& result);
92
93 const std::string name_;
94 syncer::UserShare* user_share_;
95 sync_driver::SyncService* service_;
96 sync_driver::DataTypeManager* manager_;
97
98 State state_;
99
100 base::ObserverList<MigrationObserver> migration_observers_;
101
102 syncer::ModelTypeSet to_migrate_;
103
104 base::Closure migration_done_callback_;
105
106 base::WeakPtrFactory<BackendMigrator> weak_ptr_factory_;
107
108 DISALLOW_COPY_AND_ASSIGN(BackendMigrator);
109 };
110
111 } // namespace browser_sync
112
113 #endif // COMPONENTS_SYNC_DRIVER_BACKEND_MIGRATOR_H_
OLDNEW
« no previous file with comments | « components/sync_driver/backend_data_type_configurer.cc ('k') | components/sync_driver/backend_migrator.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698