Commit 3306a492 authored by Jeffrey Cohen's avatar Jeffrey Cohen Committed by Commit Bot

[Screenshot] retrying installation closes fallback dialog.

The fallback dialog passes its dismissal runnable to be called on a
successful image_editor installation.

Bug: 1117675
Change-Id: I08a536b77ec459741940d20082b270aa4e900f1f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2363813
Commit-Queue: Jeffrey Cohen <jeffreycohen@chromium.org>
Reviewed-by: default avatarTanya Gupta <tgupta@chromium.org>
Cr-Commit-Position: refs/heads/master@{#800262}
parent 9684040e
...@@ -66,7 +66,7 @@ public class ScreenshotCoordinator { ...@@ -66,7 +66,7 @@ public class ScreenshotCoordinator {
launchEditor(); launchEditor();
} else if (sInstallAttempts < MAX_INSTALL_ATTEMPTS) { } else if (sInstallAttempts < MAX_INSTALL_ATTEMPTS) {
sInstallAttempts++; sInstallAttempts++;
installEditor(true); installEditor(true, /* onSuccessRunnable= */ null);
} else { } else {
launchSharesheet(); launchSharesheet();
} }
...@@ -95,17 +95,19 @@ public class ScreenshotCoordinator { ...@@ -95,17 +95,19 @@ public class ScreenshotCoordinator {
/** /**
* Runnable friendly helper function to retry the installation after going to the fallback. * Runnable friendly helper function to retry the installation after going to the fallback.
* @param onSuccess. Runnable to run on success.
*/ */
protected void retryInstallEditor() { protected void retryInstallEditor(Runnable onSuccess) {
installEditor(false); installEditor(false, onSuccess);
} }
/** /**
* Installs the DFM and shows UI (i.e. toasts and a retry dialog) informing the * Installs the DFM and shows UI (i.e. toasts and a retry dialog) informing the
* user of the installation status. * user of the installation status.
* @param showFallback The fallback will be shown on a unsuccessful installation. * @param showFallback The fallback will be shown on a unsuccessful installation.
* @param onSuccessRunnable the runnable to run on a succesfful install.
*/ */
private void installEditor(boolean showFallback) { private void installEditor(boolean showFallback, Runnable onSuccessRunnable) {
final ModuleInstallUi ui = new ModuleInstallUi( final ModuleInstallUi ui = new ModuleInstallUi(
mTab, R.string.image_editor_module_title, new ModuleInstallUi.FailureUiListener() { mTab, R.string.image_editor_module_title, new ModuleInstallUi.FailureUiListener() {
@Override @Override
...@@ -113,7 +115,7 @@ public class ScreenshotCoordinator { ...@@ -113,7 +115,7 @@ public class ScreenshotCoordinator {
if (retry) { if (retry) {
// User initiated retries are not counted toward the maximum number // User initiated retries are not counted toward the maximum number
// of install attempts per session. // of install attempts per session.
installEditor(showFallback); installEditor(showFallback, onSuccessRunnable);
} else if (showFallback) { } else if (showFallback) {
launchSharesheet(); launchSharesheet();
} }
...@@ -124,6 +126,9 @@ public class ScreenshotCoordinator { ...@@ -124,6 +126,9 @@ public class ScreenshotCoordinator {
ImageEditorModuleProvider.maybeInstallModule((success) -> { ImageEditorModuleProvider.maybeInstallModule((success) -> {
if (success) { if (success) {
ui.showInstallSuccessUi(); ui.showInstallSuccessUi();
if (onSuccessRunnable != null) {
onSuccessRunnable.run();
}
launchEditor(); launchEditor();
} else if (showFallback) { } else if (showFallback) {
launchSharesheet(); launchSharesheet();
......
...@@ -7,6 +7,7 @@ package org.chromium.chrome.browser.share.screenshot; ...@@ -7,6 +7,7 @@ package org.chromium.chrome.browser.share.screenshot;
import android.content.Context; import android.content.Context;
import android.graphics.Bitmap; import android.graphics.Bitmap;
import org.chromium.base.Callback;
import org.chromium.chrome.browser.share.share_sheet.ChromeOptionShareCallback; import org.chromium.chrome.browser.share.share_sheet.ChromeOptionShareCallback;
import org.chromium.chrome.browser.tab.Tab; import org.chromium.chrome.browser.tab.Tab;
import org.chromium.ui.modelutil.PropertyKey; import org.chromium.ui.modelutil.PropertyKey;
...@@ -33,11 +34,11 @@ public class ScreenshotShareSheetCoordinator { ...@@ -33,11 +34,11 @@ public class ScreenshotShareSheetCoordinator {
* @param screenshotShareSheetView the view for the screenshot share sheet. * @param screenshotShareSheetView the view for the screenshot share sheet.
* @param tab The tab that launched this screenshot. * @param tab The tab that launched this screenshot.
* @param shareSheetCallback The callback to be called on share. * @param shareSheetCallback The callback to be called on share.
* @param deleteRunanble The runnable to be called on retry. * @param installCallback The callback to be called on retry.
*/ */
public ScreenshotShareSheetCoordinator(Context context, Bitmap screenshot, public ScreenshotShareSheetCoordinator(Context context, Bitmap screenshot,
Runnable deleteRunnable, ScreenshotShareSheetView screenshotShareSheetView, Tab tab, Runnable deleteRunnable, ScreenshotShareSheetView screenshotShareSheetView, Tab tab,
ChromeOptionShareCallback shareSheetCallback, Runnable installCallback) { ChromeOptionShareCallback shareSheetCallback, Callback<Runnable> installCallback) {
ArrayList<PropertyKey> allProperties = ArrayList<PropertyKey> allProperties =
new ArrayList<>(Arrays.asList(ScreenshotShareSheetViewProperties.ALL_KEYS)); new ArrayList<>(Arrays.asList(ScreenshotShareSheetViewProperties.ALL_KEYS));
mModel = new PropertyModel(allProperties); mModel = new PropertyModel(allProperties);
......
...@@ -12,6 +12,7 @@ import android.os.Bundle; ...@@ -12,6 +12,7 @@ import android.os.Bundle;
import androidx.appcompat.app.AlertDialog; import androidx.appcompat.app.AlertDialog;
import org.chromium.base.Callback;
import org.chromium.chrome.R; import org.chromium.chrome.R;
import org.chromium.chrome.browser.share.share_sheet.ChromeOptionShareCallback; import org.chromium.chrome.browser.share.share_sheet.ChromeOptionShareCallback;
import org.chromium.chrome.browser.tab.Tab; import org.chromium.chrome.browser.tab.Tab;
...@@ -23,10 +24,9 @@ public class ScreenshotShareSheetDialog extends DialogFragment { ...@@ -23,10 +24,9 @@ public class ScreenshotShareSheetDialog extends DialogFragment {
private Context mContext; private Context mContext;
private ScreenshotShareSheetView mDialogView; private ScreenshotShareSheetView mDialogView;
private Bitmap mScreenshot; private Bitmap mScreenshot;
private Runnable mDeleteRunnable;
private Tab mTab; private Tab mTab;
private ChromeOptionShareCallback mShareCallback; private ChromeOptionShareCallback mChromeOptionShareCallback;
private Runnable mInstallCallback; private Callback<Runnable> mInstallCallback;
/** /**
* The ScreenshotShareSheetDialog constructor. * The ScreenshotShareSheetDialog constructor.
...@@ -36,17 +36,17 @@ public class ScreenshotShareSheetDialog extends DialogFragment { ...@@ -36,17 +36,17 @@ public class ScreenshotShareSheetDialog extends DialogFragment {
/** /**
* Initialize the dialog outside of the constructor as fragments require default constructor. * Initialize the dialog outside of the constructor as fragments require default constructor.
* @param screenshot The screenshot image to show. * @param screenshot The screenshot image to show.
* @param deleteRunnable The function to call on delete.
* @param tab The shared tab. * @param tab The shared tab.
* @param shareSheetCoordnator the base share sheet coordinator * @param chromeOptionShareCallback the callback to trigger on share.
* @param installCallback the callback to trigger on install.
*/ */
public void init(Bitmap screenshot, Runnable deleteRunnable, Tab tab, public void init(Bitmap screenshot, Tab tab,
ChromeOptionShareCallback shareSheetCallback, Runnable installCallback) { ChromeOptionShareCallback chromeOptionShareCallback,
Callback<Runnable> installCallback) {
mScreenshot = screenshot; mScreenshot = screenshot;
mDeleteRunnable = deleteRunnable;
mInstallCallback = installCallback; mInstallCallback = installCallback;
mTab = tab; mTab = tab;
mShareCallback = shareSheetCallback; mChromeOptionShareCallback = chromeOptionShareCallback;
} }
@Override @Override
...@@ -64,9 +64,9 @@ public class ScreenshotShareSheetDialog extends DialogFragment { ...@@ -64,9 +64,9 @@ public class ScreenshotShareSheetDialog extends DialogFragment {
R.layout.screenshot_share_sheet, null); R.layout.screenshot_share_sheet, null);
builder.setView(screenshotShareSheetView); builder.setView(screenshotShareSheetView);
ScreenshotShareSheetCoordinator shareCoordinator = ScreenshotShareSheetCoordinator shareCoordinator = new ScreenshotShareSheetCoordinator(
new ScreenshotShareSheetCoordinator(mContext, mScreenshot, mDeleteRunnable, mContext, mScreenshot, this::dismiss, screenshotShareSheetView, mTab,
screenshotShareSheetView, mTab, mShareCallback, mInstallCallback); mChromeOptionShareCallback, mInstallCallback);
return builder.create(); return builder.create();
} }
} }
...@@ -8,6 +8,7 @@ import android.app.Activity; ...@@ -8,6 +8,7 @@ import android.app.Activity;
import android.app.FragmentManager; import android.app.FragmentManager;
import android.graphics.Bitmap; import android.graphics.Bitmap;
import org.chromium.base.Callback;
import org.chromium.chrome.browser.share.share_sheet.ChromeOptionShareCallback; import org.chromium.chrome.browser.share.share_sheet.ChromeOptionShareCallback;
import org.chromium.chrome.browser.tab.Tab; import org.chromium.chrome.browser.tab.Tab;
/** /**
...@@ -23,13 +24,17 @@ public class ScreenshotShareSheetDialogCoordinator { ...@@ -23,13 +24,17 @@ public class ScreenshotShareSheetDialogCoordinator {
* *
* @param context The context to use for user permissions. * @param context The context to use for user permissions.
* @param screenshot The screenshot to be shared. * @param screenshot The screenshot to be shared.
* @param tab The shared tab.
* @param chromeOptionShareCallback the callback to trigger on share.
* @param installCallback the callback to trigger on install.
*/ */
public ScreenshotShareSheetDialogCoordinator(Activity activity, Bitmap screenshot, Tab tab, public ScreenshotShareSheetDialogCoordinator(Activity activity, Bitmap screenshot, Tab tab,
ChromeOptionShareCallback shareCallback, Runnable installCallback) { ChromeOptionShareCallback chromeOptionShareCallback,
Callback<Runnable> installCallback) {
mFragmentManager = activity.getFragmentManager(); mFragmentManager = activity.getFragmentManager();
mScreenshot = screenshot; mScreenshot = screenshot;
mDialog = new ScreenshotShareSheetDialog(); mDialog = new ScreenshotShareSheetDialog();
mDialog.init(mScreenshot, this::dismiss, tab, shareCallback, installCallback); mDialog.init(mScreenshot, tab, chromeOptionShareCallback, installCallback);
} }
/** /**
...@@ -38,11 +43,4 @@ public class ScreenshotShareSheetDialogCoordinator { ...@@ -38,11 +43,4 @@ public class ScreenshotShareSheetDialogCoordinator {
protected void showShareSheet() { protected void showShareSheet() {
mDialog.show(mFragmentManager, null); mDialog.show(mFragmentManager, null);
} }
/**
* Dismiss the main dialog.
*/
public void dismiss() {
mDialog.dismiss();
}
} }
...@@ -26,8 +26,8 @@ class ScreenshotShareSheetMediator { ...@@ -26,8 +26,8 @@ class ScreenshotShareSheetMediator {
private final PropertyModel mModel; private final PropertyModel mModel;
private final Context mContext; private final Context mContext;
private final Runnable mSaveRunnable; private final Runnable mSaveRunnable;
private final Runnable mDeleteRunnable; private final Runnable mCloseDialogRunnable;
private final Runnable mInstallRunnable; private final Callback<Runnable> mInstallCallback;
private final ChromeOptionShareCallback mChromeOptionShareCallback; private final ChromeOptionShareCallback mChromeOptionShareCallback;
private final Tab mTab; private final Tab mTab;
...@@ -36,22 +36,24 @@ class ScreenshotShareSheetMediator { ...@@ -36,22 +36,24 @@ class ScreenshotShareSheetMediator {
* The ScreenshotShareSheetMediator constructor. * The ScreenshotShareSheetMediator constructor.
* @param context The context to use. * @param context The context to use.
* @param propertyModel The property model to use to communicate with views. * @param propertyModel The property model to use to communicate with views.
* @param deleteRunnable The action to take when cancel or delete is called. * @param closeDialogRunnable The action to take to close the dialog.
* @param saveRunnable The action to take when save is called. * @param saveRunnable The action to take when save is called.
* @param tab The tab that originated this screenshot. * @param tab The tab that originated this screenshot.
* @param chromeOptionShareCallback The callback to share a screenshot via the share sheet. * @param chromeOptionShareCallback The callback to share a screenshot via the share sheet.
* @param installRunnable The action to take when install is called. * @param installCallback The action to take when install is called, will call runnable on
* success.
*/ */
ScreenshotShareSheetMediator(Context context, PropertyModel propertyModel, ScreenshotShareSheetMediator(Context context, PropertyModel propertyModel,
Runnable deleteRunnable, Runnable saveRunnable, Tab tab, Runnable closeDialogRunnable, Runnable saveRunnable, Tab tab,
ChromeOptionShareCallback chromeOptionShareCallback, Runnable installRunnable) { ChromeOptionShareCallback chromeOptionShareCallback,
mDeleteRunnable = deleteRunnable; Callback<Runnable> installCallback) {
mCloseDialogRunnable = closeDialogRunnable;
mSaveRunnable = saveRunnable; mSaveRunnable = saveRunnable;
mContext = context; mContext = context;
mModel = propertyModel; mModel = propertyModel;
mTab = tab; mTab = tab;
mChromeOptionShareCallback = chromeOptionShareCallback; mChromeOptionShareCallback = chromeOptionShareCallback;
mInstallRunnable = installRunnable; mInstallCallback = installCallback;
mModel.set(ScreenshotShareSheetViewProperties.NO_ARG_OPERATION_LISTENER, mModel.set(ScreenshotShareSheetViewProperties.NO_ARG_OPERATION_LISTENER,
operation -> { performNoArgOperation(operation); }); operation -> { performNoArgOperation(operation); });
} }
...@@ -67,11 +69,11 @@ class ScreenshotShareSheetMediator { ...@@ -67,11 +69,11 @@ class ScreenshotShareSheetMediator {
share(); share();
} else if (NoArgOperation.SAVE == operation) { } else if (NoArgOperation.SAVE == operation) {
mSaveRunnable.run(); mSaveRunnable.run();
mDeleteRunnable.run(); mCloseDialogRunnable.run();
} else if (NoArgOperation.DELETE == operation) { } else if (NoArgOperation.DELETE == operation) {
mDeleteRunnable.run(); mCloseDialogRunnable.run();
} else if (NoArgOperation.INSTALL == operation) { } else if (NoArgOperation.INSTALL == operation) {
mInstallRunnable.run(); mInstallCallback.onResult(mCloseDialogRunnable);
} }
} }
...@@ -102,7 +104,7 @@ class ScreenshotShareSheetMediator { ...@@ -102,7 +104,7 @@ class ScreenshotShareSheetMediator {
}; };
generateTemporaryUriFromBitmap(mContext, title, bitmap, callback); generateTemporaryUriFromBitmap(mContext, title, bitmap, callback);
mDeleteRunnable.run(); mCloseDialogRunnable.run();
} }
protected void generateTemporaryUriFromBitmap( protected void generateTemporaryUriFromBitmap(
......
...@@ -53,7 +53,7 @@ public class ScreenshotShareSheetMediatorUnitTest { ...@@ -53,7 +53,7 @@ public class ScreenshotShareSheetMediatorUnitTest {
Runnable mSaveRunnable; Runnable mSaveRunnable;
@Mock @Mock
Runnable mInstallRunnable; Callback<Runnable> mInstallRunnable;
@Mock @Mock
Activity mContext; Activity mContext;
...@@ -71,9 +71,10 @@ public class ScreenshotShareSheetMediatorUnitTest { ...@@ -71,9 +71,10 @@ public class ScreenshotShareSheetMediatorUnitTest {
MockScreenshotShareSheetMediator(Context context, PropertyModel propertyModel, MockScreenshotShareSheetMediator(Context context, PropertyModel propertyModel,
Runnable deleteRunnable, Runnable saveRunnable, Tab tab, Runnable deleteRunnable, Runnable saveRunnable, Tab tab,
ChromeOptionShareCallback chromeOptionShareCallback, Runnable installRunnable) { ChromeOptionShareCallback chromeOptionShareCallback,
Callback<Runnable> installCallback) {
super(context, propertyModel, deleteRunnable, saveRunnable, tab, super(context, propertyModel, deleteRunnable, saveRunnable, tab,
chromeOptionShareCallback, installRunnable); chromeOptionShareCallback, installCallback);
} }
@Override @Override
protected void generateTemporaryUriFromBitmap( protected void generateTemporaryUriFromBitmap(
...@@ -150,7 +151,7 @@ public class ScreenshotShareSheetMediatorUnitTest { ...@@ -150,7 +151,7 @@ public class ScreenshotShareSheetMediatorUnitTest {
mModel.get(ScreenshotShareSheetViewProperties.NO_ARG_OPERATION_LISTENER); mModel.get(ScreenshotShareSheetViewProperties.NO_ARG_OPERATION_LISTENER);
callback.onResult(ScreenshotShareSheetViewProperties.NoArgOperation.INSTALL); callback.onResult(ScreenshotShareSheetViewProperties.NoArgOperation.INSTALL);
verify(mInstallRunnable).run(); verify(mInstallRunnable).onResult(any());
} }
@After @After
......
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