@@ -0,0 +1,2263 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.%0A// Use of this source code is governed by a BSD-style license that can be%0A// found in the LICENSE file.%0A%0Apackage org.chromium.chrome.browser.sync;%0A%0Aimport org.chromium.base.ThreadUtils;%0A%0A/**%0A * Starts up the sync backend and notifies the caller once the backend finishes%0A * initializing or if the backend fails to start up.%0A */%0Apublic class SyncStartupHelper implements ProfileSyncService.SyncStateChangedListener %7B%0A    private static final String TAG = %22SyncStartupHelper%22;%0A    private final ProfileSyncService mProfileSyncService;%0A    private final Delegate mDelegate;%0A    private boolean mDestroyed;%0A%0A    /**%0A     * Callback interface for SyncStartupHelper.%0A     */%0A    public interface Delegate %7B%0A        // Invoked once the sync backend has successfully started up.%0A        public void startupComplete();%0A%0A        // Invoked if the sync backend failed to start up.%0A        public void startupFailed();%0A    %7D%0A%0A    public SyncStartupHelper(ProfileSyncService profileSyncService, Delegate delegate) %7B%0A        ThreadUtils.assertOnUiThread();%0A        mProfileSyncService = profileSyncService;%0A        mDelegate = delegate;%0A        assert mDelegate != null;%0A    %7D%0A%0A    public void startSync() %7B%0A        ThreadUtils.assertOnUiThread();%0A        assert !mDestroyed;%0A        if (mProfileSyncService.isSyncInitialized()) %7B%0A            // Sync is already initialized - notify the delegate.%0A            mDelegate.startupComplete();%0A        %7D else %7B%0A            // Tell the sync engine to start up.%0A            mProfileSyncService.syncSignIn();%0A            mProfileSyncService.addSyncStateChangedListener(SyncStartupHelper.this);%0A            syncStateChanged();%0A        %7D%0A    %7D%0A%0A    public void destroy() %7B%0A        ThreadUtils.assertOnUiThread();%0A        mProfileSyncService.removeSyncStateChangedListener(this);%0A        mDestroyed = true;%0A    %7D%0A%0A    @Override%0A    public void syncStateChanged() %7B%0A        if (mProfileSyncService.isSyncInitialized()) %7B%0A            mDelegate.startupComplete();%0A        %7D else if ((mProfileSyncService.getAuthError() != GoogleServiceAuthError.State.NONE)%0A                %7C%7C mProfileSyncService.hasUnrecoverableError()) %7B%0A            mDelegate.startupFailed();%0A        %7D%0A    %7D%0A%0A%7D%0A

Copy SyncStartupHelper upstream.