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 "sync/internal_api/sync_manager_impl.h" | 5 #include "sync/internal_api/sync_manager_impl.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/base64.h" | 9 #include "base/base64.h" |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
292 | 292 |
293 if (marker.token().empty()) | 293 if (marker.token().empty()) |
294 result.Put(i.Get()); | 294 result.Put(i.Get()); |
295 } | 295 } |
296 return result; | 296 return result; |
297 } | 297 } |
298 | 298 |
299 void SyncManagerImpl::ConfigureSyncer( | 299 void SyncManagerImpl::ConfigureSyncer( |
300 ConfigureReason reason, | 300 ConfigureReason reason, |
301 ModelTypeSet to_download, | 301 ModelTypeSet to_download, |
| 302 ModelTypeSet to_purge, |
302 ModelTypeSet to_journal, | 303 ModelTypeSet to_journal, |
303 ModelTypeSet to_unapply, | 304 ModelTypeSet to_unapply, |
304 ModelTypeSet to_ignore, | |
305 const ModelSafeRoutingInfo& new_routing_info, | 305 const ModelSafeRoutingInfo& new_routing_info, |
306 const base::Closure& ready_task, | 306 const base::Closure& ready_task, |
307 const base::Closure& retry_task) { | 307 const base::Closure& retry_task) { |
308 DCHECK(thread_checker_.CalledOnValidThread()); | 308 DCHECK(thread_checker_.CalledOnValidThread()); |
309 DCHECK(!ready_task.is_null()); | 309 DCHECK(!ready_task.is_null()); |
310 DCHECK(!retry_task.is_null()); | 310 DCHECK(!retry_task.is_null()); |
311 | 311 |
312 // Cleanup any types that might have just been disabled. | |
313 ModelTypeSet previous_types = ModelTypeSet::All(); | |
314 if (!session_context_->routing_info().empty()) | |
315 previous_types = GetRoutingInfoTypes(session_context_->routing_info()); | |
316 | |
317 // By removing the |to_ignore| types from the previous types, they won't be | |
318 // treated as disabled, and therefore won't be purged. | |
319 previous_types.RemoveAll(to_ignore); | |
320 | |
321 DVLOG(1) << "Configuring -" | 312 DVLOG(1) << "Configuring -" |
| 313 << "\n\t" << "current types: " |
| 314 << ModelTypeSetToString(GetRoutingInfoTypes(new_routing_info)) |
322 << "\n\t" << "types to download: " | 315 << "\n\t" << "types to download: " |
323 << ModelTypeSetToString(to_download) | 316 << ModelTypeSetToString(to_download) |
324 << "\n\t" << "current types: " | 317 << "\n\t" << "types to purge: " |
325 << ModelTypeSetToString(GetRoutingInfoTypes(new_routing_info)) | 318 << ModelTypeSetToString(to_purge) |
326 << "\n\t" << "previous types: " | 319 << "\n\t" << "types to journal: " |
327 << ModelTypeSetToString(previous_types) | |
328 << "\n\t" << "to_journal: " | |
329 << ModelTypeSetToString(to_journal) | 320 << ModelTypeSetToString(to_journal) |
330 << "\n\t" << "to_unapply: " | 321 << "\n\t" << "types to unapply: " |
331 << ModelTypeSetToString(to_unapply) | 322 << ModelTypeSetToString(to_unapply); |
332 << "\n\t" << "to_ignore: " | 323 if (!PurgeDisabledTypes(to_purge, |
333 << ModelTypeSetToString(to_ignore); | |
334 if (!PurgeDisabledTypes(previous_types, | |
335 GetRoutingInfoTypes(new_routing_info), | |
336 to_journal, | 324 to_journal, |
337 to_unapply)) { | 325 to_unapply)) { |
338 // We failed to cleanup the types. Invoke the ready task without actually | 326 // We failed to cleanup the types. Invoke the ready task without actually |
339 // configuring any types. The caller should detect this as a configuration | 327 // configuring any types. The caller should detect this as a configuration |
340 // failure and act appropriately. | 328 // failure and act appropriately. |
341 ready_task.Run(); | 329 ready_task.Run(); |
342 return; | 330 return; |
343 } | 331 } |
344 | 332 |
345 ConfigurationParams params(GetSourceFromReason(reason), | 333 ConfigurationParams params(GetSourceFromReason(reason), |
(...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
594 UMA_HISTOGRAM_COUNTS("Sync.PartiallySyncedTypes", | 582 UMA_HISTOGRAM_COUNTS("Sync.PartiallySyncedTypes", |
595 partially_synced_types.Size()); | 583 partially_synced_types.Size()); |
596 if (partially_synced_types.Empty()) | 584 if (partially_synced_types.Empty()) |
597 return true; | 585 return true; |
598 return directory()->PurgeEntriesWithTypeIn(partially_synced_types, | 586 return directory()->PurgeEntriesWithTypeIn(partially_synced_types, |
599 ModelTypeSet(), | 587 ModelTypeSet(), |
600 ModelTypeSet()); | 588 ModelTypeSet()); |
601 } | 589 } |
602 | 590 |
603 bool SyncManagerImpl::PurgeDisabledTypes( | 591 bool SyncManagerImpl::PurgeDisabledTypes( |
604 ModelTypeSet previously_enabled_types, | 592 ModelTypeSet to_purge, |
605 ModelTypeSet currently_enabled_types, | |
606 ModelTypeSet to_journal, | 593 ModelTypeSet to_journal, |
607 ModelTypeSet to_unapply) { | 594 ModelTypeSet to_unapply) { |
608 ModelTypeSet disabled_types = Difference(previously_enabled_types, | 595 if (to_purge.Empty()) |
609 currently_enabled_types); | |
610 if (disabled_types.Empty()) | |
611 return true; | 596 return true; |
612 DVLOG(1) << "Purging disabled types " | 597 DVLOG(1) << "Purging disabled types " << ModelTypeSetToString(to_purge); |
613 << ModelTypeSetToString(disabled_types); | 598 DCHECK(to_purge.HasAll(to_journal)); |
614 DCHECK(disabled_types.HasAll(to_journal)); | 599 DCHECK(to_purge.HasAll(to_unapply)); |
615 DCHECK(disabled_types.HasAll(to_unapply)); | 600 return directory()->PurgeEntriesWithTypeIn(to_purge, to_journal, to_unapply); |
616 return directory()->PurgeEntriesWithTypeIn(disabled_types, | |
617 to_journal, | |
618 to_unapply); | |
619 } | 601 } |
620 | 602 |
621 void SyncManagerImpl::UpdateCredentials(const SyncCredentials& credentials) { | 603 void SyncManagerImpl::UpdateCredentials(const SyncCredentials& credentials) { |
622 DCHECK(thread_checker_.CalledOnValidThread()); | 604 DCHECK(thread_checker_.CalledOnValidThread()); |
623 DCHECK(initialized_); | 605 DCHECK(initialized_); |
624 DCHECK(!credentials.email.empty()); | 606 DCHECK(!credentials.email.empty()); |
625 DCHECK(!credentials.sync_token.empty()); | 607 DCHECK(!credentials.sync_token.empty()); |
626 | 608 |
627 observing_network_connectivity_changes_ = true; | 609 observing_network_connectivity_changes_ = true; |
628 if (!connection_manager_->SetAuthToken(credentials.sync_token, | 610 if (!connection_manager_->SetAuthToken(credentials.sync_token, |
(...skipping 788 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1417 int SyncManagerImpl::GetDefaultNudgeDelay() { | 1399 int SyncManagerImpl::GetDefaultNudgeDelay() { |
1418 return kDefaultNudgeDelayMilliseconds; | 1400 return kDefaultNudgeDelayMilliseconds; |
1419 } | 1401 } |
1420 | 1402 |
1421 // static. | 1403 // static. |
1422 int SyncManagerImpl::GetPreferencesNudgeDelay() { | 1404 int SyncManagerImpl::GetPreferencesNudgeDelay() { |
1423 return kPreferencesNudgeDelayMilliseconds; | 1405 return kPreferencesNudgeDelayMilliseconds; |
1424 } | 1406 } |
1425 | 1407 |
1426 } // namespace syncer | 1408 } // namespace syncer |
OLD | NEW |