| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/string_number_conversions.h" | 9 #include "base/string_number_conversions.h" |
| 10 #include "chrome/browser/sync/profile_sync_service.h" | 10 #include "chrome/browser/sync/profile_sync_service.h" |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 114 manager_->Configure(full_set, sync_api::CONFIGURE_REASON_MIGRATION); | 114 manager_->Configure(full_set, sync_api::CONFIGURE_REASON_MIGRATION); |
| 115 } | 115 } |
| 116 | 116 |
| 117 void BackendMigrator::Observe(int type, | 117 void BackendMigrator::Observe(int type, |
| 118 const NotificationSource& source, | 118 const NotificationSource& source, |
| 119 const NotificationDetails& details) { | 119 const NotificationDetails& details) { |
| 120 DCHECK_EQ(chrome::NOTIFICATION_SYNC_CONFIGURE_DONE, type); | 120 DCHECK_EQ(chrome::NOTIFICATION_SYNC_CONFIGURE_DONE, type); |
| 121 if (state_ == IDLE) | 121 if (state_ == IDLE) |
| 122 return; | 122 return; |
| 123 | 123 |
| 124 const DataTypeManager::ConfigureResult* result = | 124 DataTypeManager::ConfigureResultWithErrorLocation* result = |
| 125 Details<DataTypeManager::ConfigureResult>(details).ptr(); | 125 Details<DataTypeManager::ConfigureResultWithErrorLocation>( |
| 126 details).ptr(); |
| 126 | 127 |
| 127 ModelTypeSet intersection; | 128 ModelTypeSet intersection; |
| 128 std::set_intersection(result->requested_types.begin(), | 129 std::set_intersection(result->requested_types.begin(), |
| 129 result->requested_types.end(), to_migrate_.begin(), to_migrate_.end(), | 130 result->requested_types.end(), to_migrate_.begin(), to_migrate_.end(), |
| 130 std::inserter(intersection, intersection.end())); | 131 std::inserter(intersection, intersection.end())); |
| 131 | 132 |
| 132 // The intersection check is to determine if our disable request was | 133 // The intersection check is to determine if our disable request was |
| 133 // interrupted by a user changing preferred types. May still need to purge. | 134 // interrupted by a user changing preferred types. May still need to purge. |
| 134 // It's pretty wild if we're in WAITING_FOR_PURGE here, because it would mean | 135 // It's pretty wild if we're in WAITING_FOR_PURGE here, because it would mean |
| 135 // that after our disable-config finished but before the purge, another config | 136 // that after our disable-config finished but before the purge, another config |
| 136 // was posted externally _and completed_, which means somehow the nudge to | 137 // was posted externally _and completed_, which means somehow the nudge to |
| 137 // purge was dropped, yet nudges are reliable. | 138 // purge was dropped, yet nudges are reliable. |
| 138 if (state_ == WAITING_TO_START || state_ == WAITING_FOR_PURGE || | 139 if (state_ == WAITING_TO_START || state_ == WAITING_FOR_PURGE || |
| 139 (state_ == DISABLING_TYPES && !intersection.empty())) { | 140 (state_ == DISABLING_TYPES && !intersection.empty())) { |
| 140 state_ = WAITING_TO_START; | 141 state_ = WAITING_TO_START; |
| 141 restart_migration_ = false; | 142 restart_migration_ = false; |
| 142 VLOG(1) << "BackendMigrator::Observe posting MigrateTypes."; | 143 VLOG(1) << "BackendMigrator::Observe posting MigrateTypes."; |
| 143 if (!BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 144 if (!BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
| 144 method_factory_.NewRunnableMethod(&BackendMigrator::MigrateTypes, | 145 method_factory_.NewRunnableMethod(&BackendMigrator::MigrateTypes, |
| 145 to_migrate_))) { | 146 to_migrate_))) { |
| 146 // Unittests need this. | 147 // Unittests need this. |
| 147 // TODO(tim): Clean this up. | 148 // TODO(tim): Clean this up. |
| 148 MigrateTypes(to_migrate_); | 149 MigrateTypes(to_migrate_); |
| 149 } | 150 } |
| 150 return; | 151 return; |
| 151 } | 152 } |
| 152 | 153 |
| 153 if (result->status != DataTypeManager::OK) { | 154 if (result->result != DataTypeManager::OK) { |
| 154 // If this fails, and we're disabling types, a type may or may not be | 155 // If this fails, and we're disabling types, a type may or may not be |
| 155 // disabled until the user restarts the browser. If this wasn't an abort, | 156 // disabled until the user restarts the browser. If this wasn't an abort, |
| 156 // any failure will be reported as an unrecoverable error to the UI. If it | 157 // any failure will be reported as an unrecoverable error to the UI. If it |
| 157 // was an abort, then typically things are shutting down anyway. There isn't | 158 // was an abort, then typically things are shutting down anyway. There isn't |
| 158 // much we can do in any case besides wait until a restart to try again. | 159 // much we can do in any case besides wait until a restart to try again. |
| 159 // The server will send down MIGRATION_DONE again for types needing | 160 // The server will send down MIGRATION_DONE again for types needing |
| 160 // migration as the type will still be enabled on restart. | 161 // migration as the type will still be enabled on restart. |
| 161 LOG(WARNING) << "Unable to migrate, configuration failed!"; | 162 LOG(WARNING) << "Unable to migrate, configuration failed!"; |
| 162 state_ = IDLE; | 163 state_ = IDLE; |
| 163 to_migrate_.clear(); | 164 to_migrate_.clear(); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 177 VLOG(1) << "BackendMigrator: Migration complete for: " << ss.str(); | 178 VLOG(1) << "BackendMigrator: Migration complete for: " << ss.str(); |
| 178 to_migrate_.clear(); | 179 to_migrate_.clear(); |
| 179 } | 180 } |
| 180 } | 181 } |
| 181 | 182 |
| 182 BackendMigrator::State BackendMigrator::state() const { | 183 BackendMigrator::State BackendMigrator::state() const { |
| 183 return state_; | 184 return state_; |
| 184 } | 185 } |
| 185 | 186 |
| 186 }; // namespace browser_sync | 187 }; // namespace browser_sync |
| OLD | NEW |