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