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

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 test Created 8 years, 4 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
« no previous file with comments | « sync/internal_api/sync_manager_impl.h ('k') | sync/internal_api/syncapi_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 ModelTypeSet previous_types = ModelTypeSet::All();
349 if (!session_context_->routing_info().empty())
350 previous_types = GetRoutingInfoTypes(session_context_->routing_info());
351 if (!PurgeDisabledTypes(previous_types,
352 GetRoutingInfoTypes(new_routing_info))) {
353 // We failed to cleanup the types. Invoke the ready task without actually
354 // configuring any types. The caller should detect this as a configuration
355 // failure and act appropriately.
356 ready_task.Run();
357 return;
358 }
359
347 // TODO(zea): set this based on whether cryptographer has keystore 360 // TODO(zea): set this based on whether cryptographer has keystore
348 // encryption key or not (requires opening a transaction). crbug.com/129665. 361 // encryption key or not (requires opening a transaction). crbug.com/129665.
349 ConfigurationParams::KeystoreKeyStatus keystore_key_status = 362 ConfigurationParams::KeystoreKeyStatus keystore_key_status =
350 ConfigurationParams::KEYSTORE_KEY_UNNECESSARY; 363 ConfigurationParams::KEYSTORE_KEY_UNNECESSARY;
351 364
352 ConfigurationParams params(GetSourceFromReason(reason), 365 ConfigurationParams params(GetSourceFromReason(reason),
353 types_to_config, 366 types_to_config,
354 new_routing_info, 367 new_routing_info,
355 keystore_key_status, 368 keystore_key_status,
356 ready_task); 369 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 468 // 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 469 // 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 470 // 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 471 // 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 472 // configuration. As a result, any partially synced datatype can stall the
460 // DTM, waiting for the configuration to complete, which it never will due 473 // DTM, waiting for the configuration to complete, which it never will due
461 // to the migration error. In addition, a partially synced nigori will 474 // to the migration error. In addition, a partially synced nigori will
462 // trigger the migration logic before the backend is initialized, resulting 475 // trigger the migration logic before the backend is initialized, resulting
463 // in crashes. We therefore detect and purge any partially synced types as 476 // in crashes. We therefore detect and purge any partially synced types as
464 // part of initialization. 477 // part of initialization.
465 if (!PurgePartiallySyncedTypes()) 478 //
479 // Similarly, a type may have been disabled previously, but we didn't
480 // manage to purge. Ensure we cleanup any disabled types before starting up.
481 //
482 // Note: If either of these methods fail, we have directory corruption and
483 // cannot continue.
484 // TODO(rlarocque): remove the PurgeDisabledTypes call once we no longer
485 // initialize the session context with the enabled types (purging disabled
486 // types will be done within ConfigureSyncer).
487 if (!PurgePartiallySyncedTypes() ||
488 !PurgeDisabledTypes(
489 ModelTypeSet::All(),
490 GetRoutingInfoTypes(session_context_->routing_info())))
466 success = false; 491 success = false;
467 492
468 // Cryptographer should only be accessed while holding a 493 // Cryptographer should only be accessed while holding a
469 // transaction. Grabbing the user share for the transaction 494 // transaction. Grabbing the user share for the transaction
470 // checks the initialization state, so this must come after 495 // checks the initialization state, so this must come after
471 // |initialized_| is set to true. 496 // |initialized_| is set to true.
472 ReadTransaction trans(FROM_HERE, GetUserShare()); 497 ReadTransaction trans(FROM_HERE, GetUserShare());
473 trans.GetCryptographer()->Bootstrap(restored_key_for_bootstrapping); 498 trans.GetCryptographer()->Bootstrap(restored_key_for_bootstrapping);
474 trans.GetCryptographer()->AddObserver(this); 499 trans.GetCryptographer()->AddObserver(this);
475 } 500 }
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after
703 partially_synced_types.RemoveAll(GetTypesWithEmptyProgressMarkerToken( 728 partially_synced_types.RemoveAll(GetTypesWithEmptyProgressMarkerToken(
704 ModelTypeSet::All())); 729 ModelTypeSet::All()));
705 730
706 UMA_HISTOGRAM_COUNTS("Sync.PartiallySyncedTypes", 731 UMA_HISTOGRAM_COUNTS("Sync.PartiallySyncedTypes",
707 partially_synced_types.Size()); 732 partially_synced_types.Size());
708 if (partially_synced_types.Empty()) 733 if (partially_synced_types.Empty())
709 return true; 734 return true;
710 return directory()->PurgeEntriesWithTypeIn(partially_synced_types); 735 return directory()->PurgeEntriesWithTypeIn(partially_synced_types);
711 } 736 }
712 737
738 bool SyncManagerImpl::PurgeDisabledTypes(
739 ModelTypeSet previously_enabled_types,
740 ModelTypeSet currently_enabled_types) {
741 ModelTypeSet disabled_types = Difference(previously_enabled_types,
742 currently_enabled_types);
743 if (disabled_types.Empty())
744 return true;
745
746 DVLOG(1) << "Purging disabled types "
747 << ModelTypeSetToString(disabled_types);
748 return directory()->PurgeEntriesWithTypeIn(disabled_types);
749 }
750
713 void SyncManagerImpl::UpdateCredentials( 751 void SyncManagerImpl::UpdateCredentials(
714 const SyncCredentials& credentials) { 752 const SyncCredentials& credentials) {
715 DCHECK(thread_checker_.CalledOnValidThread()); 753 DCHECK(thread_checker_.CalledOnValidThread());
716 DCHECK_EQ(credentials.email, share_.name); 754 DCHECK_EQ(credentials.email, share_.name);
717 DCHECK(!credentials.email.empty()); 755 DCHECK(!credentials.email.empty());
718 DCHECK(!credentials.sync_token.empty()); 756 DCHECK(!credentials.sync_token.empty());
719 757
720 observing_ip_address_changes_ = true; 758 observing_ip_address_changes_ = true;
721 if (connection_manager_->set_auth_token(credentials.sync_token)) { 759 if (connection_manager_->set_auth_token(credentials.sync_token)) {
722 sync_notifier_->UpdateCredentials( 760 sync_notifier_->UpdateCredentials(
(...skipping 1168 matching lines...) Expand 10 before | Expand all | Expand 10 after
1891 int SyncManagerImpl::GetDefaultNudgeDelay() { 1929 int SyncManagerImpl::GetDefaultNudgeDelay() {
1892 return kDefaultNudgeDelayMilliseconds; 1930 return kDefaultNudgeDelayMilliseconds;
1893 } 1931 }
1894 1932
1895 // static. 1933 // static.
1896 int SyncManagerImpl::GetPreferencesNudgeDelay() { 1934 int SyncManagerImpl::GetPreferencesNudgeDelay() {
1897 return kPreferencesNudgeDelayMilliseconds; 1935 return kPreferencesNudgeDelayMilliseconds;
1898 } 1936 }
1899 1937
1900 } // namespace syncer 1938 } // namespace syncer
OLDNEW
« no previous file with comments | « sync/internal_api/sync_manager_impl.h ('k') | sync/internal_api/syncapi_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698