| Index: chrome/browser/android/download/download_manager_service.cc
|
| diff --git a/chrome/browser/android/download/download_manager_service.cc b/chrome/browser/android/download/download_manager_service.cc
|
| index f7aab9567b62a8ad4b5fb9bda08826f653a461d7..d7e1bc39559f89054e5e2ee25e9ee8d778d5f476 100644
|
| --- a/chrome/browser/android/download/download_manager_service.cc
|
| +++ b/chrome/browser/android/download/download_manager_service.cc
|
| @@ -115,55 +115,21 @@ void DownloadManagerService::RemoveDownload(
|
| }
|
|
|
| void DownloadManagerService::GetAllDownloads(JNIEnv* env,
|
| - const JavaParamRef<jobject>& obj) {
|
| + const JavaParamRef<jobject>& obj,
|
| + bool is_off_the_record) {
|
| if (is_history_query_complete_)
|
| - GetAllDownloadsInternal();
|
| + GetAllDownloadsInternal(is_off_the_record);
|
| + else if (is_off_the_record)
|
| + EnqueueDownloadAction(std::string(), INITIALIZE_OFF_THE_RECORD_UI);
|
| else
|
| EnqueueDownloadAction(std::string(), INITIALIZE_UI);
|
| }
|
|
|
| -void DownloadManagerService::GetDownloadInfoFor(
|
| - JNIEnv* env,
|
| - jobject obj,
|
| - const JavaParamRef<jstring>& jdownload_guid,
|
| - bool is_off_the_record) {
|
| - // The UI shouldn't be able to request any info about a specific item until it
|
| - // has been initialized with the list of existing downloads.
|
| - DCHECK(is_history_query_complete_ || is_off_the_record);
|
| -
|
| +void DownloadManagerService::GetAllDownloadsInternal(bool is_off_the_record) {
|
| content::DownloadManager* manager = GetDownloadManager(is_off_the_record);
|
| if (java_ref_.is_null() || !manager)
|
| return;
|
|
|
| - // Search through the downloads for the entry with the given GUID.
|
| - content::DownloadManager::DownloadVector all_items;
|
| - manager->GetAllDownloads(&all_items);
|
| - std::string download_guid = ConvertJavaStringToUTF8(env, jdownload_guid);
|
| - for (auto item : all_items) {
|
| - if (item->GetGuid() != download_guid)
|
| - continue;
|
| -
|
| - Java_DownloadManagerService_onDownloadItemUpdated(
|
| - env,
|
| - java_ref_.obj(),
|
| - ConvertUTF8ToJavaString(env, item->GetGuid()).obj(),
|
| - ConvertUTF8ToJavaString(
|
| - env, item->GetFileNameToReportUser().value()).obj(),
|
| - ConvertUTF8ToJavaString(
|
| - env, item->GetTargetFilePath().value()).obj(),
|
| - ConvertUTF8ToJavaString(env, item->GetTabUrl().spec()).obj(),
|
| - ConvertUTF8ToJavaString(env, item->GetMimeType()).obj(),
|
| - item->GetStartTime().ToJavaTime(),
|
| - item->GetTotalBytes());
|
| - break;
|
| - }
|
| -}
|
| -
|
| -void DownloadManagerService::GetAllDownloadsInternal() {
|
| - content::DownloadManager* manager = GetDownloadManager(false);
|
| - if (java_ref_.is_null() || !manager)
|
| - return;
|
| -
|
| content::DownloadManager::DownloadVector all_items;
|
| manager->GetAllDownloads(&all_items);
|
|
|
| @@ -193,7 +159,7 @@ void DownloadManagerService::GetAllDownloadsInternal() {
|
| }
|
|
|
| Java_DownloadManagerService_onAllDownloadsRetrieved(
|
| - env, java_ref_.obj(), j_download_item_list.obj());
|
| + env, java_ref_.obj(), j_download_item_list.obj(), is_off_the_record);
|
| }
|
|
|
|
|
| @@ -231,7 +197,10 @@ void DownloadManagerService::OnHistoryQueryComplete() {
|
| CancelDownloadInternal(download_guid, false);
|
| break;
|
| case INITIALIZE_UI:
|
| - GetAllDownloadsInternal();
|
| + GetAllDownloadsInternal(false);
|
| + break;
|
| + case INITIALIZE_OFF_THE_RECORD_UI:
|
| + GetAllDownloadsInternal(true);
|
| break;
|
| default:
|
| NOTREACHED();
|
| @@ -244,15 +213,54 @@ void DownloadManagerService::OnHistoryQueryComplete() {
|
| content::DownloadManager* manager = GetDownloadManager(false);
|
| if (manager)
|
| original_notifier_.reset(new AllDownloadItemNotifier(manager, this));
|
| +
|
| + content::DownloadManager* off_the_record_manager = GetDownloadManager(true);
|
| + if (off_the_record_manager) {
|
| + off_the_record_notifier_.reset(
|
| + new AllDownloadItemNotifier(off_the_record_manager, this));
|
| + }
|
| +}
|
| +
|
| +void DownloadManagerService::OnDownloadUpdated(
|
| + content::DownloadManager* manager, content::DownloadItem* item) {
|
| + // Ignore anything that isn't a completed download notification.
|
| + if (!item->IsDone() || java_ref_.is_null())
|
| + return;
|
| +
|
| + bool is_off_the_record = false;
|
| + content::DownloadManager* off_the_record_manager = GetDownloadManager(true);
|
| + if (off_the_record_manager && manager == off_the_record_manager)
|
| + is_off_the_record = true;
|
| +
|
| + JNIEnv* env = base::android::AttachCurrentThread();
|
| + Java_DownloadManagerService_onDownloadItemUpdated(
|
| + env,
|
| + java_ref_.obj(),
|
| + ConvertUTF8ToJavaString(env, item->GetGuid()).obj(),
|
| + ConvertUTF8ToJavaString(
|
| + env, item->GetFileNameToReportUser().value()).obj(),
|
| + ConvertUTF8ToJavaString(
|
| + env, item->GetTargetFilePath().value()).obj(),
|
| + ConvertUTF8ToJavaString(env, item->GetTabUrl().spec()).obj(),
|
| + ConvertUTF8ToJavaString(env, item->GetMimeType()).obj(),
|
| + item->GetStartTime().ToJavaTime(),
|
| + item->GetTotalBytes(),
|
| + is_off_the_record);
|
| }
|
|
|
| void DownloadManagerService::OnDownloadRemoved(
|
| content::DownloadManager* manager, content::DownloadItem* item) {
|
| + bool is_off_the_record = false;
|
| + content::DownloadManager* off_the_record_manager = GetDownloadManager(true);
|
| + if (off_the_record_manager && manager == off_the_record_manager)
|
| + is_off_the_record = true;
|
| +
|
| JNIEnv* env = base::android::AttachCurrentThread();
|
| Java_DownloadManagerService_onDownloadItemRemoved(
|
| env,
|
| java_ref_.obj(),
|
| - ConvertUTF8ToJavaString(env, item->GetGuid()).obj());
|
| + ConvertUTF8ToJavaString(env, item->GetGuid()).obj(),
|
| + is_off_the_record);
|
| }
|
|
|
| void DownloadManagerService::ResumeDownloadInternal(
|
| @@ -335,6 +343,7 @@ void DownloadManagerService::EnqueueDownloadAction(
|
| iter->second = action;
|
| break;
|
| case INITIALIZE_UI:
|
| + case INITIALIZE_OFF_THE_RECORD_UI:
|
| iter->second = action;
|
| break;
|
| default:
|
|
|