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

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

Issue 1809203006: Switch to use download GUID to indentify download items (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix merge error Created 4 years, 8 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 435 matching lines...) Expand 10 before | Expand all | Expand 10 after
446 env, GetJavaObject()->Controller(env).obj(), view.obj(), jfilename.obj(), 446 env, GetJavaObject()->Controller(env).obj(), view.obj(), jfilename.obj(),
447 jmime_type.obj()); 447 jmime_type.obj());
448 } 448 }
449 449
450 void DownloadControllerAndroidImpl::OnDownloadUpdated(DownloadItem* item) { 450 void DownloadControllerAndroidImpl::OnDownloadUpdated(DownloadItem* item) {
451 DCHECK_CURRENTLY_ON(BrowserThread::UI); 451 DCHECK_CURRENTLY_ON(BrowserThread::UI);
452 if (item->IsDangerous() && (item->GetState() != DownloadItem::CANCELLED)) 452 if (item->IsDangerous() && (item->GetState() != DownloadItem::CANCELLED))
453 OnDangerousDownload(item); 453 OnDangerousDownload(item);
454 454
455 JNIEnv* env = base::android::AttachCurrentThread(); 455 JNIEnv* env = base::android::AttachCurrentThread();
456 ScopedJavaLocalRef<jstring> jguid =
457 ConvertUTF8ToJavaString(env, item->GetGuid());
456 ScopedJavaLocalRef<jstring> jurl = 458 ScopedJavaLocalRef<jstring> jurl =
457 ConvertUTF8ToJavaString(env, item->GetURL().spec()); 459 ConvertUTF8ToJavaString(env, item->GetURL().spec());
458 ScopedJavaLocalRef<jstring> jmime_type = 460 ScopedJavaLocalRef<jstring> jmime_type =
459 ConvertUTF8ToJavaString(env, item->GetMimeType()); 461 ConvertUTF8ToJavaString(env, item->GetMimeType());
460 ScopedJavaLocalRef<jstring> jpath = 462 ScopedJavaLocalRef<jstring> jpath =
461 ConvertUTF8ToJavaString(env, item->GetTargetFilePath().value()); 463 ConvertUTF8ToJavaString(env, item->GetTargetFilePath().value());
462 ScopedJavaLocalRef<jstring> jfilename = ConvertUTF8ToJavaString( 464 ScopedJavaLocalRef<jstring> jfilename = ConvertUTF8ToJavaString(
463 env, item->GetTargetFilePath().BaseName().value()); 465 env, item->GetTargetFilePath().BaseName().value());
464 ScopedJavaLocalRef<jstring> joriginal_url = 466 ScopedJavaLocalRef<jstring> joriginal_url =
465 ConvertUTF8ToJavaString(env, item->GetOriginalUrl().spec()); 467 ConvertUTF8ToJavaString(env, item->GetOriginalUrl().spec());
466 ScopedJavaLocalRef<jstring> jreferrer_url = 468 ScopedJavaLocalRef<jstring> jreferrer_url =
467 ConvertUTF8ToJavaString(env, item->GetReferrerUrl().spec()); 469 ConvertUTF8ToJavaString(env, item->GetReferrerUrl().spec());
468 470
469 switch (item->GetState()) { 471 switch (item->GetState()) {
470 case DownloadItem::IN_PROGRESS: { 472 case DownloadItem::IN_PROGRESS: {
471 base::TimeDelta time_delta; 473 base::TimeDelta time_delta;
472 item->TimeRemaining(&time_delta); 474 item->TimeRemaining(&time_delta);
473 Java_DownloadController_onDownloadUpdated( 475 Java_DownloadController_onDownloadUpdated(
474 env, GetJavaObject()->Controller(env).obj(), jurl.obj(), 476 env, GetJavaObject()->Controller(env).obj(), jurl.obj(),
475 jmime_type.obj(), jfilename.obj(), jpath.obj(), 477 jmime_type.obj(), jfilename.obj(), jpath.obj(),
476 item->GetReceivedBytes(), item->GetId(), item->PercentComplete(), 478 item->GetReceivedBytes(), item->GetId(), jguid.obj(),
477 time_delta.InMilliseconds(), item->HasUserGesture(), item->IsPaused(), 479 item->PercentComplete(), time_delta.InMilliseconds(),
480 item->HasUserGesture(), item->IsPaused(),
478 // Get all requirements that allows a download to be resumable. 481 // Get all requirements that allows a download to be resumable.
479 !item->GetBrowserContext()->IsOffTheRecord()); 482 !item->GetBrowserContext()->IsOffTheRecord());
480 break; 483 break;
481 } 484 }
482 case DownloadItem::COMPLETE: 485 case DownloadItem::COMPLETE:
483 // Multiple OnDownloadUpdated() notifications may be issued while the 486 // Multiple OnDownloadUpdated() notifications may be issued while the
484 // download is in the COMPLETE state. Only handle one. 487 // download is in the COMPLETE state. Only handle one.
485 item->RemoveObserver(this); 488 item->RemoveObserver(this);
486 489
487 // Call onDownloadCompleted 490 // Call onDownloadCompleted
488 Java_DownloadController_onDownloadCompleted( 491 Java_DownloadController_onDownloadCompleted(
489 env, GetJavaObject()->Controller(env).obj(), jurl.obj(), 492 env, GetJavaObject()->Controller(env).obj(), jurl.obj(),
490 jmime_type.obj(), jfilename.obj(), jpath.obj(), 493 jmime_type.obj(), jfilename.obj(), jpath.obj(),
491 item->GetReceivedBytes(), item->GetId(), 494 item->GetReceivedBytes(), item->GetId(), jguid.obj(),
492 joriginal_url.obj(), jreferrer_url.obj(), item->HasUserGesture()); 495 joriginal_url.obj(), jreferrer_url.obj(), item->HasUserGesture());
493 break; 496 break;
494 case DownloadItem::CANCELLED: 497 case DownloadItem::CANCELLED:
495 Java_DownloadController_onDownloadCancelled( 498 Java_DownloadController_onDownloadCancelled(
496 env, GetJavaObject()->Controller(env).obj(), item->GetId()); 499 env, GetJavaObject()->Controller(env).obj(), item->GetId(),
500 jguid.obj());
497 break; 501 break;
498 case DownloadItem::INTERRUPTED: 502 case DownloadItem::INTERRUPTED:
499 // When device loses/changes network, we get a NETWORK_TIMEOUT, 503 // When device loses/changes network, we get a NETWORK_TIMEOUT,
500 // NETWORK_FAILED or NETWORK_DISCONNECTED error. Download should auto 504 // NETWORK_FAILED or NETWORK_DISCONNECTED error. Download should auto
501 // resume in this case. 505 // resume in this case.
502 Java_DownloadController_onDownloadInterrupted( 506 Java_DownloadController_onDownloadInterrupted(
503 env, GetJavaObject()->Controller(env).obj(), jurl.obj(), 507 env, GetJavaObject()->Controller(env).obj(), jurl.obj(),
504 jmime_type.obj(), jfilename.obj(), jpath.obj(), 508 jmime_type.obj(), jfilename.obj(), jpath.obj(),
505 item->GetReceivedBytes(), item->GetId(), item->CanResume(), 509 item->GetReceivedBytes(), item->GetId(), jguid.obj(),
506 IsInterruptedDownloadAutoResumable(item)); 510 item->CanResume(), IsInterruptedDownloadAutoResumable(item));
511 item->RemoveObserver(this);
507 break; 512 break;
508 case DownloadItem::MAX_DOWNLOAD_STATE: 513 case DownloadItem::MAX_DOWNLOAD_STATE:
509 NOTREACHED(); 514 NOTREACHED();
510 } 515 }
511 } 516 }
512 517
513 void DownloadControllerAndroidImpl::OnDangerousDownload(DownloadItem* item) { 518 void DownloadControllerAndroidImpl::OnDangerousDownload(DownloadItem* item) {
514 JNIEnv* env = base::android::AttachCurrentThread(); 519 JNIEnv* env = base::android::AttachCurrentThread();
515 ScopedJavaLocalRef<jstring> jfilename = ConvertUTF8ToJavaString( 520 ScopedJavaLocalRef<jstring> jfilename = ConvertUTF8ToJavaString(
516 env, item->GetTargetFilePath().BaseName().value()); 521 env, item->GetTargetFilePath().BaseName().value());
522 ScopedJavaLocalRef<jstring> jguid =
523 ConvertUTF8ToJavaString(env, item->GetGuid());
517 ScopedJavaLocalRef<jobject> view_core = GetContentViewCoreFromWebContents( 524 ScopedJavaLocalRef<jobject> view_core = GetContentViewCoreFromWebContents(
518 item->GetWebContents()); 525 item->GetWebContents());
519 if (!view_core.is_null()) { 526 if (!view_core.is_null()) {
520 Java_DownloadController_onDangerousDownload( 527 Java_DownloadController_onDangerousDownload(
521 env, GetJavaObject()->Controller(env).obj(), view_core.obj(), 528 env, GetJavaObject()->Controller(env).obj(), view_core.obj(),
522 jfilename.obj(), item->GetId()); 529 jfilename.obj(), jguid.obj());
523 } 530 }
524 } 531 }
525 532
526 ScopedJavaLocalRef<jobject> 533 ScopedJavaLocalRef<jobject>
527 DownloadControllerAndroidImpl::GetContentViewCoreFromWebContents( 534 DownloadControllerAndroidImpl::GetContentViewCoreFromWebContents(
528 WebContents* web_contents) { 535 WebContents* web_contents) {
529 if (!web_contents) 536 if (!web_contents)
530 return ScopedJavaLocalRef<jobject>(); 537 return ScopedJavaLocalRef<jobject>();
531 538
532 ContentViewCore* view_core = ContentViewCore::FromWebContents(web_contents); 539 ContentViewCore* view_core = ContentViewCore::FromWebContents(web_contents);
(...skipping 19 matching lines...) Expand all
552 const ContextMenuParams& params, WebContents* web_contents, bool is_link, 559 const ContextMenuParams& params, WebContents* web_contents, bool is_link,
553 const std::string& extra_headers) { 560 const std::string& extra_headers) {
554 int process_id = web_contents->GetRenderProcessHost()->GetID(); 561 int process_id = web_contents->GetRenderProcessHost()->GetID();
555 int routing_id = web_contents->GetRoutingID(); 562 int routing_id = web_contents->GetRoutingID();
556 AcquireFileAccessPermission( 563 AcquireFileAccessPermission(
557 web_contents, base::Bind(&CreateContextMenuDownload, process_id, 564 web_contents, base::Bind(&CreateContextMenuDownload, process_id,
558 routing_id, params, is_link, extra_headers)); 565 routing_id, params, is_link, extra_headers));
559 } 566 }
560 567
561 void DownloadControllerAndroidImpl::DangerousDownloadValidated( 568 void DownloadControllerAndroidImpl::DangerousDownloadValidated(
562 WebContents* web_contents, int download_id, bool accept) { 569 WebContents* web_contents,
570 const std::string& download_guid,
571 bool accept) {
563 if (!web_contents) 572 if (!web_contents)
564 return; 573 return;
565 DownloadManagerImpl* dlm = static_cast<DownloadManagerImpl*>( 574 DownloadManagerImpl* dlm = static_cast<DownloadManagerImpl*>(
566 BrowserContext::GetDownloadManager(web_contents->GetBrowserContext())); 575 BrowserContext::GetDownloadManager(web_contents->GetBrowserContext()));
567 DownloadItem* item = dlm->GetDownload(download_id); 576 DownloadItem* item = dlm->GetDownloadByGuid(download_guid);
568 if (!item) 577 if (!item)
569 return; 578 return;
570 if (accept) 579 if (accept)
571 item->ValidateDangerousDownload(); 580 item->ValidateDangerousDownload();
572 else 581 else
573 item->Remove(); 582 item->Remove();
574 } 583 }
575 584
576 DownloadControllerAndroidImpl::DownloadInfoAndroid::DownloadInfoAndroid( 585 DownloadControllerAndroidImpl::DownloadInfoAndroid::DownloadInfoAndroid(
577 net::URLRequest* request) 586 net::URLRequest* request)
(...skipping 16 matching lines...) Expand all
594 } 603 }
595 604
596 const ResourceRequestInfo* info = ResourceRequestInfo::ForRequest(request); 605 const ResourceRequestInfo* info = ResourceRequestInfo::ForRequest(request);
597 if (info) 606 if (info)
598 has_user_gesture = info->HasUserGesture(); 607 has_user_gesture = info->HasUserGesture();
599 } 608 }
600 609
601 DownloadControllerAndroidImpl::DownloadInfoAndroid::~DownloadInfoAndroid() {} 610 DownloadControllerAndroidImpl::DownloadInfoAndroid::~DownloadInfoAndroid() {}
602 611
603 } // namespace content 612 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698