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