| 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/profile_sync_service.h" | 10 #include "chrome/browser/sync/profile_sync_service.h" |
| 11 #include "chrome/common/chrome_notification_types.h" | 11 #include "chrome/common/chrome_notification_types.h" |
| 12 #include "content/public/browser/notification_details.h" | 12 #include "content/public/browser/notification_details.h" |
| 13 #include "content/public/browser/notification_source.h" | 13 #include "content/public/browser/notification_source.h" |
| 14 #include "sync/internal_api/public/configure_reason.h" | 14 #include "sync/internal_api/public/configure_reason.h" |
| 15 #include "sync/internal_api/public/read_transaction.h" | 15 #include "sync/internal_api/public/read_transaction.h" |
| 16 #include "sync/protocol/sync.pb.h" | 16 #include "sync/protocol/sync.pb.h" |
| 17 #include "sync/syncable/directory.h" // TODO(tim): Bug 131130. | 17 #include "sync/syncable/directory.h" // TODO(tim): Bug 131130. |
| 18 | 18 |
| 19 using syncable::ModelTypeSet; | 19 using syncable::ModelTypeSet; |
| 20 | 20 |
| 21 namespace browser_sync { | 21 namespace browser_sync { |
| 22 | 22 |
| 23 using syncable::ModelTypeToString; | 23 using syncable::ModelTypeToString; |
| 24 | 24 |
| 25 MigrationObserver::~MigrationObserver() {} | 25 MigrationObserver::~MigrationObserver() {} |
| 26 | 26 |
| 27 BackendMigrator::BackendMigrator(const std::string& name, | 27 BackendMigrator::BackendMigrator(const std::string& name, |
| 28 csync::UserShare* user_share, | 28 syncer::UserShare* user_share, |
| 29 ProfileSyncService* service, | 29 ProfileSyncService* service, |
| 30 DataTypeManager* manager, | 30 DataTypeManager* manager, |
| 31 const base::Closure &migration_done_callback) | 31 const base::Closure &migration_done_callback) |
| 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 migration_done_callback_(migration_done_callback) { | 35 migration_done_callback_(migration_done_callback) { |
| 36 } | 36 } |
| 37 | 37 |
| 38 BackendMigrator::~BackendMigrator() { | 38 BackendMigrator::~BackendMigrator() { |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 105 const ModelTypeSet difference = Difference(full_set, to_migrate_); | 105 const ModelTypeSet difference = Difference(full_set, to_migrate_); |
| 106 bool configure_with_nigori = !to_migrate_.Has(syncable::NIGORI); | 106 bool configure_with_nigori = !to_migrate_.Has(syncable::NIGORI); |
| 107 SDVLOG(1) << "BackendMigrator disabling types " | 107 SDVLOG(1) << "BackendMigrator disabling types " |
| 108 << ModelTypeSetToString(to_migrate_) << "; configuring " | 108 << ModelTypeSetToString(to_migrate_) << "; configuring " |
| 109 << ModelTypeSetToString(difference) | 109 << ModelTypeSetToString(difference) |
| 110 << (configure_with_nigori ? " with nigori" : " without nigori"); | 110 << (configure_with_nigori ? " with nigori" : " without nigori"); |
| 111 | 111 |
| 112 // Add nigori for config or not based upon if the server told us to migrate | 112 // Add nigori for config or not based upon if the server told us to migrate |
| 113 // nigori or not. | 113 // nigori or not. |
| 114 if (configure_with_nigori) { | 114 if (configure_with_nigori) { |
| 115 manager_->Configure(difference, csync::CONFIGURE_REASON_MIGRATION); | 115 manager_->Configure(difference, syncer::CONFIGURE_REASON_MIGRATION); |
| 116 } else { | 116 } else { |
| 117 manager_->ConfigureWithoutNigori(difference, | 117 manager_->ConfigureWithoutNigori(difference, |
| 118 csync::CONFIGURE_REASON_MIGRATION); | 118 syncer::CONFIGURE_REASON_MIGRATION); |
| 119 } | 119 } |
| 120 } | 120 } |
| 121 | 121 |
| 122 void BackendMigrator::OnConfigureDone( | 122 void BackendMigrator::OnConfigureDone( |
| 123 const DataTypeManager::ConfigureResult& result) { | 123 const DataTypeManager::ConfigureResult& result) { |
| 124 if (state_ == IDLE) | 124 if (state_ == IDLE) |
| 125 return; | 125 return; |
| 126 | 126 |
| 127 // |manager_|'s methods aren't re-entrant, and we're notified from | 127 // |manager_|'s methods aren't re-entrant, and we're notified from |
| 128 // them, so post a task to avoid problems. | 128 // them, so post a task to avoid problems. |
| 129 SDVLOG(1) << "Posting OnConfigureDoneImpl"; | 129 SDVLOG(1) << "Posting OnConfigureDoneImpl"; |
| 130 MessageLoop::current()->PostTask( | 130 MessageLoop::current()->PostTask( |
| 131 FROM_HERE, | 131 FROM_HERE, |
| 132 base::Bind(&BackendMigrator::OnConfigureDoneImpl, | 132 base::Bind(&BackendMigrator::OnConfigureDoneImpl, |
| 133 weak_ptr_factory_.GetWeakPtr(), result)); | 133 weak_ptr_factory_.GetWeakPtr(), result)); |
| 134 } | 134 } |
| 135 | 135 |
| 136 namespace { | 136 namespace { |
| 137 | 137 |
| 138 syncable::ModelTypeSet GetUnsyncedDataTypes(csync::UserShare* user_share) { | 138 syncable::ModelTypeSet GetUnsyncedDataTypes(syncer::UserShare* user_share) { |
| 139 csync::ReadTransaction trans(FROM_HERE, user_share); | 139 syncer::ReadTransaction trans(FROM_HERE, user_share); |
| 140 syncable::ModelTypeSet unsynced_data_types; | 140 syncable::ModelTypeSet unsynced_data_types; |
| 141 for (int i = syncable::FIRST_REAL_MODEL_TYPE; | 141 for (int i = syncable::FIRST_REAL_MODEL_TYPE; |
| 142 i < syncable::MODEL_TYPE_COUNT; ++i) { | 142 i < syncable::MODEL_TYPE_COUNT; ++i) { |
| 143 syncable::ModelType type = syncable::ModelTypeFromInt(i); | 143 syncable::ModelType type = syncable::ModelTypeFromInt(i); |
| 144 sync_pb::DataTypeProgressMarker progress_marker; | 144 sync_pb::DataTypeProgressMarker progress_marker; |
| 145 trans.GetDirectory()->GetDownloadProgress(type, &progress_marker); | 145 trans.GetDirectory()->GetDownloadProgress(type, &progress_marker); |
| 146 if (progress_marker.token().empty()) { | 146 if (progress_marker.token().empty()) { |
| 147 unsynced_data_types.Put(type); | 147 unsynced_data_types.Put(type); |
| 148 } | 148 } |
| 149 } | 149 } |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 201 << "; not re-enabling yet"; | 201 << "; not re-enabling yet"; |
| 202 return; | 202 return; |
| 203 } | 203 } |
| 204 | 204 |
| 205 ChangeState(REENABLING_TYPES); | 205 ChangeState(REENABLING_TYPES); |
| 206 // Don't use |to_migrate_| for the re-enabling because the user | 206 // Don't use |to_migrate_| for the re-enabling because the user |
| 207 // may have chosen to disable types during the migration. | 207 // may have chosen to disable types during the migration. |
| 208 const ModelTypeSet full_set = service_->GetPreferredDataTypes(); | 208 const ModelTypeSet full_set = service_->GetPreferredDataTypes(); |
| 209 SDVLOG(1) << "BackendMigrator re-enabling types: " | 209 SDVLOG(1) << "BackendMigrator re-enabling types: " |
| 210 << syncable::ModelTypeSetToString(full_set); | 210 << syncable::ModelTypeSetToString(full_set); |
| 211 manager_->Configure(full_set, csync::CONFIGURE_REASON_MIGRATION); | 211 manager_->Configure(full_set, syncer::CONFIGURE_REASON_MIGRATION); |
| 212 } else if (state_ == REENABLING_TYPES) { | 212 } else if (state_ == REENABLING_TYPES) { |
| 213 // We're done! | 213 // We're done! |
| 214 ChangeState(IDLE); | 214 ChangeState(IDLE); |
| 215 | 215 |
| 216 SDVLOG(1) << "BackendMigrator: Migration complete for: " | 216 SDVLOG(1) << "BackendMigrator: Migration complete for: " |
| 217 << syncable::ModelTypeSetToString(to_migrate_); | 217 << syncable::ModelTypeSetToString(to_migrate_); |
| 218 to_migrate_.Clear(); | 218 to_migrate_.Clear(); |
| 219 | 219 |
| 220 if (!migration_done_callback_.is_null()) | 220 if (!migration_done_callback_.is_null()) |
| 221 migration_done_callback_.Run(); | 221 migration_done_callback_.Run(); |
| 222 } | 222 } |
| 223 } | 223 } |
| 224 | 224 |
| 225 BackendMigrator::State BackendMigrator::state() const { | 225 BackendMigrator::State BackendMigrator::state() const { |
| 226 return state_; | 226 return state_; |
| 227 } | 227 } |
| 228 | 228 |
| 229 syncable::ModelTypeSet | 229 syncable::ModelTypeSet |
| 230 BackendMigrator::GetPendingMigrationTypesForTest() const { | 230 BackendMigrator::GetPendingMigrationTypesForTest() const { |
| 231 return to_migrate_; | 231 return to_migrate_; |
| 232 } | 232 } |
| 233 | 233 |
| 234 #undef SDVLOG | 234 #undef SDVLOG |
| 235 | 235 |
| 236 #undef SLOG | 236 #undef SLOG |
| 237 | 237 |
| 238 }; // namespace browser_sync | 238 }; // namespace browser_sync |
| OLD | NEW |