diff options
author | shashishekhar@chromium.org <shashishekhar@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-11-22 01:03:06 +0000 |
---|---|---|
committer | shashishekhar@chromium.org <shashishekhar@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-11-22 01:03:06 +0000 |
commit | d219519e9f9d831d607fcd0cec836c957939313d (patch) | |
tree | de2fd3d0440a1637bb5513643c30ad8182963982 /content/browser/android | |
parent | 13b0f88e6b3309e69aa38ce5a2c9be3151b0b921 (diff) | |
download | chromium_src-d219519e9f9d831d607fcd0cec836c957939313d.zip chromium_src-d219519e9f9d831d607fcd0cec836c957939313d.tar.gz chromium_src-d219519e9f9d831d607fcd0cec836c957939313d.tar.bz2 |
[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
Diffstat (limited to 'content/browser/android')
-rw-r--r-- | content/browser/android/download_controller_android_impl.cc | 54 |
1 files changed, 40 insertions, 14 deletions
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<jstring> jurl = ConvertUTF8ToJavaString(env, item->GetURL().spec()); @@ -276,10 +268,44 @@ void DownloadControllerAndroidImpl::OnDownloadUpdated(DownloadItem* item) { ScopedJavaLocalRef<jstring> 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) { |