Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(200)

Side by Side Diff: content/browser/android/download_controller_android_impl.cc

Issue 1684293002: Separate download cancel handling from download failure (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "content/browser/android/download_controller_android_impl.h" 5 #include "content/browser/android/download_controller_android_impl.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/android/context_utils.h" 9 #include "base/android/context_utils.h"
10 #include "base/android/jni_android.h" 10 #include "base/android/jni_android.h"
(...skipping 430 matching lines...) Expand 10 before | Expand all | Expand 10 after
441 ConvertUTF8ToJavaString(env, item->GetTargetFilePath().value()); 441 ConvertUTF8ToJavaString(env, item->GetTargetFilePath().value());
442 ScopedJavaLocalRef<jstring> jfilename = ConvertUTF8ToJavaString( 442 ScopedJavaLocalRef<jstring> jfilename = ConvertUTF8ToJavaString(
443 env, item->GetTargetFilePath().BaseName().value()); 443 env, item->GetTargetFilePath().BaseName().value());
444 444
445 switch (item->GetState()) { 445 switch (item->GetState()) {
446 case DownloadItem::IN_PROGRESS: { 446 case DownloadItem::IN_PROGRESS: {
447 base::TimeDelta time_delta; 447 base::TimeDelta time_delta;
448 item->TimeRemaining(&time_delta); 448 item->TimeRemaining(&time_delta);
449 Java_DownloadController_onDownloadUpdated( 449 Java_DownloadController_onDownloadUpdated(
450 env, GetJavaObject()->Controller(env).obj(), 450 env, GetJavaObject()->Controller(env).obj(),
451 base::android::GetApplicationContext(), jurl.obj(), jmime_type.obj(), 451 jurl.obj(), jmime_type.obj(),
452 jfilename.obj(), jpath.obj(), item->GetReceivedBytes(), true, 452 jfilename.obj(), jpath.obj(), item->GetReceivedBytes(), true,
453 item->GetId(), item->PercentComplete(), time_delta.InMilliseconds(), 453 item->GetId(), item->PercentComplete(), time_delta.InMilliseconds(),
454 item->HasUserGesture(), 454 item->HasUserGesture(),
455 // Get all requirements that allows a download to be resumable. 455 // Get all requirements that allows a download to be resumable.
456 !item->GetBrowserContext()->IsOffTheRecord()); 456 !item->GetBrowserContext()->IsOffTheRecord());
457 break; 457 break;
458 } 458 }
459 case DownloadItem::COMPLETE: 459 case DownloadItem::COMPLETE:
460 // Multiple OnDownloadUpdated() notifications may be issued while the 460 // Multiple OnDownloadUpdated() notifications may be issued while the
461 // download is in the COMPLETE state. Only handle one. 461 // download is in the COMPLETE state. Only handle one.
462 item->RemoveObserver(this); 462 item->RemoveObserver(this);
463 463
464 // Call onDownloadCompleted 464 // Call onDownloadCompleted
465 Java_DownloadController_onDownloadCompleted( 465 Java_DownloadController_onDownloadCompleted(
466 env, GetJavaObject()->Controller(env).obj(), 466 env, GetJavaObject()->Controller(env).obj(), jurl.obj(),
467 base::android::GetApplicationContext(), jurl.obj(), jmime_type.obj(), 467 jmime_type.obj(), jfilename.obj(), jpath.obj(),
468 jfilename.obj(), jpath.obj(), item->GetReceivedBytes(), true, 468 item->GetReceivedBytes(), true, item->GetId(),
469 item->GetId(), item->HasUserGesture()); 469 item->HasUserGesture());
470 break; 470 break;
471 case DownloadItem::CANCELLED: 471 case DownloadItem::CANCELLED:
472 Java_DownloadController_onDownloadCancelled(
473 env, GetJavaObject()->Controller(env).obj(), item->GetId());
474 break;
472 // TODO(shashishekhar): An interrupted download can be resumed. Android 475 // TODO(shashishekhar): An interrupted download can be resumed. Android
473 // currently does not support resumable downloads. Add handling for 476 // currently does not support resumable downloads. Add handling for
474 // interrupted case based on item->CanResume(). 477 // interrupted case based on item->CanResume().
475 case DownloadItem::INTERRUPTED: 478 case DownloadItem::INTERRUPTED:
476 // Call onDownloadCompleted with success = false. 479 // Call onDownloadCompleted with success = false.
477 Java_DownloadController_onDownloadCompleted( 480 Java_DownloadController_onDownloadCompleted(
478 env, GetJavaObject()->Controller(env).obj(), 481 env, GetJavaObject()->Controller(env).obj(), jurl.obj(),
479 base::android::GetApplicationContext(), jurl.obj(), jmime_type.obj(), 482 jmime_type.obj(), jfilename.obj(), jpath.obj(),
480 jfilename.obj(), jpath.obj(), item->GetReceivedBytes(), false, 483 item->GetReceivedBytes(), false, item->GetId(),
481 item->GetId(), item->HasUserGesture()); 484 item->HasUserGesture());
482 break; 485 break;
483 case DownloadItem::MAX_DOWNLOAD_STATE: 486 case DownloadItem::MAX_DOWNLOAD_STATE:
484 NOTREACHED(); 487 NOTREACHED();
485 } 488 }
486 } 489 }
487 490
488 void DownloadControllerAndroidImpl::OnDangerousDownload(DownloadItem* item) { 491 void DownloadControllerAndroidImpl::OnDangerousDownload(DownloadItem* item) {
489 JNIEnv* env = base::android::AttachCurrentThread(); 492 JNIEnv* env = base::android::AttachCurrentThread();
490 ScopedJavaLocalRef<jstring> jfilename = ConvertUTF8ToJavaString( 493 ScopedJavaLocalRef<jstring> jfilename = ConvertUTF8ToJavaString(
491 env, item->GetTargetFilePath().BaseName().value()); 494 env, item->GetTargetFilePath().BaseName().value());
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
569 } 572 }
570 573
571 const ResourceRequestInfo* info = ResourceRequestInfo::ForRequest(request); 574 const ResourceRequestInfo* info = ResourceRequestInfo::ForRequest(request);
572 if (info) 575 if (info)
573 has_user_gesture = info->HasUserGesture(); 576 has_user_gesture = info->HasUserGesture();
574 } 577 }
575 578
576 DownloadControllerAndroidImpl::DownloadInfoAndroid::~DownloadInfoAndroid() {} 579 DownloadControllerAndroidImpl::DownloadInfoAndroid::~DownloadInfoAndroid() {}
577 580
578 } // namespace content 581 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698