Commit a3db4d82 authored by Xing Liu's avatar Xing Liu Committed by Commit Bot

Download later: Plumb DownloadSchedule through JNI bridge.

This CL passes download later data through DownloadDialogBridge.

Bug: 1078454
Change-Id: Idd2cbbded85ce25e630bf37ad523254cfec9265c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2233361Reviewed-by: default avatarMin Qin <qinmin@chromium.org>
Commit-Queue: Xing Liu <xingliu@chromium.org>
Cr-Commit-Position: refs/heads/master@{#775788}
parent 5d52f967
...@@ -82,12 +82,23 @@ void DownloadDialogBridge::ShowDialog(gfx::NativeWindow native_window, ...@@ -82,12 +82,23 @@ void DownloadDialogBridge::ShowDialog(gfx::NativeWindow native_window,
void DownloadDialogBridge::OnComplete( void DownloadDialogBridge::OnComplete(
JNIEnv* env, JNIEnv* env,
const base::android::JavaParamRef<jobject>& obj, const base::android::JavaParamRef<jobject>& obj,
const base::android::JavaParamRef<jstring>& returned_path) { const base::android::JavaParamRef<jstring>& returned_path,
jboolean on_wifi,
jlong start_time) {
DownloadDialogResult dialog_result; DownloadDialogResult dialog_result;
dialog_result.location_result = DownloadLocationDialogResult::USER_CONFIRMED; dialog_result.location_result = DownloadLocationDialogResult::USER_CONFIRMED;
dialog_result.file_path = base::FilePath( dialog_result.file_path = base::FilePath(
base::android::ConvertJavaStringToUTF8(env, returned_path)); base::android::ConvertJavaStringToUTF8(env, returned_path));
if (on_wifi) {
dialog_result.download_schedule =
download::DownloadSchedule(true /*on_wifi*/);
}
if (start_time > 0) {
dialog_result.download_schedule =
download::DownloadSchedule(base::Time::FromJavaTime(start_time));
}
CompleteSelection(std::move(dialog_result)); CompleteSelection(std::move(dialog_result));
is_dialog_showing_ = false; is_dialog_showing_ = false;
} }
......
...@@ -31,6 +31,7 @@ struct DownloadDialogResult { ...@@ -31,6 +31,7 @@ struct DownloadDialogResult {
// Used to show a dialog for the user to select download details, such as file // Used to show a dialog for the user to select download details, such as file
// location, file name. and download start time. // location, file name. and download start time.
// TODO(xingliu): Move logic out of the bridge, and write a test.
class DownloadDialogBridge { class DownloadDialogBridge {
public: public:
using DialogCallback = base::OnceCallback<void(DownloadDialogResult)>; using DialogCallback = base::OnceCallback<void(DownloadDialogResult)>;
...@@ -50,7 +51,9 @@ class DownloadDialogBridge { ...@@ -50,7 +51,9 @@ class DownloadDialogBridge {
void OnComplete(JNIEnv* env, void OnComplete(JNIEnv* env,
const base::android::JavaParamRef<jobject>& obj, const base::android::JavaParamRef<jobject>& obj,
const base::android::JavaParamRef<jstring>& returned_path); const base::android::JavaParamRef<jstring>& returned_path,
jboolean on_wifi,
jlong start_time);
void OnCanceled(JNIEnv* env, const base::android::JavaParamRef<jobject>& obj); void OnCanceled(JNIEnv* env, const base::android::JavaParamRef<jobject>& obj);
......
...@@ -29,6 +29,7 @@ import java.util.ArrayList; ...@@ -29,6 +29,7 @@ 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.
*/ */
public class DownloadDialogBridge implements ModalDialogProperties.Controller { public class DownloadDialogBridge implements ModalDialogProperties.Controller {
private static final long INVALID_START_TIME = -1;
private long mNativeDownloadDialogBridge; private long mNativeDownloadDialogBridge;
private PropertyModel mDialogModel; private PropertyModel mDialogModel;
private DownloadLocationCustomView mCustomView; private DownloadLocationCustomView mCustomView;
...@@ -119,8 +120,9 @@ public class DownloadDialogBridge implements ModalDialogProperties.Controller { ...@@ -119,8 +120,9 @@ public class DownloadDialogBridge implements ModalDialogProperties.Controller {
if (dir.type == DirectoryOption.DownloadLocationDirectoryType.DEFAULT) { if (dir.type == DirectoryOption.DownloadLocationDirectoryType.DEFAULT) {
assert (!TextUtils.isEmpty(dir.location)); assert (!TextUtils.isEmpty(dir.location));
setDownloadAndSaveFileDefaultDirectory(dir.location); setDownloadAndSaveFileDefaultDirectory(dir.location);
DownloadDialogBridgeJni.get().onComplete( DownloadDialogBridgeJni.get().onComplete(mNativeDownloadDialogBridge,
mNativeDownloadDialogBridge, DownloadDialogBridge.this, mSuggestedPath); DownloadDialogBridge.this, mSuggestedPath, false /*onWifi*/,
INVALID_START_TIME);
} }
return; return;
} }
...@@ -202,8 +204,9 @@ public class DownloadDialogBridge implements ModalDialogProperties.Controller { ...@@ -202,8 +204,9 @@ public class DownloadDialogBridge implements ModalDialogProperties.Controller {
DirectoryOption.DownloadLocationDirectoryType.NUM_ENTRIES); DirectoryOption.DownloadLocationDirectoryType.NUM_ENTRIES);
File file = new File(directoryOption.location, fileName); File file = new File(directoryOption.location, fileName);
DownloadDialogBridgeJni.get().onComplete( DownloadDialogBridgeJni.get().onComplete(mNativeDownloadDialogBridge,
mNativeDownloadDialogBridge, DownloadDialogBridge.this, file.getAbsolutePath()); DownloadDialogBridge.this, file.getAbsolutePath(), false /*onWifi*/,
INVALID_START_TIME);
} }
// Update preference to show prompt based on whether checkbox is checked only when the user // Update preference to show prompt based on whether checkbox is checked only when the user
...@@ -253,8 +256,8 @@ public class DownloadDialogBridge implements ModalDialogProperties.Controller { ...@@ -253,8 +256,8 @@ public class DownloadDialogBridge implements ModalDialogProperties.Controller {
@NativeMethods @NativeMethods
interface Natives { interface Natives {
void onComplete( void onComplete(long nativeDownloadDialogBridge, DownloadDialogBridge caller,
long nativeDownloadDialogBridge, DownloadDialogBridge caller, String returnedPath); String returnedPath, boolean onWifi, long startTime);
void onCanceled(long nativeDownloadDialogBridge, DownloadDialogBridge caller); void onCanceled(long nativeDownloadDialogBridge, DownloadDialogBridge caller);
String getDownloadDefaultDirectory(); String getDownloadDefaultDirectory();
void setDownloadAndSaveFileDefaultDirectory(String directory); void setDownloadAndSaveFileDefaultDirectory(String directory);
......
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