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

Side by Side Diff: components/sync/driver/backend_migrator.h

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

Powered by Google App Engine
This is Rietveld 408576698