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