Commit 64cf7d9d authored by Xing Liu's avatar Xing Liu Committed by Commit Bot

Download location android: Check SD card before showing location dialog.

This CL checks if the user has SD card. Don't show download location
dialog if user don't have SD card.

Bug: 896873
Change-Id: I157b8958669c0692247f7cf3798f32867675b11c
Reviewed-on: https://chromium-review.googlesource.com/c/1290509Reviewed-by: default avatarDavid Trainor <dtrainor@chromium.org>
Commit-Queue: Xing Liu <xingliu@chromium.org>
Cr-Commit-Position: refs/heads/master@{#601365}
parent 66809e49
...@@ -4,6 +4,9 @@ ...@@ -4,6 +4,9 @@
package org.chromium.chrome.browser.download; package org.chromium.chrome.browser.download;
import android.content.Context;
import android.text.TextUtils;
import org.chromium.base.annotations.CalledByNative; import org.chromium.base.annotations.CalledByNative;
import org.chromium.base.metrics.RecordHistogram; import org.chromium.base.metrics.RecordHistogram;
import org.chromium.chrome.browser.ChromeActivity; import org.chromium.chrome.browser.ChromeActivity;
...@@ -14,6 +17,7 @@ import org.chromium.chrome.browser.preferences.PrefServiceBridge; ...@@ -14,6 +17,7 @@ import org.chromium.chrome.browser.preferences.PrefServiceBridge;
import org.chromium.ui.base.WindowAndroid; import org.chromium.ui.base.WindowAndroid;
import java.io.File; import java.io.File;
import java.util.ArrayList;
/** /**
* Helper class to handle communication between download location dialog and native. * Helper class to handle communication between download location dialog and native.
...@@ -22,6 +26,10 @@ public class DownloadLocationDialogBridge implements ModalDialogView.Controller ...@@ -22,6 +26,10 @@ public class DownloadLocationDialogBridge implements ModalDialogView.Controller
private long mNativeDownloadLocationDialogBridge; private long mNativeDownloadLocationDialogBridge;
private DownloadLocationDialog mLocationDialog; private DownloadLocationDialog mLocationDialog;
private ModalDialogManager mModalDialogManager; private ModalDialogManager mModalDialogManager;
private long mTotalBytes;
private @DownloadLocationDialogType int mDialogType;
private String mSuggestedPath;
private Context mContext;
private DownloadLocationDialogBridge(long nativeDownloadLocationDialogBridge) { private DownloadLocationDialogBridge(long nativeDownloadLocationDialogBridge) {
mNativeDownloadLocationDialogBridge = nativeDownloadLocationDialogBridge; mNativeDownloadLocationDialogBridge = nativeDownloadLocationDialogBridge;
...@@ -52,12 +60,13 @@ public class DownloadLocationDialogBridge implements ModalDialogView.Controller ...@@ -52,12 +60,13 @@ public class DownloadLocationDialogBridge implements ModalDialogView.Controller
} }
mModalDialogManager = activity.getModalDialogManager(); mModalDialogManager = activity.getModalDialogManager();
mContext = activity;
mTotalBytes = totalBytes;
mDialogType = dialogType;
mSuggestedPath = suggestedPath;
if (mLocationDialog != null) return; DownloadDirectoryProvider.getInstance().getAllDirectoriesOptions(
mLocationDialog = DownloadLocationDialog.create( (ArrayList<DirectoryOption> dirs) -> { onDirectoryOptionsRetrieved(dirs); });
this, activity, totalBytes, dialogType, new File(suggestedPath));
mModalDialogManager.showDialog(mLocationDialog, ModalDialogManager.ModalDialogType.APP);
} }
@Override @Override
...@@ -91,6 +100,34 @@ public class DownloadLocationDialogBridge implements ModalDialogView.Controller ...@@ -91,6 +100,34 @@ public class DownloadLocationDialogBridge implements ModalDialogView.Controller
mLocationDialog = null; mLocationDialog = null;
} }
/**
* Called after retrieved the download directory options.
* @param dirs An list of available download directories.
*/
private void onDirectoryOptionsRetrieved(ArrayList<DirectoryOption> dirs) {
// If there is only one directory available, don't show the default dialog, and set the
// download directory to default. Dialog will still show for other types of dialogs, like
// name conflict or disk error.
if (dirs.size() == 1 && mDialogType == DownloadLocationDialogType.DEFAULT) {
final DirectoryOption dir = dirs.get(0);
if (dir.type == DirectoryOption.DownloadLocationDirectoryType.DEFAULT) {
assert(!TextUtils.isEmpty(dir.location));
PrefServiceBridge.getInstance().setDownloadAndSaveFileDefaultDirectory(
dir.location);
nativeOnComplete(mNativeDownloadLocationDialogBridge, mSuggestedPath);
}
return;
}
// Already showing the dialog.
if (mLocationDialog != null) return;
// Actually show the dialog.
mLocationDialog = DownloadLocationDialog.create(
this, mContext, mTotalBytes, mDialogType, new File(mSuggestedPath));
mModalDialogManager.showDialog(mLocationDialog, ModalDialogManager.ModalDialogType.APP);
}
/** /**
* Pass along information from location dialog to native. * Pass along information from location dialog to native.
* *
...@@ -119,7 +156,8 @@ public class DownloadLocationDialogBridge implements ModalDialogView.Controller ...@@ -119,7 +156,8 @@ public class DownloadLocationDialogBridge implements ModalDialogView.Controller
nativeOnComplete(mNativeDownloadLocationDialogBridge, file.getAbsolutePath()); nativeOnComplete(mNativeDownloadLocationDialogBridge, file.getAbsolutePath());
} }
// Update preference to show prompt based on whether checkbox is checked. // Update preference to show prompt based on whether checkbox is checked only when the user
// click the positive button.
if (dontShowAgain) { if (dontShowAgain) {
PrefServiceBridge.getInstance().setPromptForDownloadAndroid( PrefServiceBridge.getInstance().setPromptForDownloadAndroid(
DownloadPromptStatus.DONT_SHOW); DownloadPromptStatus.DONT_SHOW);
......
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