| 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/message_loop.h" | 7 #include "base/message_loop/message_loop.h" |
| 8 #include "base/strings/string_number_conversions.h" | 8 #include "base/strings/string_number_conversions.h" |
| 9 #include "base/tracked_objects.h" | 9 #include "base/tracked_objects.h" |
| 10 #include "chrome/browser/chrome_notification_types.h" | 10 #include "chrome/browser/chrome_notification_types.h" |
| 11 #include "chrome/browser/sync/profile_sync_service.h" | 11 #include "chrome/browser/sync/profile_sync_service.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 syncer::ModelTypeSet; | 19 using syncer::ModelTypeSet; |
| 20 | 20 |
| 21 namespace browser_sync { | 21 namespace browser_sync { |
| 22 | 22 |
| 23 using syncer::ModelTypeToString; | 23 using syncer::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 syncer::UserShare* user_share, | 28 syncer::UserShare* user_share, |
| 29 ProfileSyncService* service, | 29 ProfileSyncService* service, |
| 30 DataTypeManager* manager, | 30 sync_driver::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 migration_done_callback_(migration_done_callback), | 34 migration_done_callback_(migration_done_callback), |
| 35 weak_ptr_factory_(this) { | 35 weak_ptr_factory_(this) { |
| 36 } | 36 } |
| 37 | 37 |
| 38 BackendMigrator::~BackendMigrator() { | 38 BackendMigrator::~BackendMigrator() { |
| 39 } | 39 } |
| 40 | 40 |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 84 } | 84 } |
| 85 | 85 |
| 86 void BackendMigrator::ChangeState(State new_state) { | 86 void BackendMigrator::ChangeState(State new_state) { |
| 87 state_ = new_state; | 87 state_ = new_state; |
| 88 FOR_EACH_OBSERVER(MigrationObserver, migration_observers_, | 88 FOR_EACH_OBSERVER(MigrationObserver, migration_observers_, |
| 89 OnMigrationStateChange()); | 89 OnMigrationStateChange()); |
| 90 } | 90 } |
| 91 | 91 |
| 92 bool BackendMigrator::TryStart() { | 92 bool BackendMigrator::TryStart() { |
| 93 DCHECK_EQ(state_, WAITING_TO_START); | 93 DCHECK_EQ(state_, WAITING_TO_START); |
| 94 if (manager_->state() == DataTypeManager::CONFIGURED) { | 94 if (manager_->state() == sync_driver::DataTypeManager::CONFIGURED) { |
| 95 RestartMigration(); | 95 RestartMigration(); |
| 96 return true; | 96 return true; |
| 97 } | 97 } |
| 98 return false; | 98 return false; |
| 99 } | 99 } |
| 100 | 100 |
| 101 void BackendMigrator::RestartMigration() { | 101 void BackendMigrator::RestartMigration() { |
| 102 // We'll now disable any running types that need to be migrated. | 102 // We'll now disable any running types that need to be migrated. |
| 103 ChangeState(DISABLING_TYPES); | 103 ChangeState(DISABLING_TYPES); |
| 104 SDVLOG(1) << "BackendMigrator disabling types " | 104 SDVLOG(1) << "BackendMigrator disabling types " |
| 105 << ModelTypeSetToString(to_migrate_); | 105 << ModelTypeSetToString(to_migrate_); |
| 106 | 106 |
| 107 manager_->PurgeForMigration(to_migrate_, syncer::CONFIGURE_REASON_MIGRATION); | 107 manager_->PurgeForMigration(to_migrate_, syncer::CONFIGURE_REASON_MIGRATION); |
| 108 } | 108 } |
| 109 | 109 |
| 110 void BackendMigrator::OnConfigureDone( | 110 void BackendMigrator::OnConfigureDone( |
| 111 const DataTypeManager::ConfigureResult& result) { | 111 const sync_driver::DataTypeManager::ConfigureResult& result) { |
| 112 if (state_ == IDLE) | 112 if (state_ == IDLE) |
| 113 return; | 113 return; |
| 114 | 114 |
| 115 // |manager_|'s methods aren't re-entrant, and we're notified from | 115 // |manager_|'s methods aren't re-entrant, and we're notified from |
| 116 // them, so post a task to avoid problems. | 116 // them, so post a task to avoid problems. |
| 117 SDVLOG(1) << "Posting OnConfigureDoneImpl"; | 117 SDVLOG(1) << "Posting OnConfigureDoneImpl"; |
| 118 base::MessageLoop::current()->PostTask( | 118 base::MessageLoop::current()->PostTask( |
| 119 FROM_HERE, | 119 FROM_HERE, |
| 120 base::Bind(&BackendMigrator::OnConfigureDoneImpl, | 120 base::Bind(&BackendMigrator::OnConfigureDoneImpl, |
| 121 weak_ptr_factory_.GetWeakPtr(), result)); | 121 weak_ptr_factory_.GetWeakPtr(), result)); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 134 if (progress_marker.token().empty()) { | 134 if (progress_marker.token().empty()) { |
| 135 unsynced_data_types.Put(type); | 135 unsynced_data_types.Put(type); |
| 136 } | 136 } |
| 137 } | 137 } |
| 138 return unsynced_data_types; | 138 return unsynced_data_types; |
| 139 } | 139 } |
| 140 | 140 |
| 141 } // namespace | 141 } // namespace |
| 142 | 142 |
| 143 void BackendMigrator::OnConfigureDoneImpl( | 143 void BackendMigrator::OnConfigureDoneImpl( |
| 144 const DataTypeManager::ConfigureResult& result) { | 144 const sync_driver::DataTypeManager::ConfigureResult& result) { |
| 145 SDVLOG(1) << "OnConfigureDone with requested types " | 145 SDVLOG(1) << "OnConfigureDone with requested types " |
| 146 << ModelTypeSetToString(result.requested_types) | 146 << ModelTypeSetToString(result.requested_types) |
| 147 << ", status " << result.status | 147 << ", status " << result.status |
| 148 << ", and to_migrate_ = " << ModelTypeSetToString(to_migrate_); | 148 << ", and to_migrate_ = " << ModelTypeSetToString(to_migrate_); |
| 149 if (state_ == WAITING_TO_START) { | 149 if (state_ == WAITING_TO_START) { |
| 150 if (!TryStart()) | 150 if (!TryStart()) |
| 151 SDVLOG(1) << "Manager still not configured; still waiting"; | 151 SDVLOG(1) << "Manager still not configured; still waiting"; |
| 152 return; | 152 return; |
| 153 } | 153 } |
| 154 | 154 |
| 155 DCHECK_GT(state_, WAITING_TO_START); | 155 DCHECK_GT(state_, WAITING_TO_START); |
| 156 | 156 |
| 157 const ModelTypeSet intersection = | 157 const ModelTypeSet intersection = |
| 158 Intersection(result.requested_types, to_migrate_); | 158 Intersection(result.requested_types, to_migrate_); |
| 159 // This intersection check is to determine if our disable request | 159 // This intersection check is to determine if our disable request |
| 160 // was interrupted by a user changing preferred types. | 160 // was interrupted by a user changing preferred types. |
| 161 if (state_ == DISABLING_TYPES && !intersection.Empty()) { | 161 if (state_ == DISABLING_TYPES && !intersection.Empty()) { |
| 162 SDVLOG(1) << "Disable request interrupted by user changing types"; | 162 SDVLOG(1) << "Disable request interrupted by user changing types"; |
| 163 RestartMigration(); | 163 RestartMigration(); |
| 164 return; | 164 return; |
| 165 } | 165 } |
| 166 | 166 |
| 167 if (result.status != DataTypeManager::OK && | 167 if (result.status != sync_driver::DataTypeManager::OK && |
| 168 result.status != DataTypeManager::PARTIAL_SUCCESS) { | 168 result.status != sync_driver::DataTypeManager::PARTIAL_SUCCESS) { |
| 169 // If this fails, and we're disabling types, a type may or may not be | 169 // If this fails, and we're disabling types, a type may or may not be |
| 170 // disabled until the user restarts the browser. If this wasn't an abort, | 170 // disabled until the user restarts the browser. If this wasn't an abort, |
| 171 // any failure will be reported as an unrecoverable error to the UI. If it | 171 // any failure will be reported as an unrecoverable error to the UI. If it |
| 172 // was an abort, then typically things are shutting down anyway. There isn't | 172 // was an abort, then typically things are shutting down anyway. There isn't |
| 173 // much we can do in any case besides wait until a restart to try again. | 173 // much we can do in any case besides wait until a restart to try again. |
| 174 // The server will send down MIGRATION_DONE again for types needing | 174 // The server will send down MIGRATION_DONE again for types needing |
| 175 // migration as the type will still be enabled on restart. | 175 // migration as the type will still be enabled on restart. |
| 176 SLOG(WARNING) << "Unable to migrate, configuration failed!"; | 176 SLOG(WARNING) << "Unable to migrate, configuration failed!"; |
| 177 ChangeState(IDLE); | 177 ChangeState(IDLE); |
| 178 to_migrate_.Clear(); | 178 to_migrate_.Clear(); |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 217 | 217 |
| 218 syncer::ModelTypeSet BackendMigrator::GetPendingMigrationTypesForTest() const { | 218 syncer::ModelTypeSet BackendMigrator::GetPendingMigrationTypesForTest() const { |
| 219 return to_migrate_; | 219 return to_migrate_; |
| 220 } | 220 } |
| 221 | 221 |
| 222 #undef SDVLOG | 222 #undef SDVLOG |
| 223 | 223 |
| 224 #undef SLOG | 224 #undef SLOG |
| 225 | 225 |
| 226 }; // namespace browser_sync | 226 }; // namespace browser_sync |
| OLD | NEW |