Commit 74976dd0 authored by Marc Treib's avatar Marc Treib Committed by Commit Bot

Sync StartupController: Get rid of TryStartImmediately

All it did was setting some sticky state and then calling TryStart(). So
let's at least make that explicit by having clients call a state setter
plus TryStart().

This also lets us rename the "setup_in_progress" param for TryStart()
to "force_immediate" which makes a lot more sense.

Bug: 854978
Change-Id: Ifd72c94847582626fa60b4a973fd93ac9691fc56
Reviewed-on: https://chromium-review.googlesource.com/1111715
Commit-Queue: Marc Treib <treib@chromium.org>
Reviewed-by: default avatarJan Krcal <jkrcal@chromium.org>
Cr-Commit-Position: refs/heads/master@{#569616}
parent 925e6577
...@@ -345,10 +345,9 @@ void ProfileSyncService::Initialize() { ...@@ -345,10 +345,9 @@ void ProfileSyncService::Initialize() {
// immediately. // immediately.
if (start_behavior_ == AUTO_START && IsSyncRequested() && if (start_behavior_ == AUTO_START && IsSyncRequested() &&
!IsFirstSetupComplete()) { !IsFirstSetupComplete()) {
startup_controller_->TryStartImmediately(); startup_controller_->SetBypassSetupCompleteAndDeferredStartup();
} else {
startup_controller_->TryStart(/*setup_in_progress=*/false);
} }
startup_controller_->TryStart(/*force_immediate=*/false);
} }
void ProfileSyncService::StartSyncingWithServer() { void ProfileSyncService::StartSyncingWithServer() {
...@@ -1242,7 +1241,7 @@ ProfileSyncService::GetSetupInProgressHandle() { ...@@ -1242,7 +1241,7 @@ ProfileSyncService::GetSetupInProgressHandle() {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
if (++outstanding_setup_in_progress_handles_ == 1) { if (++outstanding_setup_in_progress_handles_ == 1) {
startup_controller_->TryStart(/*setup_in_progress=*/true); startup_controller_->TryStart(/*force_immediate=*/true);
NotifyObservers(); NotifyObservers();
} }
...@@ -1967,7 +1966,8 @@ void ProfileSyncService::RequestStart() { ...@@ -1967,7 +1966,8 @@ void ProfileSyncService::RequestStart() {
sync_prefs_.SetSyncRequested(true); sync_prefs_.SetSyncRequested(true);
NotifyObservers(); NotifyObservers();
} }
startup_controller_->TryStartImmediately(); startup_controller_->SetBypassSetupCompleteAndDeferredStartup();
startup_controller_->TryStart(IsSetupInProgress());
} }
void ProfileSyncService::ReconfigureDatatypeManager() { void ProfileSyncService::ReconfigureDatatypeManager() {
......
...@@ -67,13 +67,13 @@ StartupController::StartupController( ...@@ -67,13 +67,13 @@ StartupController::StartupController(
can_start_callback_(std::move(can_start)), can_start_callback_(std::move(can_start)),
start_engine_callback_(std::move(start_engine)), start_engine_callback_(std::move(start_engine)),
bypass_setup_complete_(false), bypass_setup_complete_(false),
received_start_request_(false), bypass_deferred_startup_(false),
weak_factory_(this) {} weak_factory_(this) {}
StartupController::~StartupController() {} StartupController::~StartupController() {}
void StartupController::Reset() { void StartupController::Reset() {
received_start_request_ = false; bypass_deferred_startup_ = false;
bypass_setup_complete_ = false; bypass_setup_complete_ = false;
start_up_time_ = base::Time(); start_up_time_ = base::Time();
start_engine_time_ = base::Time(); start_engine_time_ = base::Time();
...@@ -105,7 +105,7 @@ void StartupController::StartUp(StartUpDeferredOption deferred_option) { ...@@ -105,7 +105,7 @@ void StartupController::StartUp(StartUpDeferredOption deferred_option) {
} }
} }
void StartupController::TryStart(bool setup_in_progress) { void StartupController::TryStart(bool force_immediate) {
if (!can_start_callback_.Run()) { if (!can_start_callback_.Run()) {
return; return;
} }
...@@ -117,17 +117,16 @@ void StartupController::TryStart(bool setup_in_progress) { ...@@ -117,17 +117,16 @@ void StartupController::TryStart(bool setup_in_progress) {
// and encryption information to the UI. // and encryption information to the UI.
// Do not start up the sync engine if setup has not completed and isn't // Do not start up the sync engine if setup has not completed and isn't
// in progress, unless told to otherwise. // in progress, unless told to otherwise.
if (setup_in_progress) { if (force_immediate) {
StartUp(STARTUP_IMMEDIATE); StartUp(STARTUP_IMMEDIATE);
} else if (sync_prefs_->IsFirstSetupComplete() || bypass_setup_complete_) { } else if (sync_prefs_->IsFirstSetupComplete() || bypass_setup_complete_) {
StartUp(received_start_request_ ? STARTUP_IMMEDIATE : STARTUP_DEFERRED); StartUp(bypass_deferred_startup_ ? STARTUP_IMMEDIATE : STARTUP_DEFERRED);
} }
} }
void StartupController::TryStartImmediately() { void StartupController::SetBypassSetupCompleteAndDeferredStartup() {
received_start_request_ = true; bypass_deferred_startup_ = true;
bypass_setup_complete_ = true; bypass_setup_complete_ = true;
TryStart(/*setup_in_progress=*/false);
} }
void StartupController::RecordTimeDeferred() { void StartupController::RecordTimeDeferred() {
...@@ -148,8 +147,8 @@ void StartupController::OnFallbackStartupTimerExpired() { ...@@ -148,8 +147,8 @@ void StartupController::OnFallbackStartupTimerExpired() {
RecordTimeDeferred(); RecordTimeDeferred();
UMA_HISTOGRAM_ENUMERATION("Sync.Startup.DeferredInitTrigger", UMA_HISTOGRAM_ENUMERATION("Sync.Startup.DeferredInitTrigger",
TRIGGER_FALLBACK_TIMER, MAX_TRIGGER_VALUE); TRIGGER_FALLBACK_TIMER, MAX_TRIGGER_VALUE);
received_start_request_ = true; bypass_deferred_startup_ = true;
TryStart(/*setup_in_progress=*/false); TryStart(/*force_immediate=*/false);
} }
StartupController::State StartupController::GetState() const { StartupController::State StartupController::GetState() const {
...@@ -183,8 +182,8 @@ void StartupController::OnDataTypeRequestsSyncStartup(ModelType type) { ...@@ -183,8 +182,8 @@ void StartupController::OnDataTypeRequestsSyncStartup(ModelType type) {
UMA_HISTOGRAM_ENUMERATION("Sync.Startup.DeferredInitTrigger", UMA_HISTOGRAM_ENUMERATION("Sync.Startup.DeferredInitTrigger",
TRIGGER_DATA_TYPE_REQUEST, MAX_TRIGGER_VALUE); TRIGGER_DATA_TYPE_REQUEST, MAX_TRIGGER_VALUE);
} }
received_start_request_ = true; bypass_deferred_startup_ = true;
TryStart(/*setup_in_progress=*/false); TryStart(/*force_immediate=*/false);
} }
} // namespace syncer } // namespace syncer
...@@ -37,15 +37,17 @@ class StartupController { ...@@ -37,15 +37,17 @@ class StartupController {
~StartupController(); ~StartupController();
// Starts up sync if it is requested by the user and preconditions are met. // Starts up sync if it is requested by the user and preconditions are met.
// If |setup_in_progress| is true, this will start sync immediately, bypassing // If |force_immediate| is true, this will start sync immediately, bypassing
// deferred startup and the "first setup complete" check. // deferred startup and the "first setup complete" check (but *not* the
// TODO(crbug.com/854978): Rename "setup_in_progress" to "force_immediate" or // |can_start_callback_| check!).
// something like that after TryStartImmediately is gone. void TryStart(bool force_immediate);
void TryStart(bool setup_in_progress);
// Tells the controller to bypass deferred startup and the "first setup
// Same as TryStart() above, but bypasses deferred startup and the first setup // complete" check. After this, any TryStart() calls (until a Reset()) will
// complete check. // cause immediate startup.
void TryStartImmediately(); // TODO(crbug.com/854978): See if we can get rid of this and just call
// TryStart(true) instead.
void SetBypassSetupCompleteAndDeferredStartup();
// Called when a datatype (SyncableService) has a need for sync to start // Called when a datatype (SyncableService) has a need for sync to start
// ASAP, presumably because a local change event has occurred but we're // ASAP, presumably because a local change event has occurred but we're
...@@ -85,13 +87,13 @@ class StartupController { ...@@ -85,13 +87,13 @@ class StartupController {
const base::RepeatingClosure start_engine_callback_; const base::RepeatingClosure start_engine_callback_;
// If true, will bypass the FirstSetupComplete check when triggering sync // If true, will bypass the FirstSetupComplete check when triggering sync
// startup. Set in TryStartImmediately. // startup. Set in SetBypassSetupCompleteAndDeferredStartup.
bool bypass_setup_complete_; bool bypass_setup_complete_;
// True if we should start sync ASAP because either a data type has // True if we should start sync ASAP because either a data type has requested
// requested it, or TryStartImmediately was called, or our deferred startup // it, or SetBypassSetupCompleteAndDeferredStartup was called, or our deferred
// timer has expired. // startup timer has expired.
bool received_start_request_; bool bypass_deferred_startup_;
// The time that StartUp() is called. This is used to calculate time spent // The time that StartUp() is called. This is used to calculate time spent
// in the deferred state; that is, after StartUp and before invoking the // in the deferred state; that is, after StartUp and before invoking the
......
...@@ -81,11 +81,11 @@ class StartupControllerTest : public testing::Test { ...@@ -81,11 +81,11 @@ class StartupControllerTest : public testing::Test {
// Test that sync doesn't start if setup is not in progress or complete. // Test that sync doesn't start if setup is not in progress or complete.
TEST_F(StartupControllerTest, NoSetupComplete) { TEST_F(StartupControllerTest, NoSetupComplete) {
controller()->TryStart(/*setup_in_progress=*/false); controller()->TryStart(/*force_immediate=*/false);
ExpectNotStarted(); ExpectNotStarted();
SetCanStart(true); SetCanStart(true);
controller()->TryStart(/*setup_in_progress=*/false); controller()->TryStart(/*force_immediate=*/false);
ExpectNotStarted(); ExpectNotStarted();
} }
...@@ -93,7 +93,7 @@ TEST_F(StartupControllerTest, NoSetupComplete) { ...@@ -93,7 +93,7 @@ TEST_F(StartupControllerTest, NoSetupComplete) {
TEST_F(StartupControllerTest, DefersAfterFirstSetupComplete) { TEST_F(StartupControllerTest, DefersAfterFirstSetupComplete) {
sync_prefs()->SetFirstSetupComplete(); sync_prefs()->SetFirstSetupComplete();
SetCanStart(true); SetCanStart(true);
controller()->TryStart(/*setup_in_progress=*/false); controller()->TryStart(/*force_immediate=*/false);
ExpectStartDeferred(); ExpectStartDeferred();
} }
...@@ -110,7 +110,7 @@ TEST_F(StartupControllerTest, NoDeferralDataTypeTrigger) { ...@@ -110,7 +110,7 @@ TEST_F(StartupControllerTest, NoDeferralDataTypeTrigger) {
TEST_F(StartupControllerTest, DataTypeTriggerInterruptsDeferral) { TEST_F(StartupControllerTest, DataTypeTriggerInterruptsDeferral) {
sync_prefs()->SetFirstSetupComplete(); sync_prefs()->SetFirstSetupComplete();
SetCanStart(true); SetCanStart(true);
controller()->TryStart(/*setup_in_progress=*/false); controller()->TryStart(/*force_immediate=*/false);
ExpectStartDeferred(); ExpectStartDeferred();
controller()->OnDataTypeRequestsSyncStartup(SESSIONS); controller()->OnDataTypeRequestsSyncStartup(SESSIONS);
...@@ -128,7 +128,7 @@ TEST_F(StartupControllerTest, DataTypeTriggerInterruptsDeferral) { ...@@ -128,7 +128,7 @@ TEST_F(StartupControllerTest, DataTypeTriggerInterruptsDeferral) {
TEST_F(StartupControllerTest, FallbackTimer) { TEST_F(StartupControllerTest, FallbackTimer) {
sync_prefs()->SetFirstSetupComplete(); sync_prefs()->SetFirstSetupComplete();
SetCanStart(true); SetCanStart(true);
controller()->TryStart(/*setup_in_progress=*/false); controller()->TryStart(/*force_immediate=*/false);
ExpectStartDeferred(); ExpectStartDeferred();
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
...@@ -147,14 +147,14 @@ TEST_F(StartupControllerTest, NoDeferralWithoutSessionsSync) { ...@@ -147,14 +147,14 @@ TEST_F(StartupControllerTest, NoDeferralWithoutSessionsSync) {
sync_prefs()->SetFirstSetupComplete(); sync_prefs()->SetFirstSetupComplete();
SetCanStart(true); SetCanStart(true);
controller()->TryStart(/*setup_in_progress=*/false); controller()->TryStart(/*force_immediate=*/false);
ExpectStarted(); ExpectStarted();
} }
// Sanity check that the fallback timer doesn't fire before startup // Sanity check that the fallback timer doesn't fire before startup
// conditions are met. // conditions are met.
TEST_F(StartupControllerTest, FallbackTimerWaits) { TEST_F(StartupControllerTest, FallbackTimerWaits) {
controller()->TryStart(/*setup_in_progress=*/false); controller()->TryStart(/*force_immediate=*/false);
ExpectNotStarted(); ExpectNotStarted();
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
ExpectNotStarted(); ExpectNotStarted();
...@@ -164,7 +164,7 @@ TEST_F(StartupControllerTest, FallbackTimerWaits) { ...@@ -164,7 +164,7 @@ TEST_F(StartupControllerTest, FallbackTimerWaits) {
TEST_F(StartupControllerTest, NoDeferralSetupInProgressTrigger) { TEST_F(StartupControllerTest, NoDeferralSetupInProgressTrigger) {
sync_prefs()->SetFirstSetupComplete(); sync_prefs()->SetFirstSetupComplete();
SetCanStart(true); SetCanStart(true);
controller()->TryStart(/*setup_in_progress=*/true); controller()->TryStart(/*force_immediate=*/true);
ExpectStarted(); ExpectStarted();
} }
...@@ -173,17 +173,20 @@ TEST_F(StartupControllerTest, NoDeferralSetupInProgressTrigger) { ...@@ -173,17 +173,20 @@ TEST_F(StartupControllerTest, NoDeferralSetupInProgressTrigger) {
TEST_F(StartupControllerTest, SetupInProgressTriggerInterruptsDeferral) { TEST_F(StartupControllerTest, SetupInProgressTriggerInterruptsDeferral) {
sync_prefs()->SetFirstSetupComplete(); sync_prefs()->SetFirstSetupComplete();
SetCanStart(true); SetCanStart(true);
controller()->TryStart(/*setup_in_progress=*/false); controller()->TryStart(/*force_immediate=*/false);
ExpectStartDeferred(); ExpectStartDeferred();
controller()->TryStart(/*setup_in_progress=*/true); controller()->TryStart(/*force_immediate=*/true);
ExpectStarted(); ExpectStarted();
} }
// Test that immediate startup can be forced. // Test that deferred startup and the FirstSetupComplete check can be bypassed.
TEST_F(StartupControllerTest, ForceImmediateStartup) { TEST_F(StartupControllerTest, BypassDeferredStartupAndSetupCompleteCheck) {
SetCanStart(true); SetCanStart(true);
controller()->TryStartImmediately(); controller()->SetBypassSetupCompleteAndDeferredStartup();
ASSERT_FALSE(sync_prefs()->IsFirstSetupComplete());
ExpectNotStarted();
controller()->TryStart(/*force_immediate=*/false);
ExpectStarted(); ExpectStarted();
} }
......
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