Commit 7be271d7 authored by Marc Treib's avatar Marc Treib Committed by Commit Bot

Replace SyncService::State::WAITING_FOR_CONSENT by PENDING_DESIRED_CONFIGURATION

This makes more sense to describe the actual state of the SyncService (rather
than the reason for it). Presence or absence of consent isn't part of the
SyncService state.
It'll also make it easier to decouple Sync-the-machinery from
Sync-the-feature, since the concept of consent doesn't apply for the
machinery.

In practice, WAITING_FOR_CONSENT and PENDING_DESIRED_CONFIGURATION are almost
equivalent, but they are defined in different terms.

Bug: 839834, 856179
Change-Id: I5fc20a1359bd302cae233a5bce9b25bda2681e2b
Reviewed-on: https://chromium-review.googlesource.com/1141804
Commit-Queue: Marc Treib <treib@chromium.org>
Reviewed-by: default avatarMikel Astiz <mastiz@chromium.org>
Cr-Commit-Position: refs/heads/master@{#576091}
parent a1906884
...@@ -805,27 +805,26 @@ syncer::SyncService::State ProfileSyncService::GetState() const { ...@@ -805,27 +805,26 @@ syncer::SyncService::State ProfileSyncService::GetState() const {
// The DataTypeManager gets created once the engine is initialized. // The DataTypeManager gets created once the engine is initialized.
DCHECK(data_type_manager_); DCHECK(data_type_manager_);
if (!IsFirstSetupComplete()) { // At this point we should usually be able to configure our data types (and
DCHECK(data_type_manager_->state() != DataTypeManager::CONFIGURED); // once the data types can be configured, they must actually get configured).
return State::WAITING_FOR_CONSENT; // However, if the initial setup hasn't been completed, then we can't
} // configure the data types. Also if a later (non-initial) setup happens to be
// in progress, we won't configure them right now.
#if DCHECK_IS_ON() if (data_type_manager_->state() == DataTypeManager::STOPPED) {
// At this point we should generally be able to configure our data types, DCHECK(!CanConfigureDataTypes());
// except if a setup is currently in progress (i.e. the Sync settings UI is return State::PENDING_DESIRED_CONFIGURATION;
// being shown). Note that if a setup is started after the data types have }
// been configured, then they'll stay configured even though
// CanConfigureDataTypes will be false. // The DataTypeManager shouldn't get configured (i.e. leave the STOPPED state)
if (!IsSetupInProgress()) { // before the initial setup is complete.
DCHECK(CanConfigureDataTypes()); DCHECK(IsFirstSetupComplete());
// After data types *can* be configured, they must actually get configured,
// so the DataTypeManager should have gotten out of the initial STOPPED // Note that if a setup is started after the data types have been configured,
// state. It can only go back to STOPPED in case of unrecoverable errors, // then they'll stay configured even though CanConfigureDataTypes will be
// for which we already checked above. // false.
DCHECK_NE(data_type_manager_->state(), DataTypeManager::STOPPED); DCHECK(CanConfigureDataTypes() || IsSetupInProgress());
DCHECK(IsSyncActive());
} DCHECK(IsSyncActive());
#endif // DCHECK_IS_ON()
if (data_type_manager_->state() != DataTypeManager::CONFIGURED) { if (data_type_manager_->state() != DataTypeManager::CONFIGURED) {
return State::CONFIGURING; return State::CONFIGURING;
......
...@@ -214,7 +214,7 @@ TEST_F(ProfileSyncServiceStartupTest, StartFirstTime) { ...@@ -214,7 +214,7 @@ TEST_F(ProfileSyncServiceStartupTest, StartFirstTime) {
EXPECT_EQ(syncer::SyncService::DISABLE_REASON_NONE, EXPECT_EQ(syncer::SyncService::DISABLE_REASON_NONE,
sync_service()->GetDisableReasons()); sync_service()->GetDisableReasons());
EXPECT_FALSE(sync_service()->IsSyncActive()); EXPECT_FALSE(sync_service()->IsSyncActive());
EXPECT_EQ(syncer::SyncService::State::WAITING_FOR_CONSENT, EXPECT_EQ(syncer::SyncService::State::PENDING_DESIRED_CONFIGURATION,
sync_service()->GetState()); sync_service()->GetState());
// Setup is already in progress, so confirmation still isn't needed. // Setup is already in progress, so confirmation still isn't needed.
...@@ -229,7 +229,7 @@ TEST_F(ProfileSyncServiceStartupTest, StartFirstTime) { ...@@ -229,7 +229,7 @@ TEST_F(ProfileSyncServiceStartupTest, StartFirstTime) {
ASSERT_FALSE(sync_service()->IsSetupInProgress()); ASSERT_FALSE(sync_service()->IsSetupInProgress());
EXPECT_TRUE(sync_service()->IsSyncConfirmationNeeded()); EXPECT_TRUE(sync_service()->IsSyncConfirmationNeeded());
EXPECT_FALSE(sync_service()->IsSyncActive()); EXPECT_FALSE(sync_service()->IsSyncActive());
EXPECT_EQ(syncer::SyncService::State::WAITING_FOR_CONSENT, EXPECT_EQ(syncer::SyncService::State::PENDING_DESIRED_CONFIGURATION,
sync_service()->GetState()); sync_service()->GetState());
// Marking first setup complete will let ProfileSyncService configure the // Marking first setup complete will let ProfileSyncService configure the
...@@ -605,15 +605,16 @@ TEST_F(ProfileSyncServiceStartupTest, FullStartupSequenceFirstTime) { ...@@ -605,15 +605,16 @@ TEST_F(ProfileSyncServiceStartupTest, FullStartupSequenceFirstTime) {
syncer::ModelTypeSet(), syncer::WeakHandle<syncer::JsBackend>(), syncer::ModelTypeSet(), syncer::WeakHandle<syncer::JsBackend>(),
syncer::WeakHandle<syncer::DataTypeDebugInfoListener>(), "test-guid", syncer::WeakHandle<syncer::DataTypeDebugInfoListener>(), "test-guid",
/*success=*/true); /*success=*/true);
EXPECT_EQ(syncer::SyncService::State::WAITING_FOR_CONSENT, ASSERT_TRUE(sync_service()->IsEngineInitialized());
EXPECT_EQ(syncer::SyncService::State::PENDING_DESIRED_CONFIGURATION,
sync_service()->GetState()); sync_service()->GetState());
// Once the user finishes the initial setup, the service can actually start // Once the user finishes the initial setup, the service can actually start
// configuring the data types. It won't actually call the DataTypeManager yet // configuring the data types. Just marking the initial setup as complete
// though, because setup is still considered in progress (we haven't released // isn't enough though, because setup is still considered in progress (we
// the setup-in-progress handle). // haven't released the setup-in-progress handle).
sync_service()->SetFirstSetupComplete(); sync_service()->SetFirstSetupComplete();
EXPECT_EQ(syncer::SyncService::State::CONFIGURING, EXPECT_EQ(syncer::SyncService::State::PENDING_DESIRED_CONFIGURATION,
sync_service()->GetState()); sync_service()->GetState());
// Releasing the setup in progress handle lets the service actually configure // Releasing the setup in progress handle lets the service actually configure
......
...@@ -385,14 +385,14 @@ TEST_F(ProfileSyncServiceTest, NeedsConfirmation) { ...@@ -385,14 +385,14 @@ TEST_F(ProfileSyncServiceTest, NeedsConfirmation) {
// Note: At this point the engine *can* start, but nothing has kicked it off // Note: At this point the engine *can* start, but nothing has kicked it off
// (usually that happens via getting and then releasing a // (usually that happens via getting and then releasing a
// SyncSetupInProgressHandle), so the state is still WAITING_FOR_START_REQUEST // SyncSetupInProgressHandle), so the state is still WAITING_FOR_START_REQUEST
// and not WAITING_FOR_CONSENT. // and not PENDING_DESIRED_CONFIGURATION.
EXPECT_EQ(syncer::SyncService::State::WAITING_FOR_START_REQUEST, EXPECT_EQ(syncer::SyncService::State::WAITING_FOR_START_REQUEST,
service()->GetState()); service()->GetState());
// Once we kick off initialization by getting and releasing a setup handle, // Once we kick off initialization by getting and releasing a setup handle,
// the state goes to WAITING_FOR_CONSENT. // the state goes to PENDING_DESIRED_CONFIGURATION.
service()->GetSetupInProgressHandle(); service()->GetSetupInProgressHandle();
EXPECT_EQ(syncer::SyncService::State::WAITING_FOR_CONSENT, EXPECT_EQ(syncer::SyncService::State::PENDING_DESIRED_CONFIGURATION,
service()->GetState()); service()->GetState());
// The last sync time shouldn't be cleared. // The last sync time shouldn't be cleared.
......
...@@ -201,8 +201,8 @@ std::string GetSummaryString(syncer::SyncService::State state, ...@@ -201,8 +201,8 @@ std::string GetSummaryString(syncer::SyncService::State state,
return "Start deferred"; return "Start deferred";
case syncer::SyncService::State::INITIALIZING: case syncer::SyncService::State::INITIALIZING:
return "Initializing"; return "Initializing";
case syncer::SyncService::State::WAITING_FOR_CONSENT: case syncer::SyncService::State::PENDING_DESIRED_CONFIGURATION:
return "Waiting for initial setup"; return "Pending desired configuration";
case syncer::SyncService::State::CONFIGURING: case syncer::SyncService::State::CONFIGURING:
return "Configuring data types"; return "Configuring data types";
case syncer::SyncService::State::ACTIVE: case syncer::SyncService::State::ACTIVE:
......
...@@ -55,7 +55,7 @@ syncer::SyncService::State FakeSyncService::GetState() const { ...@@ -55,7 +55,7 @@ syncer::SyncService::State FakeSyncService::GetState() const {
return State::INITIALIZING; return State::INITIALIZING;
} }
if (!IsFirstSetupComplete()) { if (!IsFirstSetupComplete()) {
return State::WAITING_FOR_CONSENT; return State::PENDING_DESIRED_CONFIGURATION;
} }
DCHECK(IsSyncActive()); DCHECK(IsSyncActive());
if (!configuration_done_) { if (!configuration_done_) {
......
...@@ -122,9 +122,12 @@ class SyncService : public DataTypeEncryptionHandler, public KeyedService { ...@@ -122,9 +122,12 @@ class SyncService : public DataTypeEncryptionHandler, public KeyedService {
START_DEFERRED, START_DEFERRED,
// The Sync engine is in the process of initializing. // The Sync engine is in the process of initializing.
INITIALIZING, INITIALIZING,
// The Sync engine is initialized, but the user hasn't completed the initial // The Sync engine is initialized, but the process of configuring the data
// Sync setup yet, so we won't actually configure the data types. // types hasn't been started yet. This usually occurs if the user hasn't
WAITING_FOR_CONSENT, // completed the initial Sync setup yet (i.e. IsFirstSetupComplete() is
// false), but it can also occur if a (non-initial) Sync setup happens to be
// ongoing while the Sync service is starting up.
PENDING_DESIRED_CONFIGURATION,
// The Sync engine itself is up and running, but the individual data types // The Sync engine itself is up and running, but the individual data types
// are being (re)configured. GetActiveDataTypes() will still be empty. // are being (re)configured. GetActiveDataTypes() will still be empty.
CONFIGURING, CONFIGURING,
......
...@@ -45,7 +45,7 @@ UploadState GetUploadToGoogleState(const SyncService* sync_service, ...@@ -45,7 +45,7 @@ UploadState GetUploadToGoogleState(const SyncService* sync_service,
case SyncService::State::WAITING_FOR_START_REQUEST: case SyncService::State::WAITING_FOR_START_REQUEST:
case SyncService::State::START_DEFERRED: case SyncService::State::START_DEFERRED:
case SyncService::State::INITIALIZING: case SyncService::State::INITIALIZING:
case SyncService::State::WAITING_FOR_CONSENT: case SyncService::State::PENDING_DESIRED_CONFIGURATION:
case SyncService::State::CONFIGURING: case SyncService::State::CONFIGURING:
return UploadState::INITIALIZING; return UploadState::INITIALIZING;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment