Commit 145c6422 authored by dfalcantara's avatar dfalcantara Committed by Commit bot

[Download Home] Expose Java side to DownloadItem states

* Expose DownloadItem::DownloadState to Java as an enum.

* Pass all DownloadItem updates to Java so that the DownloadHistoryAdapter
  can process them.  We're still ignoring everything but the COMPLETE state.

BUG=616324

Review-Url: https://codereview.chromium.org/2320693003
Cr-Commit-Position: refs/heads/master@{#417439}
parent 13f29c23
...@@ -1554,14 +1554,14 @@ public class DownloadManagerService extends BroadcastReceiver implements ...@@ -1554,14 +1554,14 @@ public class DownloadManagerService extends BroadcastReceiver implements
} }
@CalledByNative @CalledByNative
private void onDownloadItemUpdated(String guid, String displayName, String filepath, String url, private void onDownloadItemUpdated(int state, String guid, String displayName, String filepath,
String mimeType, long startTimestamp, long totalBytes, boolean isOffTheRecord, String url, String mimeType, long startTimestamp, long totalBytes,
boolean hasBeenExternallyRemoved) { boolean isOffTheRecord, boolean hasBeenExternallyRemoved) {
DownloadItem item = createDownloadItem( DownloadItem item = createDownloadItem(
guid, displayName, filepath, url, mimeType, startTimestamp, totalBytes, guid, displayName, filepath, url, mimeType, startTimestamp, totalBytes,
hasBeenExternallyRemoved); hasBeenExternallyRemoved);
for (DownloadHistoryAdapter adapter : mHistoryAdapters) { for (DownloadHistoryAdapter adapter : mHistoryAdapters) {
adapter.onDownloadItemUpdated(item, isOffTheRecord); adapter.onDownloadItemUpdated(item, isOffTheRecord, state);
} }
} }
......
...@@ -24,6 +24,7 @@ import org.chromium.chrome.browser.offlinepages.downloads.OfflinePageDownloadBri ...@@ -24,6 +24,7 @@ import org.chromium.chrome.browser.offlinepages.downloads.OfflinePageDownloadBri
import org.chromium.chrome.browser.offlinepages.downloads.OfflinePageDownloadItem; import org.chromium.chrome.browser.offlinepages.downloads.OfflinePageDownloadItem;
import org.chromium.chrome.browser.widget.DateDividedAdapter; import org.chromium.chrome.browser.widget.DateDividedAdapter;
import org.chromium.chrome.browser.widget.selection.SelectionDelegate; import org.chromium.chrome.browser.widget.selection.SelectionDelegate;
import org.chromium.content_public.browser.DownloadState;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
...@@ -174,9 +175,12 @@ public class DownloadHistoryAdapter extends DateDividedAdapter implements Downlo ...@@ -174,9 +175,12 @@ public class DownloadHistoryAdapter extends DateDividedAdapter implements Downlo
/** /**
* Updates the list when new information about a download comes in. * Updates the list when new information about a download comes in.
*/ */
public void onDownloadItemUpdated(DownloadItem item, boolean isOffTheRecord) { public void onDownloadItemUpdated(DownloadItem item, boolean isOffTheRecord, int state) {
if (isOffTheRecord && !mShowOffTheRecord) return; if (isOffTheRecord && !mShowOffTheRecord) return;
// The adapter currently only cares about completion events.
if (state != DownloadState.COMPLETE) return;
List<DownloadItemWrapper> list = getDownloadItemList(isOffTheRecord); List<DownloadItemWrapper> list = getDownloadItemList(isOffTheRecord);
int index = findItemIndex(list, item.getId()); int index = findItemIndex(list, item.getId());
......
...@@ -31,6 +31,7 @@ import org.chromium.chrome.test.util.ChromeRestriction; ...@@ -31,6 +31,7 @@ import org.chromium.chrome.test.util.ChromeRestriction;
import org.chromium.content.browser.test.util.CallbackHelper; import org.chromium.content.browser.test.util.CallbackHelper;
import org.chromium.content.browser.test.util.Criteria; import org.chromium.content.browser.test.util.Criteria;
import org.chromium.content.browser.test.util.CriteriaHelper; import org.chromium.content.browser.test.util.CriteriaHelper;
import org.chromium.content_public.browser.DownloadState;
import java.util.List; import java.util.List;
...@@ -140,7 +141,7 @@ public class DownloadActivityTest extends BaseActivityInstrumentationTestCase<Do ...@@ -140,7 +141,7 @@ public class DownloadActivityTest extends BaseActivityInstrumentationTestCase<Do
ThreadUtils.runOnUiThread(new Runnable() { ThreadUtils.runOnUiThread(new Runnable() {
@Override @Override
public void run() { public void run() {
mAdapter.onDownloadItemUpdated(updateItem, false); mAdapter.onDownloadItemUpdated(updateItem, false, DownloadState.COMPLETE);
} }
}); });
mAdapterObserver.onChangedCallback.waitForCallback(callCount); mAdapterObserver.onChangedCallback.waitForCallback(callCount);
...@@ -153,7 +154,7 @@ public class DownloadActivityTest extends BaseActivityInstrumentationTestCase<Do ...@@ -153,7 +154,7 @@ public class DownloadActivityTest extends BaseActivityInstrumentationTestCase<Do
ThreadUtils.runOnUiThread(new Runnable() { ThreadUtils.runOnUiThread(new Runnable() {
@Override @Override
public void run() { public void run() {
mAdapter.onDownloadItemUpdated(deletedItem, false); mAdapter.onDownloadItemUpdated(deletedItem, false, DownloadState.COMPLETE);
} }
}); });
mAdapterObserver.onChangedCallback.waitForCallback(callCount); mAdapterObserver.onChangedCallback.waitForCallback(callCount);
......
...@@ -17,6 +17,7 @@ import org.chromium.chrome.browser.download.ui.StubbedProvider.StubbedOfflinePag ...@@ -17,6 +17,7 @@ import org.chromium.chrome.browser.download.ui.StubbedProvider.StubbedOfflinePag
import org.chromium.chrome.browser.offlinepages.downloads.OfflinePageDownloadItem; import org.chromium.chrome.browser.offlinepages.downloads.OfflinePageDownloadItem;
import org.chromium.content.browser.test.NativeLibraryTestBase; import org.chromium.content.browser.test.NativeLibraryTestBase;
import org.chromium.content.browser.test.util.CallbackHelper; import org.chromium.content.browser.test.util.CallbackHelper;
import org.chromium.content_public.browser.DownloadState;
/** /**
* Tests a DownloadHistoryAdapter that is isolated from the real bridges. * Tests a DownloadHistoryAdapter that is isolated from the real bridges.
...@@ -158,7 +159,7 @@ public class DownloadHistoryAdapterTest extends NativeLibraryTestBase { ...@@ -158,7 +159,7 @@ public class DownloadHistoryAdapterTest extends NativeLibraryTestBase {
// Add the first item. // Add the first item.
assertEquals(1, mObserver.onChangedCallback.getCallCount()); assertEquals(1, mObserver.onChangedCallback.getCallCount());
DownloadItem item0 = StubbedProvider.createDownloadItem(0, "19840116 12:00"); DownloadItem item0 = StubbedProvider.createDownloadItem(0, "19840116 12:00");
mAdapter.onDownloadItemUpdated(item0, false); mAdapter.onDownloadItemUpdated(item0, false, DownloadState.COMPLETE);
mObserver.onChangedCallback.waitForCallback(1); mObserver.onChangedCallback.waitForCallback(1);
checkAdapterContents(null, item0); checkAdapterContents(null, item0);
assertEquals(1, mAdapter.getTotalDownloadSize()); assertEquals(1, mAdapter.getTotalDownloadSize());
...@@ -166,7 +167,7 @@ public class DownloadHistoryAdapterTest extends NativeLibraryTestBase { ...@@ -166,7 +167,7 @@ public class DownloadHistoryAdapterTest extends NativeLibraryTestBase {
// Add a second item with a different date. // Add a second item with a different date.
assertEquals(2, mObserver.onChangedCallback.getCallCount()); assertEquals(2, mObserver.onChangedCallback.getCallCount());
DownloadItem item1 = StubbedProvider.createDownloadItem(1, "19840117 12:00"); DownloadItem item1 = StubbedProvider.createDownloadItem(1, "19840117 12:00");
mAdapter.onDownloadItemUpdated(item1, false); mAdapter.onDownloadItemUpdated(item1, false, DownloadState.COMPLETE);
mObserver.onChangedCallback.waitForCallback(2); mObserver.onChangedCallback.waitForCallback(2);
checkAdapterContents(null, item1, null, item0); checkAdapterContents(null, item1, null, item0);
assertEquals(11, mAdapter.getTotalDownloadSize()); assertEquals(11, mAdapter.getTotalDownloadSize());
...@@ -174,7 +175,7 @@ public class DownloadHistoryAdapterTest extends NativeLibraryTestBase { ...@@ -174,7 +175,7 @@ public class DownloadHistoryAdapterTest extends NativeLibraryTestBase {
// Add a third item with the same date as the second item. // Add a third item with the same date as the second item.
assertEquals(3, mObserver.onChangedCallback.getCallCount()); assertEquals(3, mObserver.onChangedCallback.getCallCount());
DownloadItem item2 = StubbedProvider.createDownloadItem(2, "19840117 18:00"); DownloadItem item2 = StubbedProvider.createDownloadItem(2, "19840117 18:00");
mAdapter.onDownloadItemUpdated(item2, false); mAdapter.onDownloadItemUpdated(item2, false, DownloadState.COMPLETE);
mObserver.onChangedCallback.waitForCallback(3); mObserver.onChangedCallback.waitForCallback(3);
checkAdapterContents(null, item2, item1, null, item0); checkAdapterContents(null, item2, item1, null, item0);
assertEquals(111, mAdapter.getTotalDownloadSize()); assertEquals(111, mAdapter.getTotalDownloadSize());
...@@ -182,7 +183,7 @@ public class DownloadHistoryAdapterTest extends NativeLibraryTestBase { ...@@ -182,7 +183,7 @@ public class DownloadHistoryAdapterTest extends NativeLibraryTestBase {
// An item with the same download ID as the second item should just update the old one. // An item with the same download ID as the second item should just update the old one.
assertEquals(4, mObserver.onChangedCallback.getCallCount()); assertEquals(4, mObserver.onChangedCallback.getCallCount());
DownloadItem item3 = StubbedProvider.createDownloadItem(2, "19840117 18:00"); DownloadItem item3 = StubbedProvider.createDownloadItem(2, "19840117 18:00");
mAdapter.onDownloadItemUpdated(item3, false); mAdapter.onDownloadItemUpdated(item3, false, DownloadState.COMPLETE);
mObserver.onChangedCallback.waitForCallback(4); mObserver.onChangedCallback.waitForCallback(4);
checkAdapterContents(null, item3, item1, null, item0); checkAdapterContents(null, item3, item1, null, item0);
assertEquals(111, mAdapter.getTotalDownloadSize()); assertEquals(111, mAdapter.getTotalDownloadSize());
......
...@@ -241,14 +241,11 @@ void DownloadManagerService::OnDownloadUpdated( ...@@ -241,14 +241,11 @@ void DownloadManagerService::OnDownloadUpdated(
if (java_ref_.is_null()) if (java_ref_.is_null())
return; return;
// Ignore anything that isn't a completed download notification.
if (item->GetState() != content::DownloadItem::DownloadState::COMPLETE)
return;
JNIEnv* env = base::android::AttachCurrentThread(); JNIEnv* env = base::android::AttachCurrentThread();
Java_DownloadManagerService_onDownloadItemUpdated( Java_DownloadManagerService_onDownloadItemUpdated(
env, env,
java_ref_.obj(), java_ref_.obj(),
item->GetState(),
ConvertUTF8ToJavaString(env, item->GetGuid()).obj(), ConvertUTF8ToJavaString(env, item->GetGuid()).obj(),
ConvertUTF8ToJavaString( ConvertUTF8ToJavaString(
env, item->GetFileNameToReportUser().value()).obj(), env, item->GetFileNameToReportUser().value()).obj(),
......
...@@ -264,6 +264,7 @@ java_cpp_enum("content_public_android_java_enums_srcjar") { ...@@ -264,6 +264,7 @@ java_cpp_enum("content_public_android_java_enums_srcjar") {
"//content/browser/android/gesture_event_type.h", "//content/browser/android/gesture_event_type.h",
"//content/browser/device_sensors/device_sensors_consts.h", "//content/browser/device_sensors/device_sensors_consts.h",
"//content/browser/device_sensors/sensor_manager_android.h", "//content/browser/device_sensors/sensor_manager_android.h",
"//content/public/browser/download_item.h",
"//content/public/browser/invalidate_type.h", "//content/public/browser/invalidate_type.h",
"//content/public/browser/navigation_controller.h", "//content/public/browser/navigation_controller.h",
"//content/public/browser/readback_types.h", "//content/public/browser/readback_types.h",
......
...@@ -52,6 +52,8 @@ class WebContents; ...@@ -52,6 +52,8 @@ class WebContents;
// This is intended to be used only on the UI thread. // This is intended to be used only on the UI thread.
class CONTENT_EXPORT DownloadItem : public base::SupportsUserData { class CONTENT_EXPORT DownloadItem : public base::SupportsUserData {
public: public:
// A Java counterpart will be generated for this enum.
// GENERATED_JAVA_ENUM_PACKAGE: org.chromium.content_public.browser
enum DownloadState { enum DownloadState {
// Download is actively progressing. // Download is actively progressing.
IN_PROGRESS = 0, IN_PROGRESS = 0,
......
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