Commit aed51f5d authored by Xing Liu's avatar Xing Liu Committed by Commit Bot

Download: Retrieve display names for all downloads.

This CL fixes a bug that download may disappear on Android Q after
they are completed.

We query and cache the display names from media store only when there
are more than 0 in progress downloads. So the cache might be empty and
we use the cache for completed download as well, which result in
missing display name and download history db recorded being removed.

Also directly check Android version in c++. The current code loads Q
API when loading Java static methods in DownloadCollectionBridge, which
triggers disk read violation on Android P.

Bug: 1106286
Change-Id: I2338a665a2147154ffd20df447fe74b84a8c8738
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2314299
Commit-Queue: Xing Liu <xingliu@chromium.org>
Reviewed-by: default avatarMin Qin <qinmin@chromium.org>
Reviewed-by: default avatarDavid Trainor <dtrainor@chromium.org>
Cr-Commit-Position: refs/heads/master@{#791631}
parent 1da1d190
...@@ -168,12 +168,6 @@ void DownloadCollectionBridge::GetDisplayNamesForDownloads( ...@@ -168,12 +168,6 @@ void DownloadCollectionBridge::GetDisplayNamesForDownloads(
std::move(cb).Run(std::move(result)); std::move(cb).Run(std::move(result));
} }
// static
bool DownloadCollectionBridge::NeedToRetrieveDisplayNames() {
JNIEnv* env = base::android::AttachCurrentThread();
return Java_DownloadCollectionBridge_needToRetrieveDisplayNames(env);
}
// static // static
base::FilePath DownloadCollectionBridge::GetDisplayName( base::FilePath DownloadCollectionBridge::GetDisplayName(
const base::FilePath& download_uri) { const base::FilePath& download_uri) {
......
...@@ -62,11 +62,6 @@ class COMPONENTS_DOWNLOAD_EXPORT DownloadCollectionBridge { ...@@ -62,11 +62,6 @@ class COMPONENTS_DOWNLOAD_EXPORT DownloadCollectionBridge {
static bool RenameDownloadUri(const base::FilePath& download_uri, static bool RenameDownloadUri(const base::FilePath& download_uri,
const base::FilePath& new_display_name); const base::FilePath& new_display_name);
// Whether download display names needs to be retrieved.
// TODO(qinmin): move display names to history and in-progress DB.
// Can be called on any thread.
static bool NeedToRetrieveDisplayNames();
using GetDisplayNamesCallback = using GetDisplayNamesCallback =
base::OnceCallback<void(InProgressDownloadManager::DisplayNames)>; base::OnceCallback<void(InProgressDownloadManager::DisplayNames)>;
// Gets the display name for all downloads. // Gets the display name for all downloads.
......
...@@ -262,14 +262,6 @@ public class DownloadCollectionBridge { ...@@ -262,14 +262,6 @@ public class DownloadCollectionBridge {
== 1; == 1;
} }
/**
* @return Whether download display names needs to be retrieved.
*/
@CalledByNative
private static boolean needToRetrieveDisplayNames() {
return isAtLeastQ();
}
/** /**
* Gets the display names for all downloads * Gets the display names for all downloads
* @return an array of download Uri and display name pair. * @return an array of download Uri and display name pair.
......
...@@ -30,6 +30,7 @@ ...@@ -30,6 +30,7 @@
#include "services/network/public/mojom/url_response_head.mojom.h" #include "services/network/public/mojom/url_response_head.mojom.h"
#if defined(OS_ANDROID) #if defined(OS_ANDROID)
#include "base/android/build_info.h"
#include "components/download/internal/common/android/download_collection_bridge.h" #include "components/download/internal/common/android/download_collection_bridge.h"
#include "components/download/public/common/download_path_reservation_tracker.h" #include "components/download/public/common/download_path_reservation_tracker.h"
#endif #endif
...@@ -574,8 +575,8 @@ void InProgressDownloadManager::OnDBInitialized( ...@@ -574,8 +575,8 @@ void InProgressDownloadManager::OnDBInitialized(
bool success, bool success,
std::unique_ptr<std::vector<DownloadDBEntry>> entries) { std::unique_ptr<std::vector<DownloadDBEntry>> entries) {
#if defined(OS_ANDROID) #if defined(OS_ANDROID)
if (entries->size() > 0 && // Retrieve display names for all downloads from media store if needed.
DownloadCollectionBridge::NeedToRetrieveDisplayNames()) { if (base::android::BuildInfo::GetInstance()->is_at_least_q()) {
DownloadCollectionBridge::GetDisplayNamesCallback callback = DownloadCollectionBridge::GetDisplayNamesCallback callback =
base::BindOnce(&InProgressDownloadManager::OnDownloadNamesRetrieved, base::BindOnce(&InProgressDownloadManager::OnDownloadNamesRetrieved,
weak_factory_.GetWeakPtr(), std::move(entries)); weak_factory_.GetWeakPtr(), std::move(entries));
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment