From d219519e9f9d831d607fcd0cec836c957939313d Mon Sep 17 00:00:00 2001 From: "shashishekhar@chromium.org" Date: Fri, 22 Nov 2013 01:03:06 +0000 Subject: [Android] Expose download progress updates to Java. Android currently does not show any progress indication for Downloads that use the Chrome network stack. Expose this information to the Java DownloadNotificationService interface. Download progress notification needs percent complete and time remaining to display the progress. BUG=314164 Review URL: https://codereview.chromium.org/78603004 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@236653 0039d316-1c4b-4281-b951-d872f2087c98 --- .../android/download_controller_android_impl.cc | 54 ++++++++++++++++------ 1 file changed, 40 insertions(+), 14 deletions(-) (limited to 'content/browser') diff --git a/content/browser/android/download_controller_android_impl.cc b/content/browser/android/download_controller_android_impl.cc index 7d27e64..f3a274a 100644 --- a/content/browser/android/download_controller_android_impl.cc +++ b/content/browser/android/download_controller_android_impl.cc @@ -9,6 +9,7 @@ #include "base/bind.h" #include "base/logging.h" #include "base/memory/scoped_ptr.h" +#include "base/time/time.h" #include "content/browser/android/content_view_core_impl.h" #include "content/browser/download/download_item_impl.h" #include "content/browser/download/download_manager_impl.h" @@ -254,18 +255,9 @@ void DownloadControllerAndroidImpl::OnDownloadStarted( void DownloadControllerAndroidImpl::OnDownloadUpdated(DownloadItem* item) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); - if (item->IsDangerous() && - (item->GetState() != DownloadItem::CANCELLED)) + if (item->IsDangerous() && (item->GetState() != DownloadItem::CANCELLED)) OnDangerousDownload(item); - if (item->GetState() != DownloadItem::COMPLETE) - return; - - // Multiple OnDownloadUpdated() notifications may be issued while the download - // is in the COMPLETE state. Only handle one. - item->RemoveObserver(this); - - // Call onDownloadCompleted JNIEnv* env = base::android::AttachCurrentThread(); ScopedJavaLocalRef jurl = ConvertUTF8ToJavaString(env, item->GetURL().spec()); @@ -276,10 +268,44 @@ void DownloadControllerAndroidImpl::OnDownloadUpdated(DownloadItem* item) { ScopedJavaLocalRef jfilename = ConvertUTF8ToJavaString( env, item->GetTargetFilePath().BaseName().value()); - Java_DownloadController_onDownloadCompleted( - env, GetJavaObject()->Controller(env).obj(), - base::android::GetApplicationContext(), jurl.obj(), jmime_type.obj(), - jfilename.obj(), jpath.obj(), item->GetReceivedBytes(), true); + switch (item->GetState()) { + case DownloadItem::IN_PROGRESS: { + base::TimeDelta time_delta; + item->TimeRemaining(&time_delta); + Java_DownloadController_onDownloadUpdated( + env, GetJavaObject()->Controller(env).obj(), + base::android::GetApplicationContext(), jurl.obj(), jmime_type.obj(), + jfilename.obj(), jpath.obj(), item->GetReceivedBytes(), true, + item->GetId(), item->PercentComplete(), time_delta.InMilliseconds()); + break; + } + case DownloadItem::COMPLETE: + // Multiple OnDownloadUpdated() notifications may be issued while the + // download is in the COMPLETE state. Only handle one. + item->RemoveObserver(this); + + // Call onDownloadCompleted + Java_DownloadController_onDownloadCompleted( + env, GetJavaObject()->Controller(env).obj(), + base::android::GetApplicationContext(), jurl.obj(), jmime_type.obj(), + jfilename.obj(), jpath.obj(), item->GetReceivedBytes(), true, + item->GetId()); + break; + case DownloadItem::CANCELLED: + // TODO(shashishekhar): An interrupted download can be resumed. Android + // currently does not support resumable downloads. Add handling for + // interrupted case based on item->CanResume(). + case DownloadItem::INTERRUPTED: + // Call onDownloadCompleted with success = false. + Java_DownloadController_onDownloadCompleted( + env, GetJavaObject()->Controller(env).obj(), + base::android::GetApplicationContext(), jurl.obj(), jmime_type.obj(), + jfilename.obj(), jpath.obj(), item->GetReceivedBytes(), false, + item->GetId()); + break; + case DownloadItem::MAX_DOWNLOAD_STATE: + NOTREACHED(); + } } void DownloadControllerAndroidImpl::OnDangerousDownload(DownloadItem* item) { -- cgit v1.1