Commit 17ca1493 authored by tim@chromium.org's avatar tim@chromium.org

sync: reland deferred init

TBR=nyquist@chromium.org
BUG=80194,348951

Review URL: https://codereview.chromium.org/183563004

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@255890 0039d316-1c4b-4281-b951-d872f2087c98
parent d23cdeee
......@@ -27,7 +27,8 @@ class SyncTest(test_case.HostDrivenTestCase):
# These ought not to change in the middle of a test for obvious reasons.
self.additional_flags = [
'--sync-url=http://%s:%d/chromiumsync' %
(self.test_server.host, self.test_server.port)]
(self.test_server.host, self.test_server.port),
'--sync-deferred-startup-timeout-seconds=0']
super(SyncTest, self).SetUp(device, shard_index, push_deps,
cleanup_test_files,
[self.test_server.port])
......
......@@ -7,6 +7,7 @@
#include "base/command_line.h"
#include "base/message_loop/message_loop.h"
#include "base/metrics/histogram.h"
#include "base/strings/string_number_conversions.h"
#include "chrome/browser/managed_mode/managed_user_signin_manager_wrapper.h"
#include "chrome/browser/signin/profile_oauth2_token_service.h"
#include "chrome/browser/sync/sync_prefs.h"
......@@ -46,9 +47,22 @@ StartupController::StartupController(
token_service_(token_service),
signin_(signin),
start_backend_(start_backend),
fallback_timeout_(
base::TimeDelta::FromSeconds(kDeferredInitFallbackSeconds)),
weak_factory_(this) {}
fallback_timeout_(base::TimeDelta::FromSeconds(
kDeferredInitFallbackSeconds)),
weak_factory_(this) {
if (CommandLine::ForCurrentProcess()->HasSwitch(
switches::kSyncDeferredStartupTimeoutSeconds)) {
int timeout = kDeferredInitFallbackSeconds;
if (base::StringToInt(CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
switches::kSyncDeferredStartupTimeoutSeconds), &timeout)) {
DCHECK_GE(0, timeout);
DVLOG(2) << "Sync StartupController overriding startup timeout to "
<< timeout << " seconds.";
fallback_timeout_ = base::TimeDelta::FromSeconds(timeout);
}
}
}
StartupController::~StartupController() {}
......@@ -72,8 +86,8 @@ bool StartupController::StartUp(StartUpDeferredOption deferred_option) {
start_up_time_ = base::Time::Now();
if (deferred_option == STARTUP_BACKEND_DEFERRED &&
CommandLine::ForCurrentProcess()->HasSwitch(
switches::kSyncEnableDeferredStartup) &&
!CommandLine::ForCurrentProcess()->HasSwitch(
switches::kSyncDisableDeferredStartup) &&
sync_prefs_->GetPreferredDataTypes(registered_types_)
.Has(syncer::SESSIONS)) {
if (first_start) {
......@@ -152,8 +166,8 @@ bool StartupController::TryStart() {
}
void StartupController::OnFallbackStartupTimerExpired() {
DCHECK(CommandLine::ForCurrentProcess()->HasSwitch(
switches::kSyncEnableDeferredStartup));
DCHECK(!CommandLine::ForCurrentProcess()->HasSwitch(
switches::kSyncDisableDeferredStartup));
if (!start_backend_time_.is_null())
return;
......@@ -179,8 +193,8 @@ std::string StartupController::GetBackendInitializationStateString() const {
}
void StartupController::OnDataTypeRequestsSyncStartup(syncer::ModelType type) {
if (!CommandLine::ForCurrentProcess()->HasSwitch(
switches::kSyncEnableDeferredStartup)) {
if (CommandLine::ForCurrentProcess()->HasSwitch(
switches::kSyncDisableDeferredStartup)) {
DVLOG(2) << "Ignoring data type request for sync startup: "
<< syncer::ModelTypeToString(type);
return;
......
......@@ -86,15 +86,6 @@ class StartupControllerTest : public testing::Test {
started_ = true;
}
void ForceDeferredStartup() {
if (!CommandLine::ForCurrentProcess()->
HasSwitch(switches::kSyncEnableDeferredStartup)) {
CommandLine::ForCurrentProcess()->
AppendSwitch(switches::kSyncEnableDeferredStartup);
controller_->Reset(syncer::UserTypes());
}
}
bool started() const { return started_; }
void clear_started() { started_ = false; }
StartupController* controller() { return controller_.get(); }
......@@ -127,8 +118,8 @@ TEST_F(StartupControllerTest, Basic) {
controller()->TryStart();
EXPECT_FALSE(started());
token_service()->IssueRefreshTokenForUser(kTestUser, kTestToken);
const bool deferred_start = CommandLine::ForCurrentProcess()->
HasSwitch(switches::kSyncEnableDeferredStartup);
const bool deferred_start = !CommandLine::ForCurrentProcess()->
HasSwitch(switches::kSyncDisableDeferredStartup);
controller()->TryStart();
EXPECT_EQ(!deferred_start, started());
std::string state(controller()->GetBackendInitializationStateString());
......@@ -163,7 +154,6 @@ TEST_F(StartupControllerTest, Managed) {
// Test that sync doesn't start until all conditions are met and a
// data type triggers sync startup.
TEST_F(StartupControllerTest, DataTypeTriggered) {
ForceDeferredStartup();
sync_prefs()->SetSyncSetupCompleted();
signin()->set_account(kTestUser);
token_service()->IssueRefreshTokenForUser(kTestUser, kTestToken);
......@@ -186,7 +176,6 @@ TEST_F(StartupControllerTest, DataTypeTriggered) {
// Test that the fallback timer starts sync in the event all
// conditions are met and no data type requests sync.
TEST_F(StartupControllerTest, FallbackTimer) {
ForceDeferredStartup();
sync_prefs()->SetSyncSetupCompleted();
signin()->set_account(kTestUser);
token_service()->IssueRefreshTokenForUser(kTestUser, kTestToken);
......@@ -206,8 +195,6 @@ TEST_F(StartupControllerTest, NoDeferralWithoutSessionsSync) {
types.Remove(syncer::MANAGED_USER_SETTINGS);
sync_prefs()->SetKeepEverythingSynced(false);
sync_prefs()->SetPreferredDataTypes(syncer::UserTypes(), types);
CommandLine::ForCurrentProcess()->AppendSwitch(
switches::kSyncEnableDeferredStartup);
controller()->Reset(syncer::UserTypes());
sync_prefs()->SetSyncSetupCompleted();
signin()->set_account(kTestUser);
......@@ -219,7 +206,6 @@ TEST_F(StartupControllerTest, NoDeferralWithoutSessionsSync) {
// Sanity check that the fallback timer doesn't fire before startup
// conditions are met.
TEST_F(StartupControllerTest, FallbackTimerWaits) {
ForceDeferredStartup();
controller()->TryStart();
EXPECT_FALSE(started());
base::RunLoop().RunUntilIdle();
......@@ -254,8 +240,8 @@ TEST_F(StartupControllerTest, Reset) {
controller()->Reset(syncer::UserTypes());
base::RunLoop().RunUntilIdle();
EXPECT_FALSE(started());
const bool deferred_start = CommandLine::ForCurrentProcess()->
HasSwitch(switches::kSyncEnableDeferredStartup);
const bool deferred_start = !CommandLine::ForCurrentProcess()->
HasSwitch(switches::kSyncDisableDeferredStartup);
controller()->TryStart();
EXPECT_EQ(!deferred_start, started());
controller()->OnDataTypeRequestsSyncStartup(syncer::SESSIONS);
......
......@@ -1402,7 +1402,11 @@ const char kSyncTrySsltcpFirstForXmpp[] = "sync-try-ssltcp-first-for-xmpp";
// Enables deferring sync backend initialization until user initiated changes
// occur.
const char kSyncEnableDeferredStartup[] = "sync-enable-deferred-startup";
const char kSyncDisableDeferredStartup[] = "sync-disable-deferred-startup";
// Allows overriding the deferred init fallback timeout.
const char kSyncDeferredStartupTimeoutSeconds[] =
"sync-deferred-startup-timeout-seconds";
// Enables feature to avoid unnecessary GetUpdate requests.
const char kSyncEnableGetUpdateAvoidance[] =
......
......@@ -377,7 +377,8 @@ extern const char kSyncNotificationHostPort[];
extern const char kSyncServiceURL[];
extern const char kSyncThrowUnrecoverableError[];
extern const char kSyncTrySsltcpFirstForXmpp[];
extern const char kSyncEnableDeferredStartup[];
extern const char kSyncDisableDeferredStartup[];
extern const char kSyncDeferredStartupTimeoutSeconds[];
extern const char kSyncEnableGetUpdateAvoidance[];
extern const char kSyncfsEnableDirectoryOperation[];
extern const char kTabCapture[];
......
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