Chromium Code Reviews| Index: chrome/android/java/src/org/chromium/chrome/browser/document/UpgradeActivity.java |
| diff --git a/chrome/android/java/src/org/chromium/chrome/browser/document/UpgradeActivity.java b/chrome/android/java/src/org/chromium/chrome/browser/document/UpgradeActivity.java |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..059b03af124518c9073eb48492136d29b7c23edb |
| --- /dev/null |
| +++ b/chrome/android/java/src/org/chromium/chrome/browser/document/UpgradeActivity.java |
| @@ -0,0 +1,102 @@ |
| +// Copyright 2016 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +package org.chromium.chrome.browser.document; |
| + |
| +import android.content.Context; |
| +import android.content.Intent; |
| +import android.os.Bundle; |
| +import android.os.Handler; |
| +import android.os.Looper; |
| +import android.support.v7.app.AppCompatActivity; |
| + |
| +import org.chromium.chrome.R; |
| +import org.chromium.chrome.browser.tabmodel.DocumentModeAssassin; |
| +import org.chromium.chrome.browser.tabmodel.DocumentModeAssassin.DocumentModeAssassinObserver; |
| +import org.chromium.chrome.browser.util.IntentUtils; |
| + |
| +/** |
| + * Activity that appears when users are being upgraded to another version of Chrome. |
| + * |
| + * TODO(dfalcantara): Do we need to worry about onNewIntent()? |
| + */ |
| +public class UpgradeActivity extends AppCompatActivity { |
| + public static final String EXTRA_INTENT_TO_REFIRE = |
| + "org.chromium.chrome.browser.document.INTENT_TO_REFIRE"; |
| + |
| + private static final long MIN_MS_TO_DISPLAY_ACTIVITY = 500; |
| + |
| + private final Handler mHandler; |
| + private final DocumentModeAssassinObserver mObserver; |
| + |
| + private boolean mHasStartedMigration; |
| + private long mStartTimestamp; |
| + |
| + public static void launchInstance(Context context, Intent originalIntent) { |
| + Intent intent = new Intent(); |
| + intent.setClass(context, UpgradeActivity.class); |
| + intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| + intent.putExtra(UpgradeActivity.EXTRA_INTENT_TO_REFIRE, originalIntent); |
| + context.startActivity(intent); |
| + } |
| + |
| + public UpgradeActivity() { |
| + mHandler = new Handler(Looper.getMainLooper()); |
| + |
| + mObserver = new DocumentModeAssassinObserver() { |
| + private boolean mAlreadyRan; |
| + |
| + @Override |
| + public void onStageChange(int newStage) { |
| + if (newStage != DocumentModeAssassin.STAGE_DONE || mAlreadyRan) return; |
| + mAlreadyRan = true; |
|
Ted C
2016/03/25 17:38:05
how could we hit the already ran case? Or is this
gone
2016/03/25 22:05:41
Paranoia. I'd suggest asserting, but it seems lik
|
| + DocumentModeAssassin.getInstance().removeObserver(this); |
| + |
| + // Always post to avoid any issues that could arise from firing the Runnable |
| + // while other Observers are being alerted. |
| + long msElapsed = System.currentTimeMillis() - mStartTimestamp; |
| + long msRemaining = Math.max(0, MIN_MS_TO_DISPLAY_ACTIVITY - msElapsed); |
| + Runnable continueExecutionRunnable = new Runnable() { |
| + @Override |
| + public void run() { |
| + continueExecution(); |
|
Ted C
2016/03/25 17:38:05
if the activity is destroyed before this is called
gone
2016/03/25 22:05:42
Reshuffled code around a bit to make it more robus
|
| + } |
| + }; |
| + mHandler.postDelayed(continueExecutionRunnable, msRemaining); |
| + } |
| + }; |
| + } |
| + |
| + @Override |
| + protected void onCreate(Bundle savedInstanceState) { |
| + super.onCreate(savedInstanceState); |
| + |
| + // Migration might have finished in the background. |
| + DocumentModeAssassin assassin = DocumentModeAssassin.getInstance(); |
| + if (!DocumentModeAssassin.isMigrationNecessary() |
| + || assassin.getStage() == DocumentModeAssassin.STAGE_DONE) { |
| + continueExecution(); |
| + return; |
| + } |
| + |
| + // Kick off migration and wait for it to finish. |
| + setContentView(R.layout.upgrade_activity); |
| + mStartTimestamp = System.currentTimeMillis(); |
| + assassin.addObserver(mObserver); |
| + assassin.migrateFromDocumentToTabbedMode(); |
| + } |
| + |
| + private void continueExecution() { |
| + finish(); |
| + |
| + // Fire the Intent that caused the user to end up on the migration pathway. |
| + Intent intent = |
| + (Intent) IntentUtils.safeGetParcelableExtra(getIntent(), EXTRA_INTENT_TO_REFIRE); |
| + if (intent != null) { |
| + intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_NEW_DOCUMENT); |
| + startActivity(intent); |
| + overridePendingTransition(android.R.anim.fade_in, 0); |
| + } |
|
Ted C
2016/03/25 17:38:05
should we try to launch a main intent otherwise?
gone
2016/03/25 22:05:41
Done.
|
| + } |
| +} |