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