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 #include "chrome/browser/sync/backend_migrator.h" | 5 #include "chrome/browser/sync/backend_migrator.h" |
6 | 6 |
7 #include "base/message_loop.h" | 7 #include "base/message_loop.h" |
8 #include "base/string_number_conversions.h" | 8 #include "base/string_number_conversions.h" |
9 #include "base/tracked_objects.h" | 9 #include "base/tracked_objects.h" |
10 #include "chrome/browser/sync/internal_api/configure_reason.h" | 10 #include "chrome/browser/sync/internal_api/configure_reason.h" |
(...skipping 10 matching lines...) Expand all Loading... |
21 namespace browser_sync { | 21 namespace browser_sync { |
22 | 22 |
23 using sessions::SyncSessionSnapshot; | 23 using sessions::SyncSessionSnapshot; |
24 using syncable::ModelTypeToString; | 24 using syncable::ModelTypeToString; |
25 | 25 |
26 MigrationObserver::~MigrationObserver() {} | 26 MigrationObserver::~MigrationObserver() {} |
27 | 27 |
28 BackendMigrator::BackendMigrator(const std::string& name, | 28 BackendMigrator::BackendMigrator(const std::string& name, |
29 sync_api::UserShare* user_share, | 29 sync_api::UserShare* user_share, |
30 ProfileSyncService* service, | 30 ProfileSyncService* service, |
31 DataTypeManager* manager) | 31 DataTypeManager* manager, |
| 32 const base::Closure &migration_done_callback) |
32 : name_(name), user_share_(user_share), service_(service), | 33 : name_(name), user_share_(user_share), service_(service), |
33 manager_(manager), state_(IDLE), | 34 manager_(manager), state_(IDLE), |
34 weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { | 35 weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), |
35 registrar_.Add(this, chrome::NOTIFICATION_SYNC_CONFIGURE_DONE, | 36 migration_done_callback_(migration_done_callback) { |
36 content::Source<DataTypeManager>(manager_)); | |
37 } | 37 } |
38 | 38 |
39 BackendMigrator::~BackendMigrator() { | 39 BackendMigrator::~BackendMigrator() { |
40 } | 40 } |
41 | 41 |
42 // Helper macros to log with the syncer thread name; useful when there | 42 // Helper macros to log with the syncer thread name; useful when there |
43 // are multiple syncer threads involved. | 43 // are multiple syncer threads involved. |
44 | 44 |
45 #define SLOG(severity) LOG(severity) << name_ << ": " | 45 #define SLOG(severity) LOG(severity) << name_ << ": " |
46 | 46 |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
113 // Add nigori for config or not based upon if the server told us to migrate | 113 // Add nigori for config or not based upon if the server told us to migrate |
114 // nigori or not. | 114 // nigori or not. |
115 if (configure_with_nigori) { | 115 if (configure_with_nigori) { |
116 manager_->Configure(difference, sync_api::CONFIGURE_REASON_MIGRATION); | 116 manager_->Configure(difference, sync_api::CONFIGURE_REASON_MIGRATION); |
117 } else { | 117 } else { |
118 manager_->ConfigureWithoutNigori(difference, | 118 manager_->ConfigureWithoutNigori(difference, |
119 sync_api::CONFIGURE_REASON_MIGRATION); | 119 sync_api::CONFIGURE_REASON_MIGRATION); |
120 } | 120 } |
121 } | 121 } |
122 | 122 |
123 void BackendMigrator::Observe(int type, | 123 void BackendMigrator::OnConfigureDone( |
124 const content::NotificationSource& source, | 124 const DataTypeManager::ConfigureResult& result) { |
125 const content::NotificationDetails& details) { | |
126 DCHECK_EQ(chrome::NOTIFICATION_SYNC_CONFIGURE_DONE, type); | |
127 if (state_ == IDLE) | 125 if (state_ == IDLE) |
128 return; | 126 return; |
129 | 127 |
130 // |manager_|'s methods aren't re-entrant, and we're notified from | 128 // |manager_|'s methods aren't re-entrant, and we're notified from |
131 // them, so post a task to avoid problems. | 129 // them, so post a task to avoid problems. |
132 SDVLOG(1) << "Posting OnConfigureDone from Observer"; | 130 SDVLOG(1) << "Posting OnConfigureDoneImpl"; |
133 MessageLoop::current()->PostTask( | 131 MessageLoop::current()->PostTask( |
134 FROM_HERE, | 132 FROM_HERE, |
135 base::Bind(&BackendMigrator::OnConfigureDone, | 133 base::Bind(&BackendMigrator::OnConfigureDoneImpl, |
136 weak_ptr_factory_.GetWeakPtr(), | 134 weak_ptr_factory_.GetWeakPtr(), result)); |
137 *content::Details<DataTypeManager::ConfigureResult>( | |
138 details).ptr())); | |
139 } | 135 } |
140 | 136 |
141 namespace { | 137 namespace { |
142 | 138 |
143 syncable::ModelTypeSet GetUnsyncedDataTypes(sync_api::UserShare* user_share) { | 139 syncable::ModelTypeSet GetUnsyncedDataTypes(sync_api::UserShare* user_share) { |
144 sync_api::ReadTransaction trans(FROM_HERE, user_share); | 140 sync_api::ReadTransaction trans(FROM_HERE, user_share); |
145 syncable::ModelTypeSet unsynced_data_types; | 141 syncable::ModelTypeSet unsynced_data_types; |
146 for (int i = syncable::FIRST_REAL_MODEL_TYPE; | 142 for (int i = syncable::FIRST_REAL_MODEL_TYPE; |
147 i < syncable::MODEL_TYPE_COUNT; ++i) { | 143 i < syncable::MODEL_TYPE_COUNT; ++i) { |
148 syncable::ModelType type = syncable::ModelTypeFromInt(i); | 144 syncable::ModelType type = syncable::ModelTypeFromInt(i); |
149 sync_pb::DataTypeProgressMarker progress_marker; | 145 sync_pb::DataTypeProgressMarker progress_marker; |
150 trans.GetDirectory()->GetDownloadProgress(type, &progress_marker); | 146 trans.GetDirectory()->GetDownloadProgress(type, &progress_marker); |
151 if (progress_marker.token().empty()) { | 147 if (progress_marker.token().empty()) { |
152 unsynced_data_types.Put(type); | 148 unsynced_data_types.Put(type); |
153 } | 149 } |
154 } | 150 } |
155 return unsynced_data_types; | 151 return unsynced_data_types; |
156 } | 152 } |
157 | 153 |
158 } // namespace | 154 } // namespace |
159 | 155 |
160 void BackendMigrator::OnConfigureDone( | 156 void BackendMigrator::OnConfigureDoneImpl( |
161 const DataTypeManager::ConfigureResult& result) { | 157 const DataTypeManager::ConfigureResult& result) { |
162 SDVLOG(1) << "OnConfigureDone with requested types " | 158 SDVLOG(1) << "OnConfigureDone with requested types " |
163 << ModelTypeSetToString(result.requested_types) | 159 << ModelTypeSetToString(result.requested_types) |
164 << ", status " << result.status | 160 << ", status " << result.status |
165 << ", and to_migrate_ = " << ModelTypeSetToString(to_migrate_); | 161 << ", and to_migrate_ = " << ModelTypeSetToString(to_migrate_); |
166 if (state_ == WAITING_TO_START) { | 162 if (state_ == WAITING_TO_START) { |
167 if (!TryStart()) | 163 if (!TryStart()) |
168 SDVLOG(1) << "Manager still not configured; still waiting"; | 164 SDVLOG(1) << "Manager still not configured; still waiting"; |
169 return; | 165 return; |
170 } | 166 } |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
214 SDVLOG(1) << "BackendMigrator re-enabling types: " | 210 SDVLOG(1) << "BackendMigrator re-enabling types: " |
215 << syncable::ModelTypeSetToString(full_set); | 211 << syncable::ModelTypeSetToString(full_set); |
216 manager_->Configure(full_set, sync_api::CONFIGURE_REASON_MIGRATION); | 212 manager_->Configure(full_set, sync_api::CONFIGURE_REASON_MIGRATION); |
217 } else if (state_ == REENABLING_TYPES) { | 213 } else if (state_ == REENABLING_TYPES) { |
218 // We're done! | 214 // We're done! |
219 ChangeState(IDLE); | 215 ChangeState(IDLE); |
220 | 216 |
221 SDVLOG(1) << "BackendMigrator: Migration complete for: " | 217 SDVLOG(1) << "BackendMigrator: Migration complete for: " |
222 << syncable::ModelTypeSetToString(to_migrate_); | 218 << syncable::ModelTypeSetToString(to_migrate_); |
223 to_migrate_.Clear(); | 219 to_migrate_.Clear(); |
| 220 |
| 221 if (!migration_done_callback_.is_null()) |
| 222 migration_done_callback_.Run(); |
224 } | 223 } |
225 } | 224 } |
226 | 225 |
227 BackendMigrator::State BackendMigrator::state() const { | 226 BackendMigrator::State BackendMigrator::state() const { |
228 return state_; | 227 return state_; |
229 } | 228 } |
230 | 229 |
231 syncable::ModelTypeSet | 230 syncable::ModelTypeSet |
232 BackendMigrator::GetPendingMigrationTypesForTest() const { | 231 BackendMigrator::GetPendingMigrationTypesForTest() const { |
233 return to_migrate_; | 232 return to_migrate_; |
234 } | 233 } |
235 | 234 |
236 #undef SDVLOG | 235 #undef SDVLOG |
237 | 236 |
238 #undef SLOG | 237 #undef SLOG |
239 | 238 |
240 }; // namespace browser_sync | 239 }; // namespace browser_sync |
OLD | NEW |