Commit 59a4c047 authored by Peter Kotwicz's avatar Peter Kotwicz Committed by Commit Bot

[Android FRE] Remove LightweightFirstRunActivity dependence on FirstRunActivity

This CL introduces FirstRunActivityBase which contains logic to be shared
between FirstRunActivity and LightweightFirstRunActivity.
This CL changes LightweightFirstRunActivity to extend
FirstRunActivityBase instead of FirstRunActivity.

BUG=755646

Change-Id: Id839e78361030aef6d7a5d2e94544760f3c117c8
Reviewed-on: https://chromium-review.googlesource.com/619252
Commit-Queue: Peter Kotwicz <pkotwicz@chromium.org>
Reviewed-by: default avatarBernhard Bauer <bauerb@chromium.org>
Reviewed-by: default avatarYusuf Ozuysal <yusufo@chromium.org>
Cr-Commit-Position: refs/heads/master@{#501173}
parent b3798f15
...@@ -6,31 +6,22 @@ package org.chromium.chrome.browser.firstrun; ...@@ -6,31 +6,22 @@ package org.chromium.chrome.browser.firstrun;
import android.app.Activity; import android.app.Activity;
import android.app.Fragment; import android.app.Fragment;
import android.app.PendingIntent;
import android.app.PendingIntent.CanceledException;
import android.content.Intent;
import android.os.Bundle; import android.os.Bundle;
import android.text.TextUtils; import android.text.TextUtils;
import org.chromium.base.ActivityState; import org.chromium.base.ActivityState;
import org.chromium.base.ApplicationStatus; import org.chromium.base.ApplicationStatus;
import org.chromium.base.ApplicationStatus.ActivityStateListener; import org.chromium.base.ApplicationStatus.ActivityStateListener;
import org.chromium.base.Log;
import org.chromium.base.VisibleForTesting; import org.chromium.base.VisibleForTesting;
import org.chromium.base.metrics.CachedMetrics.EnumeratedHistogramSample; import org.chromium.base.metrics.CachedMetrics.EnumeratedHistogramSample;
import org.chromium.chrome.R; import org.chromium.chrome.R;
import org.chromium.chrome.browser.customtabs.CustomTabActivity; import org.chromium.chrome.browser.customtabs.CustomTabActivity;
import org.chromium.chrome.browser.customtabs.CustomTabsConnection;
import org.chromium.chrome.browser.document.ChromeLauncherActivity;
import org.chromium.chrome.browser.init.AsyncInitializationActivity;
import org.chromium.chrome.browser.metrics.UmaUtils; import org.chromium.chrome.browser.metrics.UmaUtils;
import org.chromium.chrome.browser.net.spdyproxy.DataReductionProxySettings; import org.chromium.chrome.browser.net.spdyproxy.DataReductionProxySettings;
import org.chromium.chrome.browser.preferences.datareduction.DataReductionPromoUtils; import org.chromium.chrome.browser.preferences.datareduction.DataReductionPromoUtils;
import org.chromium.chrome.browser.preferences.datareduction.DataReductionProxyUma; import org.chromium.chrome.browser.preferences.datareduction.DataReductionProxyUma;
import org.chromium.chrome.browser.profiles.ProfileManagerUtils;
import org.chromium.chrome.browser.search_engines.TemplateUrlService; import org.chromium.chrome.browser.search_engines.TemplateUrlService;
import org.chromium.chrome.browser.searchwidget.SearchWidgetProvider; import org.chromium.chrome.browser.searchwidget.SearchWidgetProvider;
import org.chromium.chrome.browser.util.IntentUtils;
import org.chromium.ui.base.LocalizationUtils; import org.chromium.ui.base.LocalizationUtils;
import java.lang.reflect.Constructor; import java.lang.reflect.Constructor;
...@@ -48,7 +39,7 @@ import java.util.concurrent.Callable; ...@@ -48,7 +39,7 @@ import java.util.concurrent.Callable;
* [Sign-in page] * [Sign-in page]
* The activity might be run more than once, e.g. 1) for ToS and sign-in, and 2) for intro. * The activity might be run more than once, e.g. 1) for ToS and sign-in, and 2) for intro.
*/ */
public class FirstRunActivity extends AsyncInitializationActivity implements FirstRunPageDelegate { public class FirstRunActivity extends FirstRunActivityBase implements FirstRunPageDelegate {
/** Alerted about various events when FirstRunActivity performs them. */ /** Alerted about various events when FirstRunActivity performs them. */
public interface FirstRunActivityObserver { public interface FirstRunActivityObserver {
/** See {@link #onFlowIsKnown}. */ /** See {@link #onFlowIsKnown}. */
...@@ -67,12 +58,9 @@ public class FirstRunActivity extends AsyncInitializationActivity implements Fir ...@@ -67,12 +58,9 @@ public class FirstRunActivity extends AsyncInitializationActivity implements Fir
void onAbortFirstRunExperience(); void onAbortFirstRunExperience();
} }
protected static final String TAG = "FirstRunActivity";
// Incoming parameters: // Incoming parameters:
public static final String EXTRA_COMING_FROM_CHROME_ICON = "Extra.ComingFromChromeIcon"; public static final String EXTRA_COMING_FROM_CHROME_ICON = "Extra.ComingFromChromeIcon";
public static final String EXTRA_USE_FRE_FLOW_SEQUENCER = "Extra.UseFreFlowSequencer"; public static final String EXTRA_USE_FRE_FLOW_SEQUENCER = "Extra.UseFreFlowSequencer";
public static final String EXTRA_START_LIGHTWEIGHT_FRE = "Extra.StartLightweightFRE";
public static final String EXTRA_CHROME_LAUNCH_INTENT = "Extra.FreChromeLaunchIntent"; public static final String EXTRA_CHROME_LAUNCH_INTENT = "Extra.FreChromeLaunchIntent";
static final String SHOW_WELCOME_PAGE = "ShowWelcome"; static final String SHOW_WELCOME_PAGE = "ShowWelcome";
...@@ -195,12 +183,6 @@ public class FirstRunActivity extends AsyncInitializationActivity implements Fir ...@@ -195,12 +183,6 @@ public class FirstRunActivity extends AsyncInitializationActivity implements Fir
mPostNativePageSequenceCreated = true; mPostNativePageSequenceCreated = true;
} }
@Override
protected boolean requiresFirstRunToBeCompleted(Intent intent) {
// The user is already in First Run.
return false;
}
@Override @Override
protected Bundle transformSavedInstanceStateForOnCreate(Bundle savedInstanceState) { protected Bundle transformSavedInstanceStateForOnCreate(Bundle savedInstanceState) {
// We pass null to Activity.onCreate() so that it doesn't automatically restore // We pass null to Activity.onCreate() so that it doesn't automatically restore
...@@ -224,11 +206,6 @@ public class FirstRunActivity extends AsyncInitializationActivity implements Fir ...@@ -224,11 +206,6 @@ public class FirstRunActivity extends AsyncInitializationActivity implements Fir
setFinishOnTouchOutside(true); setFinishOnTouchOutside(true);
// Skip creating content view if it is to start a lightweight First Run Experience.
if (mFreProperties.getBoolean(FirstRunActivity.EXTRA_START_LIGHTWEIGHT_FRE)) {
return;
}
mPager = new FirstRunViewPager(this); mPager = new FirstRunViewPager(this);
mPager.setId(R.id.fre_pager); mPager.setId(R.id.fre_pager);
mPager.setOffscreenPageLimit(3); mPager.setOffscreenPageLimit(3);
...@@ -312,11 +289,6 @@ public class FirstRunActivity extends AsyncInitializationActivity implements Fir ...@@ -312,11 +289,6 @@ public class FirstRunActivity extends AsyncInitializationActivity implements Fir
} }
} }
@Override
public boolean shouldStartGpuProcess() {
return true;
}
// Activity: // Activity:
@Override @Override
...@@ -352,21 +324,9 @@ public class FirstRunActivity extends AsyncInitializationActivity implements Fir ...@@ -352,21 +324,9 @@ public class FirstRunActivity extends AsyncInitializationActivity implements Fir
super.onRestoreInstanceState(new Bundle()); super.onRestoreInstanceState(new Bundle());
} }
@Override
public void onPause() {
super.onPause();
flushPersistentData();
}
@Override @Override
public void onStart() { public void onStart() {
super.onStart(); super.onStart();
// Since the FRE may be shown before any tab is shown, mark that this is the point at
// which Chrome went to foreground. This is needed as otherwise an assert will be hit
// in UmaUtils.getForegroundStartTime() when recording the time taken to load the first
// page (which happens after native has been initialized possibly while FRE is still
// active).
UmaUtils.recordForegroundStartTime();
stopProgressionIfNotAcceptedTermsOfService(); stopProgressionIfNotAcceptedTermsOfService();
} }
...@@ -502,51 +462,6 @@ public class FirstRunActivity extends AsyncInitializationActivity implements Fir ...@@ -502,51 +462,6 @@ public class FirstRunActivity extends AsyncInitializationActivity implements Fir
jumpToPage(mPager.getCurrentItem() + 1); jumpToPage(mPager.getCurrentItem() + 1);
} }
protected void flushPersistentData() {
if (mNativeSideIsInitialized) {
ProfileManagerUtils.flushPersistentDataForAllProfiles();
}
}
/**
* Sends the PendingIntent included with the CHROME_LAUNCH_INTENT extra if it exists.
* @param complete Whether first run completed successfully.
* @return Whether a pending intent was sent.
*/
protected final boolean sendPendingIntentIfNecessary(final boolean complete) {
PendingIntent pendingIntent = IntentUtils.safeGetParcelableExtra(getIntent(),
EXTRA_CHROME_LAUNCH_INTENT);
if (pendingIntent == null) return false;
Intent extraDataIntent = new Intent();
extraDataIntent.putExtra(FirstRunActivity.EXTRA_FIRST_RUN_ACTIVITY_RESULT, true);
extraDataIntent.putExtra(FirstRunActivity.EXTRA_FIRST_RUN_COMPLETE, complete);
try {
// After the PendingIntent has been sent, send a first run callback to custom tabs if
// necessary.
PendingIntent.OnFinished onFinished = new PendingIntent.OnFinished() {
@Override
public void onSendFinished(PendingIntent pendingIntent, Intent intent,
int resultCode, String resultData, Bundle resultExtras) {
if (ChromeLauncherActivity.isCustomTabIntent(intent)) {
CustomTabsConnection.getInstance().sendFirstRunCallbackIfNecessary(
intent, complete);
}
}
};
// Use the PendingIntent to send the intent that originally launched Chrome. The intent
// will go back to the ChromeLauncherActivity, which will route it accordingly.
pendingIntent.send(this, complete ? Activity.RESULT_OK : Activity.RESULT_CANCELED,
extraDataIntent, onFinished, null);
return true;
} catch (CanceledException e) {
Log.e(TAG, "Unable to send PendingIntent.", e);
}
return false;
}
/** /**
* Transitions to a given page. * Transitions to a given page.
* @return Whether the transition to a given page was allowed. * @return Whether the transition to a given page was allowed.
......
// Copyright 2015 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.firstrun;
import android.app.Activity;
import android.app.PendingIntent;
import android.app.PendingIntent.CanceledException;
import android.content.Intent;
import android.os.Bundle;
import org.chromium.base.Log;
import org.chromium.chrome.browser.customtabs.CustomTabsConnection;
import org.chromium.chrome.browser.document.ChromeLauncherActivity;
import org.chromium.chrome.browser.init.AsyncInitializationActivity;
import org.chromium.chrome.browser.metrics.UmaUtils;
import org.chromium.chrome.browser.profiles.ProfileManagerUtils;
import org.chromium.chrome.browser.util.IntentUtils;
/** Base class for First Run Experience. */
public abstract class FirstRunActivityBase extends AsyncInitializationActivity {
private static final String TAG = "FirstRunActivity";
private boolean mNativeInitialized;
@Override
protected boolean requiresFirstRunToBeCompleted(Intent intent) {
// The user is already in First Run.
return false;
}
@Override
public boolean shouldStartGpuProcess() {
return true;
}
// Activity:
@Override
public void onPause() {
super.onPause();
flushPersistentData();
}
@Override
public void onStart() {
super.onStart();
// Since the FRE may be shown before any tab is shown, mark that this is the point at
// which Chrome went to foreground. This is needed as otherwise an assert will be hit
// in UmaUtils.getForegroundStartTime() when recording the time taken to load the first
// page (which happens after native has been initialized possibly while FRE is still
// active).
UmaUtils.recordForegroundStartTime();
}
@Override
public void finishNativeInitialization() {
super.finishNativeInitialization();
mNativeInitialized = true;
}
protected void flushPersistentData() {
if (mNativeInitialized) {
ProfileManagerUtils.flushPersistentDataForAllProfiles();
}
}
/**
* Sends the PendingIntent included with the CHROME_LAUNCH_INTENT extra if it exists.
* @param complete Whether first run completed successfully.
* @return Whether a pending intent was sent.
*/
protected final boolean sendPendingIntentIfNecessary(final boolean complete) {
PendingIntent pendingIntent = IntentUtils.safeGetParcelableExtra(
getIntent(), FirstRunActivity.EXTRA_CHROME_LAUNCH_INTENT);
if (pendingIntent == null) return false;
Intent extraDataIntent = new Intent();
extraDataIntent.putExtra(FirstRunActivity.EXTRA_FIRST_RUN_ACTIVITY_RESULT, true);
extraDataIntent.putExtra(FirstRunActivity.EXTRA_FIRST_RUN_COMPLETE, complete);
try {
// After the PendingIntent has been sent, send a first run callback to custom tabs if
// necessary.
PendingIntent.OnFinished onFinished = new PendingIntent.OnFinished() {
@Override
public void onSendFinished(PendingIntent pendingIntent, Intent intent,
int resultCode, String resultData, Bundle resultExtras) {
if (ChromeLauncherActivity.isCustomTabIntent(intent)) {
CustomTabsConnection.getInstance().sendFirstRunCallbackIfNecessary(
intent, complete);
}
}
};
// Use the PendingIntent to send the intent that originally launched Chrome. The intent
// will go back to the ChromeLauncherActivity, which will route it accordingly.
pendingIntent.send(this, complete ? Activity.RESULT_OK : Activity.RESULT_CANCELED,
extraDataIntent, onFinished, null);
return true;
} catch (CanceledException e) {
Log.e(TAG, "Unable to send PendingIntent.", e);
}
return false;
}
}
...@@ -297,7 +297,6 @@ public abstract class FirstRunFlowSequencer { ...@@ -297,7 +297,6 @@ public abstract class FirstRunFlowSequencer {
Intent intent = new Intent(); Intent intent = new Intent();
intent.setClassName(context, LightweightFirstRunActivity.class.getName()); intent.setClassName(context, LightweightFirstRunActivity.class.getName());
intent.putExtra(FirstRunActivity.EXTRA_COMING_FROM_CHROME_ICON, fromChromeIcon); intent.putExtra(FirstRunActivity.EXTRA_COMING_FROM_CHROME_ICON, fromChromeIcon);
intent.putExtra(FirstRunActivity.EXTRA_START_LIGHTWEIGHT_FRE, true);
return intent; return intent;
} }
...@@ -369,8 +368,7 @@ public abstract class FirstRunFlowSequencer { ...@@ -369,8 +368,7 @@ public abstract class FirstRunFlowSequencer {
List<WeakReference<Activity>> activities = ApplicationStatus.getRunningActivities(); List<WeakReference<Activity>> activities = ApplicationStatus.getRunningActivities();
for (WeakReference<Activity> weakActivity : activities) { for (WeakReference<Activity> weakActivity : activities) {
Activity activity = weakActivity.get(); Activity activity = weakActivity.get();
if (activity instanceof FirstRunActivity if (activity instanceof FirstRunActivity) {
&& !(activity instanceof LightweightFirstRunActivity)) {
isGenericFreActive = true; isGenericFreActive = true;
break; break;
} }
......
...@@ -23,18 +23,19 @@ import org.chromium.ui.text.SpanApplier.SpanInfo; ...@@ -23,18 +23,19 @@ import org.chromium.ui.text.SpanApplier.SpanInfo;
/** /**
* Lightweight FirstRunActivity. It shows ToS dialog only. * Lightweight FirstRunActivity. It shows ToS dialog only.
*/ */
public class LightweightFirstRunActivity extends FirstRunActivity { public class LightweightFirstRunActivity extends FirstRunActivityBase {
private Button mOkButton; private Button mOkButton;
private boolean mNativeInitialized; private boolean mNativeInitialized;
private boolean mTriggerAcceptAfterNativeInit; private boolean mTriggerAcceptAfterNativeInit;
@Override @Override
public void setContentView() { public void setContentView() {
super.setContentView();
if (CommandLine.getInstance().hasSwitch(ChromeSwitches.DISABLE_FIRST_RUN_EXPERIENCE)) { if (CommandLine.getInstance().hasSwitch(ChromeSwitches.DISABLE_FIRST_RUN_EXPERIENCE)) {
completeFirstRunExperience(); completeFirstRunExperience();
} }
setFinishOnTouchOutside(true);
setContentView(LayoutInflater.from(LightweightFirstRunActivity.this) setContentView(LayoutInflater.from(LightweightFirstRunActivity.this)
.inflate(R.layout.lightweight_fre_tos, null)); .inflate(R.layout.lightweight_fre_tos, null));
...@@ -88,6 +89,15 @@ public class LightweightFirstRunActivity extends FirstRunActivity { ...@@ -88,6 +89,15 @@ public class LightweightFirstRunActivity extends FirstRunActivity {
} }
@Override @Override
public void onBackPressed() {
abortFirstRunExperience();
}
public void abortFirstRunExperience() {
finish();
sendPendingIntentIfNecessary(false);
}
public void completeFirstRunExperience() { public void completeFirstRunExperience() {
FirstRunStatus.setLightweightFirstRunFlowComplete(true); FirstRunStatus.setLightweightFirstRunFlowComplete(true);
finish(); finish();
......
...@@ -403,6 +403,7 @@ chrome_java_sources = [ ...@@ -403,6 +403,7 @@ chrome_java_sources = [
"java/src/org/chromium/chrome/browser/firstrun/FirstRunChooserView.java", "java/src/org/chromium/chrome/browser/firstrun/FirstRunChooserView.java",
"java/src/org/chromium/chrome/browser/firstrun/LightweightFirstRunActivity.java", "java/src/org/chromium/chrome/browser/firstrun/LightweightFirstRunActivity.java",
"java/src/org/chromium/chrome/browser/firstrun/FirstRunActivity.java", "java/src/org/chromium/chrome/browser/firstrun/FirstRunActivity.java",
"java/src/org/chromium/chrome/browser/firstrun/FirstRunActivityBase.java",
"java/src/org/chromium/chrome/browser/firstrun/FirstRunFlowSequencer.java", "java/src/org/chromium/chrome/browser/firstrun/FirstRunFlowSequencer.java",
"java/src/org/chromium/chrome/browser/firstrun/FirstRunPage.java", "java/src/org/chromium/chrome/browser/firstrun/FirstRunPage.java",
"java/src/org/chromium/chrome/browser/firstrun/FirstRunPageDelegate.java", "java/src/org/chromium/chrome/browser/firstrun/FirstRunPageDelegate.java",
......
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