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/glue/data_type_manager_impl.h" | 5 #include "chrome/browser/sync/glue/data_type_manager_impl.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <functional> | 8 #include <functional> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
73 reason == sync_api::CONFIGURE_REASON_RECONFIGURATION) { | 73 reason == sync_api::CONFIGURE_REASON_RECONFIGURATION) { |
74 // If we're already configured and the types haven't changed, we can exit | 74 // If we're already configured and the types haven't changed, we can exit |
75 // out early. | 75 // out early. |
76 NotifyStart(); | 76 NotifyStart(); |
77 ConfigureResult result(OK, last_requested_types_); | 77 ConfigureResult result(OK, last_requested_types_); |
78 NotifyDone(result); | 78 NotifyDone(result); |
79 return; | 79 return; |
80 } | 80 } |
81 | 81 |
82 last_requested_types_ = desired_types; | 82 last_requested_types_ = desired_types; |
| 83 last_nigori_state_ = nigori_state; |
83 // Only proceed if we're in a steady state or blocked. | 84 // Only proceed if we're in a steady state or blocked. |
84 if (state_ != STOPPED && state_ != CONFIGURED && state_ != BLOCKED) { | 85 if (state_ != STOPPED && state_ != CONFIGURED && state_ != BLOCKED) { |
85 DVLOG(1) << "Received configure request while configuration in flight. " | 86 DVLOG(1) << "Received configure request while configuration in flight. " |
86 << "Postponing until current configuration complete."; | 87 << "Postponing until current configuration complete."; |
87 needs_reconfigure_ = true; | 88 needs_reconfigure_ = true; |
88 last_configure_reason_ = reason; | 89 last_configure_reason_ = reason; |
89 last_nigori_state_ = nigori_state; | |
90 return; | 90 return; |
91 } | 91 } |
92 | 92 |
93 model_association_manager_.Initialize(desired_types); | |
94 Restart(reason, nigori_state); | 93 Restart(reason, nigori_state); |
95 } | 94 } |
96 | 95 |
97 void DataTypeManagerImpl::Restart( | 96 void DataTypeManagerImpl::Restart( |
98 sync_api::ConfigureReason reason, | 97 sync_api::ConfigureReason reason, |
99 BackendDataTypeConfigurer::NigoriState nigori_state) { | 98 BackendDataTypeConfigurer::NigoriState nigori_state) { |
100 DVLOG(1) << "Restarting..."; | 99 DVLOG(1) << "Restarting..."; |
| 100 model_association_manager_.Initialize(last_requested_types_); |
101 last_restart_time_ = base::Time::Now(); | 101 last_restart_time_ = base::Time::Now(); |
102 | 102 |
103 DCHECK(state_ == STOPPED || state_ == CONFIGURED || state_ == BLOCKED); | 103 DCHECK(state_ == STOPPED || state_ == CONFIGURED || state_ == BLOCKED); |
104 | 104 |
105 // Starting from a "steady state" (stopped or configured) state | 105 // Starting from a "steady state" (stopped or configured) state |
106 // should send a start notification. | 106 // should send a start notification. |
107 if (state_ == STOPPED || state_ == CONFIGURED) | 107 if (state_ == STOPPED || state_ == CONFIGURED) |
108 NotifyStart(); | 108 NotifyStart(); |
109 | 109 |
110 model_association_manager_.StopDisabledTypes(); | 110 model_association_manager_.StopDisabledTypes(); |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
203 return; | 203 return; |
204 } | 204 } |
205 | 205 |
206 state_ = CONFIGURING; | 206 state_ = CONFIGURING; |
207 model_association_manager_.StartAssociationAsync(); | 207 model_association_manager_.StartAssociationAsync(); |
208 } | 208 } |
209 | 209 |
210 void DataTypeManagerImpl::OnModelAssociationDone( | 210 void DataTypeManagerImpl::OnModelAssociationDone( |
211 const DataTypeManager::ConfigureResult& result) { | 211 const DataTypeManager::ConfigureResult& result) { |
212 if (result.status == ABORTED || result.status == UNRECOVERABLE_ERROR) { | 212 if (result.status == ABORTED || result.status == UNRECOVERABLE_ERROR) { |
213 Abort(result.status, result.errors.size() >= 1 ? | 213 Abort(result.status, result.failed_data_types.size() >= 1 ? |
214 result.errors.front() : | 214 result.failed_data_types.front() : |
215 SyncError()); | 215 SyncError()); |
216 | |
217 return; | 216 return; |
218 } | 217 } |
219 | 218 |
220 if (ProcessReconfigure()) { | 219 if (ProcessReconfigure()) { |
221 return; | 220 return; |
222 } | 221 } |
223 | 222 |
224 if (result.status == CONFIGURE_BLOCKED) { | 223 if (result.status == CONFIGURE_BLOCKED) { |
225 failed_datatypes_info_.insert(failed_datatypes_info_.end(), | 224 failed_datatypes_info_.insert(failed_datatypes_info_.end(), |
226 result.errors.begin(), | 225 result.failed_data_types.begin(), |
227 result.errors.end()); | 226 result.failed_data_types.end()); |
228 SetBlockedAndNotify(); | 227 SetBlockedAndNotify(); |
229 return; | 228 return; |
230 } | 229 } |
231 | 230 |
232 DCHECK(result.status == PARTIAL_SUCCESS || result.status == OK); | 231 DCHECK(result.status == PARTIAL_SUCCESS || result.status == OK); |
233 state_ = CONFIGURED; | 232 state_ = CONFIGURED; |
234 failed_datatypes_info_.insert(failed_datatypes_info_.end(), | 233 failed_datatypes_info_.insert(failed_datatypes_info_.end(), |
235 result.errors.begin(), | 234 result.failed_data_types.begin(), |
236 result.errors.end()); | 235 result.failed_data_types.end()); |
237 ConfigureResult configure_result(result.status, | 236 ConfigureResult configure_result(result.status, |
238 result.requested_types, | 237 result.requested_types, |
239 failed_datatypes_info_); | 238 failed_datatypes_info_, |
| 239 result.waiting_to_start); |
240 NotifyDone(configure_result); | 240 NotifyDone(configure_result); |
241 failed_datatypes_info_.clear(); | 241 failed_datatypes_info_.clear(); |
242 } | 242 } |
243 | 243 |
| 244 void DataTypeManagerImpl::OnTypesLoaded() { |
| 245 if (state_ != CONFIGURED) { |
| 246 // Ignore this. either we just started another configuration or |
| 247 // we are in some sort of error. |
| 248 return; |
| 249 } |
| 250 |
| 251 Restart(sync_api::CONFIGURE_REASON_RECONFIGURATION, |
| 252 last_nigori_state_); |
| 253 } |
| 254 |
244 | 255 |
245 void DataTypeManagerImpl::Stop() { | 256 void DataTypeManagerImpl::Stop() { |
246 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 257 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
247 if (state_ == STOPPED) | 258 if (state_ == STOPPED) |
248 return; | 259 return; |
249 | 260 |
250 // If we are currently configuring, then the current type is in a | 261 // If we are currently configuring, then the current type is in a |
251 // partially started state. Abort the startup of the current type, | 262 // partially started state. Abort the startup of the current type, |
252 // which will synchronously invoke the start callback. | 263 // which will synchronously invoke the start callback. |
253 if (state_ == CONFIGURING) { | 264 if (state_ == CONFIGURING) { |
(...skipping 27 matching lines...) Expand all Loading... |
281 | 292 |
282 void DataTypeManagerImpl::Abort(ConfigureStatus status, | 293 void DataTypeManagerImpl::Abort(ConfigureStatus status, |
283 const SyncError& error) { | 294 const SyncError& error) { |
284 DCHECK_NE(OK, status); | 295 DCHECK_NE(OK, status); |
285 FinishStop(); | 296 FinishStop(); |
286 std::list<SyncError> error_list; | 297 std::list<SyncError> error_list; |
287 if (error.IsSet()) | 298 if (error.IsSet()) |
288 error_list.push_back(error); | 299 error_list.push_back(error); |
289 ConfigureResult result(status, | 300 ConfigureResult result(status, |
290 last_requested_types_, | 301 last_requested_types_, |
291 error_list); | 302 error_list, |
| 303 syncable::ModelTypeSet()); |
292 NotifyDone(result); | 304 NotifyDone(result); |
293 } | 305 } |
294 | 306 |
295 void DataTypeManagerImpl::NotifyStart() { | 307 void DataTypeManagerImpl::NotifyStart() { |
296 content::NotificationService::current()->Notify( | 308 content::NotificationService::current()->Notify( |
297 chrome::NOTIFICATION_SYNC_CONFIGURE_START, | 309 chrome::NOTIFICATION_SYNC_CONFIGURE_START, |
298 content::Source<DataTypeManager>(this), | 310 content::Source<DataTypeManager>(this), |
299 content::NotificationService::NoDetails()); | 311 content::NotificationService::NoDetails()); |
300 } | 312 } |
301 | 313 |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
349 content::Source<DataTypeManager>(this), | 361 content::Source<DataTypeManager>(this), |
350 content::NotificationService::NoDetails()); | 362 content::NotificationService::NoDetails()); |
351 } | 363 } |
352 | 364 |
353 void DataTypeManagerImpl::AddToConfigureTime() { | 365 void DataTypeManagerImpl::AddToConfigureTime() { |
354 DCHECK(!last_restart_time_.is_null()); | 366 DCHECK(!last_restart_time_.is_null()); |
355 configure_time_delta_ += (base::Time::Now() - last_restart_time_); | 367 configure_time_delta_ += (base::Time::Now() - last_restart_time_); |
356 } | 368 } |
357 | 369 |
358 } // namespace browser_sync | 370 } // namespace browser_sync |
OLD | NEW |