Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2)

Side by Side Diff: sync/internal_api/sync_manager_impl.cc

Issue 10541079: [Sync] Remove CleanupDisabledTypes command and move purge logic into SyncManager. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix rebase conflict Created 8 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 326 matching lines...) Expand 10 before | Expand all | Expand 10 after
337 void SyncManagerImpl::ConfigureSyncer( 337 void SyncManagerImpl::ConfigureSyncer(
338 ConfigureReason reason, 338 ConfigureReason reason,
339 const ModelTypeSet& types_to_config, 339 const ModelTypeSet& types_to_config,
340 const ModelSafeRoutingInfo& new_routing_info, 340 const ModelSafeRoutingInfo& new_routing_info,
341 const base::Closure& ready_task, 341 const base::Closure& ready_task,
342 const base::Closure& retry_task) { 342 const base::Closure& retry_task) {
343 DCHECK(thread_checker_.CalledOnValidThread()); 343 DCHECK(thread_checker_.CalledOnValidThread());
344 DCHECK(!ready_task.is_null()); 344 DCHECK(!ready_task.is_null());
345 DCHECK(!retry_task.is_null()); 345 DCHECK(!retry_task.is_null());
346 346
347 // Cleanup any types that might have just been disabled.
348 if (!CleanupDisabledTypes(
349 GetRoutingInfoTypes(session_context_->routing_info()),
350 GetRoutingInfoTypes(new_routing_info))) {
351 // We failed to cleanup the types. Invoke the ready task without actually
352 // configuring any types. The caller should detect this as a configuration
353 // failure and act appropriately.
354 ready_task.Run();
355 return;
356 }
357
347 // TODO(zea): set this based on whether cryptographer has keystore 358 // TODO(zea): set this based on whether cryptographer has keystore
348 // encryption key or not (requires opening a transaction). crbug.com/129665. 359 // encryption key or not (requires opening a transaction). crbug.com/129665.
349 ConfigurationParams::KeystoreKeyStatus keystore_key_status = 360 ConfigurationParams::KeystoreKeyStatus keystore_key_status =
350 ConfigurationParams::KEYSTORE_KEY_UNNECESSARY; 361 ConfigurationParams::KEYSTORE_KEY_UNNECESSARY;
351 362
352 ConfigurationParams params(GetSourceFromReason(reason), 363 ConfigurationParams params(GetSourceFromReason(reason),
353 types_to_config, 364 types_to_config,
354 new_routing_info, 365 new_routing_info,
355 keystore_key_status, 366 keystore_key_status,
356 ready_task); 367 ready_task);
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
455 // re-downloaded during any configuration. But, it's possible for a datatype 466 // re-downloaded during any configuration. But, it's possible for a datatype
456 // to have a progress marker but not have initial sync ended yet, making 467 // to have a progress marker but not have initial sync ended yet, making
457 // it a candidate for migration. This is a problem, as the DataTypeManager 468 // it a candidate for migration. This is a problem, as the DataTypeManager
458 // does not support a migration while it's already in the middle of a 469 // does not support a migration while it's already in the middle of a
459 // configuration. As a result, any partially synced datatype can stall the 470 // configuration. As a result, any partially synced datatype can stall the
460 // DTM, waiting for the configuration to complete, which it never will due 471 // DTM, waiting for the configuration to complete, which it never will due
461 // to the migration error. In addition, a partially synced nigori will 472 // to the migration error. In addition, a partially synced nigori will
462 // trigger the migration logic before the backend is initialized, resulting 473 // trigger the migration logic before the backend is initialized, resulting
463 // in crashes. We therefore detect and purge any partially synced types as 474 // in crashes. We therefore detect and purge any partially synced types as
464 // part of initialization. 475 // part of initialization.
465 if (!PurgePartiallySyncedTypes()) 476 //
477 // Similarly, a type may have been disabled previously, but we didn't
478 // manage to purge. Ensure we cleanup any disabled types before starting up.
479 //
480 // Note: If either of these methods fail, we have directory corruption and
481 // cannot continue.
482 if (!PurgePartiallySyncedTypes() ||
483 !CleanupDisabledTypes(
tim (not reviewing) 2012/07/26 21:39:45 nit - lets use the same verb (Purge/Cleanup) here,
Nicolas Zea 2012/07/26 23:29:59 Done.
484 ModelTypeSet::All(),
485 GetRoutingInfoTypes(session_context_->routing_info())))
466 success = false; 486 success = false;
467 487
468 // Cryptographer should only be accessed while holding a 488 // Cryptographer should only be accessed while holding a
469 // transaction. Grabbing the user share for the transaction 489 // transaction. Grabbing the user share for the transaction
470 // checks the initialization state, so this must come after 490 // checks the initialization state, so this must come after
471 // |initialized_| is set to true. 491 // |initialized_| is set to true.
472 ReadTransaction trans(FROM_HERE, GetUserShare()); 492 ReadTransaction trans(FROM_HERE, GetUserShare());
473 trans.GetCryptographer()->Bootstrap(restored_key_for_bootstrapping); 493 trans.GetCryptographer()->Bootstrap(restored_key_for_bootstrapping);
474 trans.GetCryptographer()->AddObserver(this); 494 trans.GetCryptographer()->AddObserver(this);
475 } 495 }
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after
703 partially_synced_types.RemoveAll(GetTypesWithEmptyProgressMarkerToken( 723 partially_synced_types.RemoveAll(GetTypesWithEmptyProgressMarkerToken(
704 ModelTypeSet::All())); 724 ModelTypeSet::All()));
705 725
706 UMA_HISTOGRAM_COUNTS("Sync.PartiallySyncedTypes", 726 UMA_HISTOGRAM_COUNTS("Sync.PartiallySyncedTypes",
707 partially_synced_types.Size()); 727 partially_synced_types.Size());
708 if (partially_synced_types.Empty()) 728 if (partially_synced_types.Empty())
709 return true; 729 return true;
710 return directory()->PurgeEntriesWithTypeIn(partially_synced_types); 730 return directory()->PurgeEntriesWithTypeIn(partially_synced_types);
711 } 731 }
712 732
733 bool SyncManagerImpl::CleanupDisabledTypes(
734 ModelTypeSet previously_enabled_types,
735 ModelTypeSet currently_enabled_types) {
736 ModelTypeSet disabled_types = Difference(previously_enabled_types,
737 currently_enabled_types);
738 if (disabled_types.Empty())
739 return true;
740
741 DVLOG(1) << "Purging disabled types "
742 << ModelTypeSetToString(disabled_types);
743 return directory()->PurgeEntriesWithTypeIn(disabled_types);
744 }
745
713 void SyncManagerImpl::UpdateCredentials( 746 void SyncManagerImpl::UpdateCredentials(
714 const SyncCredentials& credentials) { 747 const SyncCredentials& credentials) {
715 DCHECK(thread_checker_.CalledOnValidThread()); 748 DCHECK(thread_checker_.CalledOnValidThread());
716 DCHECK_EQ(credentials.email, share_.name); 749 DCHECK_EQ(credentials.email, share_.name);
717 DCHECK(!credentials.email.empty()); 750 DCHECK(!credentials.email.empty());
718 DCHECK(!credentials.sync_token.empty()); 751 DCHECK(!credentials.sync_token.empty());
719 752
720 observing_ip_address_changes_ = true; 753 observing_ip_address_changes_ = true;
721 if (connection_manager_->set_auth_token(credentials.sync_token)) { 754 if (connection_manager_->set_auth_token(credentials.sync_token)) {
722 sync_notifier_->UpdateCredentials( 755 sync_notifier_->UpdateCredentials(
(...skipping 1168 matching lines...) Expand 10 before | Expand all | Expand 10 after
1891 int SyncManagerImpl::GetDefaultNudgeDelay() { 1924 int SyncManagerImpl::GetDefaultNudgeDelay() {
1892 return kDefaultNudgeDelayMilliseconds; 1925 return kDefaultNudgeDelayMilliseconds;
1893 } 1926 }
1894 1927
1895 // static. 1928 // static.
1896 int SyncManagerImpl::GetPreferencesNudgeDelay() { 1929 int SyncManagerImpl::GetPreferencesNudgeDelay() {
1897 return kPreferencesNudgeDelayMilliseconds; 1930 return kPreferencesNudgeDelayMilliseconds;
1898 } 1931 }
1899 1932
1900 } // namespace syncer 1933 } // namespace syncer
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698