diff options
author | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2020-11-18 16:35:47 +0100 |
---|---|---|
committer | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2020-11-18 15:45:54 +0000 |
commit | 32f5a1c56531e4210bc4cf8d8c7825d66e081888 (patch) | |
tree | eeeec6822f4d738d8454525233fd0e2e3a659e6d /chromium/components/download | |
parent | 99677208ff3b216fdfec551fbe548da5520cd6fb (diff) | |
download | qtwebengine-chromium-32f5a1c56531e4210bc4cf8d8c7825d66e081888.tar.gz |
BASELINE: Update Chromium to 87.0.4280.67
Change-Id: Ib157360be8c2ffb2c73125751a89f60e049c1d54
Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
Diffstat (limited to 'chromium/components/download')
16 files changed, 22 insertions, 738 deletions
diff --git a/chromium/components/download/internal/background_service/android/java/src/org/chromium/components/download/internal/BatteryStatusListenerAndroid.java b/chromium/components/download/internal/background_service/android/java/src/org/chromium/components/download/internal/BatteryStatusListenerAndroid.java deleted file mode 100644 index 7f26b65b793..00000000000 --- a/chromium/components/download/internal/background_service/android/java/src/org/chromium/components/download/internal/BatteryStatusListenerAndroid.java +++ /dev/null @@ -1,37 +0,0 @@ -// Copyright 2017 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -package org.chromium.components.download.internal; - -import android.content.Intent; -import android.content.IntentFilter; -import android.os.BatteryManager; - -import org.chromium.base.ContextUtils; -import org.chromium.base.annotations.CalledByNative; -import org.chromium.base.annotations.JNINamespace; - -/** - * Helper Java class to query battery status. - * - * The class is created and owned by native side. - */ -@JNINamespace("download") -public final class BatteryStatusListenerAndroid { - @CalledByNative - public static int getBatteryPercentage() { - IntentFilter filter = new IntentFilter(Intent.ACTION_BATTERY_CHANGED); - Intent batteryStatus = ContextUtils.getApplicationContext().registerReceiver(null, filter); - if (batteryStatus == null) return 0; - - int scale = batteryStatus.getIntExtra(BatteryManager.EXTRA_SCALE, -1); - if (scale == 0) return 0; - - int level = batteryStatus.getIntExtra(BatteryManager.EXTRA_LEVEL, -1); - int percentage = (int) Math.round(100.0 * level / scale); - - assert(percentage >= 0 && percentage <= 100); - return percentage; - } -} diff --git a/chromium/components/download/internal/background_service/controller_impl.cc b/chromium/components/download/internal/background_service/controller_impl.cc index cff032f274d..1060e6ee71b 100644 --- a/chromium/components/download/internal/background_service/controller_impl.cc +++ b/chromium/components/download/internal/background_service/controller_impl.cc @@ -860,7 +860,6 @@ void ControllerImpl::ResolveInitialRequestStates() { // Update the Entry::State to the new correct state. if (new_state != entry->state) { - stats::LogRecoveryOperation(new_state); TransitTo(entry, new_state, model_.get()); } @@ -1150,8 +1149,6 @@ void ControllerImpl::HandleCompleteDownload(CompletionType type, if (type == CompletionType::SUCCEED) { DCHECK(driver_entry.has_value()); - stats::LogFilePathRenamed(driver_entry->current_file_path != - entry->target_file_path); entry->target_file_path = driver_entry->current_file_path; entry->completion_time = driver_entry->completion_time; entry->bytes_downloaded = driver_entry->bytes_downloaded; diff --git a/chromium/components/download/internal/background_service/scheduler/device_status_listener.cc b/chromium/components/download/internal/background_service/scheduler/device_status_listener.cc index 76f11e5db9c..becbb1fe920 100644 --- a/chromium/components/download/internal/background_service/scheduler/device_status_listener.cc +++ b/chromium/components/download/internal/background_service/scheduler/device_status_listener.cc @@ -24,6 +24,9 @@ NetworkStatus ToNetworkStatus(network::mojom::ConnectionType type) { case network::mojom::ConnectionType::CONNECTION_2G: case network::mojom::ConnectionType::CONNECTION_3G: case network::mojom::ConnectionType::CONNECTION_4G: + case network::mojom::ConnectionType::CONNECTION_5G: + // TODO(crbug.com/1127134): 5G networks may be unmetered. Find a way to + // detect this and make DeviceStatusListener aware of it. return NetworkStatus::METERED; case network::mojom::ConnectionType::CONNECTION_UNKNOWN: case network::mojom::ConnectionType::CONNECTION_NONE: diff --git a/chromium/components/download/internal/background_service/stats.cc b/chromium/components/download/internal/background_service/stats.cc index f4b6d5d9cc3..1a98f954f23 100644 --- a/chromium/components/download/internal/background_service/stats.cc +++ b/chromium/components/download/internal/background_service/stats.cc @@ -192,11 +192,6 @@ void LogStartDownloadResult(DownloadClient client, DownloadParams::StartResult::COUNT); } -void LogRecoveryOperation(Entry::State to_state) { - UMA_HISTOGRAM_ENUMERATION("Download.Service.Recovery", to_state, - Entry::State::COUNT); -} - void LogDownloadCompletion(CompletionType type, uint64_t file_size_bytes) { // Records completion type. UMA_HISTOGRAM_ENUMERATION("Download.Service.Finish.Type", type, @@ -299,12 +294,6 @@ void LogFileDirDiskUtilization(int64_t total_disk_space, int64_t files_size) { UMA_HISTOGRAM_PERCENTAGE("Download.Service.Files.FreeDiskSpace", (free_disk_space * 100) / total_disk_space); - UMA_HISTOGRAM_PERCENTAGE("Download.Service.Files.DiskUsed", - (files_size * 100) / total_disk_space); -} - -void LogFilePathRenamed(bool renamed) { - UMA_HISTOGRAM_BOOLEAN("Download.Service.Files.PathRenamed", renamed); } void LogEntryEvent(DownloadEvent event) { diff --git a/chromium/components/download/internal/background_service/stats.h b/chromium/components/download/internal/background_service/stats.h index 950801342e8..7bbeda897e6 100644 --- a/chromium/components/download/internal/background_service/stats.h +++ b/chromium/components/download/internal/background_service/stats.h @@ -159,10 +159,6 @@ void LogServiceApiAction(DownloadClient client, ServiceApiAction action); void LogStartDownloadResult(DownloadClient client, DownloadParams::StartResult result); -// Logs recovery operations that happened when we had to move from one state -// to another on startup. -void LogRecoveryOperation(Entry::State to_state); - // Logs download completion event, download time, and the file size. void LogDownloadCompletion(CompletionType type, uint64_t file_size_bytes); @@ -203,10 +199,6 @@ void LogFileDirDiskUtilization(int64_t total_disk_space, int64_t free_disk_space, int64_t files_size); -// Logs if the final download file path is different from the requested file -// path. -void LogFilePathRenamed(bool renamed); - // Logs an action the Controller takes on an active download. void LogEntryEvent(DownloadEvent event); diff --git a/chromium/components/download/internal/common/BUILD.gn b/chromium/components/download/internal/common/BUILD.gn index 97ee3626adc..b2e26585bbe 100644 --- a/chromium/components/download/internal/common/BUILD.gn +++ b/chromium/components/download/internal/common/BUILD.gn @@ -9,6 +9,13 @@ if (is_android) { import("//build/config/android/rules.gni") } +# This file depends on the legacy global sources assignment filter. It should +# be converted to check target platform before assigning source files to the +# sources variable. Remove this import and set_sources_assignment_filter call +# when the file has been converted. See https://crbug.com/1018739 for details. +import("//build/config/deprecated_default_sources_assignment_filter.gni") +set_sources_assignment_filter(deprecated_default_sources_assignment_filter) + source_set("internal") { visibility = [ ":for_tests", diff --git a/chromium/components/download/internal/common/android/java/src/org/chromium/components/download/DownloadCollectionBridge.java b/chromium/components/download/internal/common/android/java/src/org/chromium/components/download/DownloadCollectionBridge.java deleted file mode 100644 index 680a72377e1..00000000000 --- a/chromium/components/download/internal/common/android/java/src/org/chromium/components/download/DownloadCollectionBridge.java +++ /dev/null @@ -1,451 +0,0 @@ -// Copyright 2019 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -package org.chromium.components.download; - -import android.annotation.TargetApi; -import android.content.ContentResolver; -import android.content.ContentUris; -import android.content.ContentValues; -import android.database.Cursor; -import android.net.Uri; -import android.os.Build; -import android.os.FileUtils; -import android.os.ParcelFileDescriptor; -import android.provider.BaseColumns; -import android.provider.MediaStore; -import android.provider.MediaStore.Downloads; -import android.provider.MediaStore.MediaColumns; -import android.text.TextUtils; -import android.text.format.DateUtils; - -import androidx.annotation.NonNull; - -import org.chromium.base.BuildInfo; -import org.chromium.base.ContextUtils; -import org.chromium.base.Log; -import org.chromium.base.StrictModeContext; -import org.chromium.base.annotations.CalledByNative; -import org.chromium.base.annotations.JNINamespace; -import org.chromium.base.annotations.NativeMethods; -import org.chromium.third_party.android.provider.MediaStoreUtils; -import org.chromium.third_party.android.provider.MediaStoreUtils.PendingParams; -import org.chromium.third_party.android.provider.MediaStoreUtils.PendingSession; - -import java.io.FileInputStream; -import java.io.InputStream; -import java.io.OutputStream; -import java.text.SimpleDateFormat; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Date; -import java.util.List; -import java.util.Locale; - -/** - * Helper class for publishing download files to the public download collection. - */ -@JNINamespace("download") -public class DownloadCollectionBridge { - private static final String TAG = "DownloadCollection"; - - // File name pattern to be used when media store has too many duplicates. This matches - // that of download_path_reservation_tracker.cc. - private static final String FILE_NAME_PATTERN = "yyyy-MM-dd'T'HHmmss.SSS"; - - private static final List<String> COMMON_DOUBLE_EXTENSIONS = - new ArrayList<String>(Arrays.asList("tar.gz", "tar.z", "tar.bz2", "tar.bz", "user.js")); - - private static DownloadDelegate sDownloadDelegate = new DownloadDelegate(); - - /** - * Class representing the Uri and display name pair for downloads. - */ - protected static class DisplayNameInfo { - private final String mUri; - private final String mDisplayName; - - public DisplayNameInfo(String uri, String displayName) { - mUri = uri; - mDisplayName = displayName; - } - - @CalledByNative("DisplayNameInfo") - private String getDownloadUri() { - return mUri; - } - - @CalledByNative("DisplayNameInfo") - private String getDisplayName() { - return mDisplayName; - } - } - - /** - * Sets the DownloadDelegate to be used for utility methods. - * TODO(qinmin): remove this method once we moved all the utility methods into - * components/. - * @param downloadDelegate The new delegate to be used. - */ - public static void setDownloadDelegate(DownloadDelegate downloadDelegate) { - // TODO(qinmin): On Android O, ClassLoader may need to access disk when - // setting the |sDownloadDelegate|. Move this to a background thread. - // See http://crbug.com/1061042. - try (StrictModeContext ignored = StrictModeContext.allowDiskReads()) { - sDownloadDelegate = downloadDelegate; - } - } - - /** - * Creates an intermediate URI for download to be written into. On completion, call - * nativeOnCreateIntermediateUriResult() with |callbackId|. - * @param fileName Name of the file. - * @param mimeType Mime type of the file. - * @param originalUrl Originating URL of the download. - * @param referrer Referrer of the download. - */ - @CalledByNative - public static String createIntermediateUriForPublish(final String fileName, - final String mimeType, final String originalUrl, final String referrer) { - Uri uri = createPendingSessionInternal(fileName, mimeType, originalUrl, referrer); - if (uri != null) return uri.toString(); - - // If there are too many duplicates on the same file name, createPendingSessionInternal() - // will return null. Generate a new file name with timestamp. - SimpleDateFormat sdf = new SimpleDateFormat(FILE_NAME_PATTERN, Locale.getDefault()); - // Remove the extension first. - String baseName = getBaseName(fileName); - String extension = fileName.substring(baseName.length()); - StringBuilder sb = new StringBuilder(baseName); - sb.append(" - "); - sb.append(sdf.format(new Date())); - sb.append(extension); - uri = createPendingSessionInternal(sb.toString(), mimeType, originalUrl, referrer); - return uri == null ? null : uri.toString(); - } - - /** - * Returns whether a download needs to be published. - * @param filePath File path of the download. - * @return True if the download needs to be published, or false otherwise. - */ - @CalledByNative - public static boolean shouldPublishDownload(final String filePath) { - if (isAtLeastQ()) { - if (filePath == null) return false; - // Only need to publish downloads that are on primary storage. - return !sDownloadDelegate.isDownloadOnSDCard(filePath); - } - return false; - } - - /** - * Copies file content from a source file to the destination Uri. - * @param sourcePath File content to be copied from. - * @param destinationUri Destination Uri to be copied to. - * @return True on success, or false otherwise. - */ - @CalledByNative - @TargetApi(29) - public static boolean copyFileToIntermediateUri( - final String sourcePath, final String destinationUri) { - try { - PendingSession session = openPendingUri(destinationUri); - OutputStream out = session.openOutputStream(); - InputStream in = new FileInputStream(sourcePath); - FileUtils.copy(in, out); - in.close(); - out.close(); - return true; - } catch (Exception e) { - Log.e(TAG, "Unable to copy content to pending Uri.", e); - } - return false; - } - - /** - * Deletes the intermediate Uri. - * @param uri Intermediate Uri that is going to be deleted. - */ - @CalledByNative - public static void deleteIntermediateUri(final String uri) { - PendingSession session = openPendingUri(uri); - session.abandon(); - } - - /** - * Publishes the completed download to public download collection. - * @param intermediateUri Intermediate Uri that is going to be published. - * @return Uri of the published file. - */ - @CalledByNative - public static String publishDownload(final String intermediateUri) { - // Android Q's MediaStore.Downloads has an issue that the custom mime type which is not - // supported by MimeTypeMap is overridden to "application/octet-stream" when publishing. - // To deal with this issue we set the mime type again after publishing. - // See crbug.com/1010829 for more details. - ContentResolver resolver = ContextUtils.getApplicationContext().getContentResolver(); - String mimeType = null; - Cursor cursor = null; - try { - cursor = resolver.query(Uri.parse(intermediateUri), - new String[] {MediaColumns.MIME_TYPE}, null, null, null); - if (cursor != null && cursor.getCount() != 0 && cursor.moveToNext()) { - mimeType = cursor.getString(cursor.getColumnIndex(MediaColumns.MIME_TYPE)); - } - } catch (Exception e) { - Log.e(TAG, "Unable to get mimeType.", e); - } finally { - if (cursor != null) cursor.close(); - } - - PendingSession session = openPendingUri(intermediateUri); - Uri publishedUri = session.publish(); - if (!TextUtils.isEmpty(mimeType)) { - try { - final ContentValues updateValues = new ContentValues(); - updateValues.put(MediaColumns.MIME_TYPE, mimeType); - resolver.update(publishedUri, updateValues, null, null); - } catch (Exception e) { - Log.e(TAG, "Unable to modify mimeType.", e); - } - } - return publishedUri.toString(); - } - - /** - * Opens the intermediate Uri for writing. - * @param intermediateUri Intermediate Uri that is going to be written to. - * @return file descriptor that is opened for writing. - */ - @CalledByNative - private static int openIntermediateUri(final String intermediateUri) { - try { - ContentResolver resolver = ContextUtils.getApplicationContext().getContentResolver(); - ParcelFileDescriptor pfd = - resolver.openFileDescriptor(Uri.parse(intermediateUri), "rw"); - ContentValues updateValues = new ContentValues(); - updateValues.put("date_expires", getNewExpirationTime()); - ContextUtils.getApplicationContext().getContentResolver().update( - Uri.parse(intermediateUri), updateValues, null, null); - return pfd.detachFd(); - } catch (Exception e) { - Log.e(TAG, "Cannot open intermediate Uri.", e); - } - return -1; - } - - /** - * Check if a download with the same name already exists. - * @param fileName The name of the file to check. - * @return whether a download with the file name exists. - */ - @CalledByNative - private static boolean fileNameExists(final String fileName) { - return getDownloadUriForFileName(fileName) != null; - } - - /** - * Renames a download Uri with a display name. - * @param downloadUri Uri of the download. - * @param displayName New display name for the download. - * @return whether rename was successful. - */ - @CalledByNative - private static boolean renameDownloadUri(final String downloadUri, final String displayName) { - final ContentValues updateValues = new ContentValues(); - Uri uri = Uri.parse(downloadUri); - updateValues.put(MediaColumns.DISPLAY_NAME, displayName); - return ContextUtils.getApplicationContext().getContentResolver().update( - uri, updateValues, null, null) - == 1; - } - - /** - * Gets the display names for all downloads - * @return an array of download Uri and display name pair. - */ - @CalledByNative - @TargetApi(29) - private static DisplayNameInfo[] getDisplayNamesForDownloads() { - ContentResolver resolver = ContextUtils.getApplicationContext().getContentResolver(); - Cursor cursor = null; - try { - Uri uri = Downloads.EXTERNAL_CONTENT_URI; - cursor = resolver.query(MediaStore.setIncludePending(uri), - new String[] {BaseColumns._ID, MediaColumns.DISPLAY_NAME}, null, null, null); - if (cursor == null || cursor.getCount() == 0) return null; - List<DisplayNameInfo> infos = new ArrayList<DisplayNameInfo>(); - while (cursor.moveToNext()) { - String displayName = - cursor.getString(cursor.getColumnIndex(MediaColumns.DISPLAY_NAME)); - Uri downloadUri = ContentUris.withAppendedId( - uri, cursor.getInt(cursor.getColumnIndex(BaseColumns._ID))); - infos.add(new DisplayNameInfo(downloadUri.toString(), displayName)); - } - return infos.toArray(new DisplayNameInfo[0]); - } catch (Exception e) { - Log.e(TAG, "Unable to get display names for downloads.", e); - } finally { - if (cursor != null) cursor.close(); - } - return null; - } - - /** - * @return whether download collection is supported. - */ - public static boolean supportsDownloadCollection() { - return isAtLeastQ(); - } - - /** - * Gets the content URI of the download that has the given file name. - * @param pendingUri name of the file. - * @return Uri of the download with the given display name. - */ - @TargetApi(29) - public static Uri getDownloadUriForFileName(String fileName) { - Cursor cursor = null; - try { - Uri uri = Downloads.EXTERNAL_CONTENT_URI; - cursor = ContextUtils.getApplicationContext().getContentResolver().query( - MediaStore.setIncludePending(uri), new String[] {BaseColumns._ID}, - "_display_name LIKE ?1", new String[] {fileName}, null); - if (cursor == null) return null; - if (cursor.moveToNext()) { - return ContentUris.withAppendedId( - uri, cursor.getInt(cursor.getColumnIndex(BaseColumns._ID))); - } - } catch (Exception e) { - Log.e(TAG, "Unable to check file name existence.", e); - } finally { - if (cursor != null) cursor.close(); - } - return null; - } - - /** - * @return number of days for an intermediate download to expire. - */ - public static int getExpirationDurationInDays() { - return DownloadCollectionBridgeJni.get().getExpirationDurationInDays(); - } - - private static boolean isAtLeastQ() { - return BuildInfo.isAtLeastQ() || Build.VERSION.SDK_INT >= 29; - } - - /** - * Helper method to create a pending session for download to be written into. - * @param fileName Name of the file. - * @param mimeType Mime type of the file. - * @param originalUrl Originating URL of the download. - * @param referrer Referrer of the download. - * @return Uri created for the pending session, or null if failed. - */ - private static Uri createPendingSessionInternal(final String fileName, final String mimeType, - final String originalUrl, final String referrer) { - PendingParams pendingParams = - createPendingParams(fileName, mimeType, originalUrl, referrer); - pendingParams.setExpirationTime(getNewExpirationTime()); - try { - return MediaStoreUtils.createPending( - ContextUtils.getApplicationContext(), pendingParams); - } catch (Exception e) { - return null; - } - } - - /** - * Helper method to create PendingParams needed for PendingSession creation. - * @param fileName Name of the file. - * @param mimeType Mime type of the file. - * @param originalUrl Originating URL of the download. - * @param referrer Referrer of the download. - * @return PendingParams needed for creating the PendingSession. - */ - @TargetApi(29) - private static PendingParams createPendingParams(final String fileName, final String mimeType, - final String originalUrl, final String referrer) { - Uri downloadsUri = Downloads.EXTERNAL_CONTENT_URI; - String newMimeType = - sDownloadDelegate.remapGenericMimeType(mimeType, originalUrl, fileName); - PendingParams pendingParams = new PendingParams(downloadsUri, fileName, newMimeType); - Uri originalUri = sDownloadDelegate.parseOriginalUrl(originalUrl); - Uri referrerUri = TextUtils.isEmpty(referrer) ? null : Uri.parse(referrer); - pendingParams.setDownloadUri(originalUri); - pendingParams.setRefererUri(referrerUri); - return pendingParams; - } - - /** - * Gets the base name, without extension, from a file name. - * TODO(qinmin): move this into a common utility class. - * @param fileName Name of the file. - * @return Base name of the file. - */ - private static String getBaseName(final String fileName) { - for (String extension : COMMON_DOUBLE_EXTENSIONS) { - if (fileName.endsWith(extension)) { - String name = fileName.substring(0, fileName.length() - extension.length()); - // remove the "." at the end. - if (name.endsWith(".")) { - return name.substring(0, name.length() - 1); - } - } - } - int index = fileName.lastIndexOf('.'); - if (index == -1) { - return fileName; - } else { - return fileName.substring(0, index); - } - } - - private static @NonNull PendingSession openPendingUri(final String pendingUri) { - return MediaStoreUtils.openPending( - ContextUtils.getApplicationContext(), Uri.parse(pendingUri)); - } - - /** - * Helper method to generate a new expiration epoch time in seconds. - * @return Epoch time value in seconds for the download to expire. - */ - private static long getNewExpirationTime() { - return (System.currentTimeMillis() - + DownloadCollectionBridge.getExpirationDurationInDays() - * DateUtils.DAY_IN_MILLIS) - / 1000; - } - - /** - * Gets the display name for a download. - * @param downloadUri Uri of the download. - * @return the display name of the download. - */ - @CalledByNative - private static String getDisplayName(final String downloadUri) { - ContentResolver resolver = ContextUtils.getApplicationContext().getContentResolver(); - Cursor cursor = null; - try { - cursor = resolver.query(Uri.parse(downloadUri), - new String[] {MediaColumns.DISPLAY_NAME}, null, null, null); - if (cursor == null || cursor.getCount() == 0) return null; - if (cursor.moveToNext()) { - return cursor.getString(cursor.getColumnIndex(MediaColumns.DISPLAY_NAME)); - } - } catch (Exception e) { - Log.e(TAG, "Unable to get display name for download.", e); - } finally { - if (cursor != null) cursor.close(); - } - return null; - } - - @NativeMethods - interface Natives { - int getExpirationDurationInDays(); - } -} diff --git a/chromium/components/download/internal/common/android/java/src/org/chromium/components/download/DownloadDelegate.java b/chromium/components/download/internal/common/android/java/src/org/chromium/components/download/DownloadDelegate.java deleted file mode 100644 index 00a38da9f1d..00000000000 --- a/chromium/components/download/internal/common/android/java/src/org/chromium/components/download/DownloadDelegate.java +++ /dev/null @@ -1,47 +0,0 @@ -// Copyright 2020 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -package org.chromium.components.download; - -import android.net.Uri; - -/** - * Helper class for providering some helper method needed by DownloadCollectionBridge. - */ -public class DownloadDelegate { - public DownloadDelegate() {} - - /** - * If the given MIME type is null, or one of the "generic" types (text/plain - * or application/octet-stream) map it to a type that Android can deal with. - * If the given type is not generic, return it unchanged. - * - * @param mimeType MIME type provided by the server. - * @param url URL of the data being loaded. - * @param filename file name obtained from content disposition header - * @return The MIME type that should be used for this data. - */ - public String remapGenericMimeType(String mimeType, String url, String filename) { - return mimeType; - } - - /** - * Parses an originating URL string and returns a valid Uri that can be inserted into - * DownloadManager. The returned Uri has to be null or non-empty http(s) scheme. - * @param originalUrl String representation of the originating URL. - * @return A valid Uri that can be accepted by DownloadManager. - */ - public Uri parseOriginalUrl(String originalUrl) { - return Uri.parse(originalUrl); - } - - /** - * Returns whether the downloaded file path is on an external SD card. - * @param filePath The download file path. - * @return Whether download is on external sd card. - */ - public boolean isDownloadOnSDCard(String filePath) { - return false; - } -} diff --git a/chromium/components/download/internal/common/download_item_impl.cc b/chromium/components/download/internal/common/download_item_impl.cc index 8a474c493b8..dfe701efa10 100644 --- a/chromium/components/download/internal/common/download_item_impl.cc +++ b/chromium/components/download/internal/common/download_item_impl.cc @@ -1313,24 +1313,10 @@ void DownloadItemImpl::UpdateValidatorsOnResumption( // a full request rather than a partial. Full restarts clobber validators. if (etag_ != new_create_info.etag || last_modified_time_ != new_create_info.last_modified) { - if (destination_info_.received_bytes > 0) { - RecordResumptionRestartCount( - ResumptionRestartCountTypes::kStrongValidatorChangesCount); - } received_slices_.clear(); destination_info_.received_bytes = 0; } - if (destination_info_.received_bytes > 0 && new_create_info.offset == 0) { - if (!base::FeatureList::IsEnabled( - features::kAllowDownloadResumptionWithoutStrongValidators) || - GetDownloadValidationLengthConfig() > - destination_info_.received_bytes) { - RecordResumptionRestartCount( - ResumptionRestartCountTypes::kRequestedByServerCount); - } - } - request_info_.url_chain.insert(request_info_.url_chain.end(), chain_iter, new_create_info.url_chain.end()); etag_ = new_create_info.etag; @@ -2521,10 +2507,6 @@ void DownloadItemImpl::ResumeInterruptedDownload( LOG_IF(ERROR, !GetFullPath().empty()) << "Download full path should be empty before resumption"; if (destination_info_.received_bytes > 0) { - if (!HasStrongValidators()) { - RecordResumptionRestartCount( - ResumptionRestartCountTypes::kMissingStrongValidatorsCount); - } RecordResumptionRestartReason(last_reason_); } destination_info_.received_bytes = 0; diff --git a/chromium/components/download/internal/common/download_response_handler.cc b/chromium/components/download/internal/common/download_response_handler.cc index 35a066fd04c..a14cb9d1808 100644 --- a/chromium/components/download/internal/common/download_response_handler.cc +++ b/chromium/components/download/internal/common/download_response_handler.cc @@ -94,8 +94,6 @@ void DownloadResponseHandler::OnReceiveResponse( cert_status_ = head->cert_status; // TODO(xingliu): Do not use http cache. - // Sets page transition type correctly and call - // |RecordDownloadSourcePageTransitionType| here. if (head->headers) { has_strong_validators_ = head->headers->HasStrongValidators(); RecordDownloadHttpResponseCode(head->headers->response_code(), @@ -243,16 +241,6 @@ void DownloadResponseHandler::OnComplete( ConvertInterruptReasonToMojoNetworkRequestStatus(reason)); } - if (reason == DOWNLOAD_INTERRUPT_REASON_NETWORK_FAILED) { - base::UmaHistogramSparse("Download.MapErrorNetworkFailed.NetworkService", - std::abs(status.error_code)); - if (is_background_mode_) { - base::UmaHistogramSparse( - "Download.MapErrorNetworkFailed.NetworkService.BackgroundDownload", - std::abs(status.error_code)); - } - } - if (started_) { delegate_->OnResponseCompleted(); return; diff --git a/chromium/components/download/internal/common/download_stats.cc b/chromium/components/download/internal/common/download_stats.cc index db9e8099e4d..338fc892817 100644 --- a/chromium/components/download/internal/common/download_stats.cc +++ b/chromium/components/download/internal/common/download_stats.cc @@ -650,7 +650,6 @@ void RecordParallelizableDownloadStats( if (!uses_parallel_requests) return; - base::TimeDelta time_saved; if (bytes_downloaded_with_parallel_streams > 0) { int64_t bandwidth_with_parallel_streams = CalculateBandwidthBytesPerSecond( bytes_downloaded_with_parallel_streams, time_with_parallel_streams); @@ -658,20 +657,6 @@ void RecordParallelizableDownloadStats( "Download.ParallelizableDownloadBandwidth." "WithParallelRequestsMultipleStreams", bandwidth_with_parallel_streams); - if (bandwidth_without_parallel_streams > 0) { - time_saved = base::TimeDelta::FromMilliseconds( - 1000.0 * bytes_downloaded_with_parallel_streams / - bandwidth_without_parallel_streams) - - time_with_parallel_streams; - } - } - - int kMillisecondsPerHour = - base::checked_cast<int>(base::Time::kMillisecondsPerSecond * 60 * 60); - if (time_saved >= base::TimeDelta()) { - UMA_HISTOGRAM_CUSTOM_COUNTS( - "Download.EstimatedTimeSavedWithParallelDownload", - time_saved.InMilliseconds(), 0, kMillisecondsPerHour, 50); } } @@ -751,17 +736,6 @@ void RecordDownloadValidationMetrics(DownloadMetricsCallsite callsite, DownloadContent::MAX); } -void RecordDownloadSourcePageTransitionType( - const base::Optional<ui::PageTransition>& page_transition) { - if (!page_transition) - return; - - UMA_HISTOGRAM_ENUMERATION( - "Download.PageTransition", - ui::PageTransitionStripQualifier(page_transition.value()), - ui::PAGE_TRANSITION_LAST_CORE + 1); -} - void RecordDownloadHttpResponseCode(int response_code, bool is_background_mode) { int status_code = net::HttpUtil::MapStatusCodeForHistogram(response_code); @@ -788,10 +762,6 @@ void RecordResumptionRestartReason(DownloadInterruptReason reason) { base::UmaHistogramSparse("Download.ResumptionRestart.Reason", reason); } -void RecordResumptionRestartCount(ResumptionRestartCountTypes type) { - base::UmaHistogramEnumeration("Download.ResumptionRestart.Counts", type); -} - void RecordDownloadManagerCreationTimeSinceStartup( base::TimeDelta elapsed_time) { base::UmaHistogramLongTimes("Download.DownloadManager.CreationDelay", diff --git a/chromium/components/download/network/android/java/src/org/chromium/components/download/NetworkStatusListenerAndroid.java b/chromium/components/download/network/android/java/src/org/chromium/components/download/NetworkStatusListenerAndroid.java deleted file mode 100644 index 03df09fa971..00000000000 --- a/chromium/components/download/network/android/java/src/org/chromium/components/download/NetworkStatusListenerAndroid.java +++ /dev/null @@ -1,98 +0,0 @@ -// Copyright 2017 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -package org.chromium.components.download; - -import androidx.annotation.VisibleForTesting; - -import org.chromium.base.annotations.CalledByNative; -import org.chromium.base.annotations.JNINamespace; -import org.chromium.base.annotations.NativeMethods; -import org.chromium.net.NetworkChangeNotifierAutoDetect; -import org.chromium.net.NetworkChangeNotifierAutoDetect.Observer; -import org.chromium.net.RegistrationPolicyAlwaysRegister; - -/** - * Network listener that can notify network connectivity changes to native side - * download::NetworkStatusListenerAndroid even when the Android application is in the background. - * - * The class is created and owned by native side, and lives and propagate network change events - * on the UI thread. - */ -@JNINamespace("download") -public final class NetworkStatusListenerAndroid implements Observer { - private long mNativePtr; - private final NetworkChangeNotifierAutoDetect mNotifier; - private static AutoDetectFactory sAutoDetectFactory = new AutoDetectFactory(); - - @VisibleForTesting - public static void setAutoDetectFactory(AutoDetectFactory factory) { - sAutoDetectFactory = factory; - } - - @CalledByNative - private int getCurrentConnectionType() { - assert mNotifier != null; - return mNotifier.getCurrentNetworkState().getConnectionType(); - } - - private NetworkStatusListenerAndroid(long nativePtr) { - mNativePtr = nativePtr; - // Register policy that can fire network change events when the application is in the - // background. - mNotifier = sAutoDetectFactory.create(this, new RegistrationPolicyAlwaysRegister()); - } - - @CalledByNative - private void clearNativePtr() { - mNotifier.unregister(); - mNativePtr = 0; - } - - @CalledByNative - private static NetworkStatusListenerAndroid create(long nativePtr) { - return new NetworkStatusListenerAndroid(nativePtr); - } - - /** - * {@link NetworkChangeNotifierAutoDetect.Observer} implementation. - */ - @Override - public void onConnectionTypeChanged(int newConnectionType) { - if (mNativePtr != 0) { - NetworkStatusListenerAndroidJni.get().notifyNetworkChange( - mNativePtr, NetworkStatusListenerAndroid.this, newConnectionType); - } - } - - /** - * Creates the NetworkChangeNotifierAutoDetect used in this class. Included so that tests - * can override it. - */ - @VisibleForTesting - public static class AutoDetectFactory { - public NetworkChangeNotifierAutoDetect create( - NetworkChangeNotifierAutoDetect.Observer observer, - NetworkChangeNotifierAutoDetect.RegistrationPolicy policy) { - return new NetworkChangeNotifierAutoDetect(observer, policy); - } - } - - @Override - public void onConnectionSubtypeChanged(int newConnectionSubtype) {} - @Override - public void onNetworkConnect(long netId, int connectionType) {} - @Override - public void onNetworkSoonToDisconnect(long netId) {} - @Override - public void onNetworkDisconnect(long netId) {} - @Override - public void purgeActiveNetworkList(long[] activeNetIds) {} - - @NativeMethods - interface Natives { - void notifyNetworkChange(long nativeNetworkStatusListenerAndroid, - NetworkStatusListenerAndroid caller, int connectionType); - } -} diff --git a/chromium/components/download/public/common/BUILD.gn b/chromium/components/download/public/common/BUILD.gn index e8edc1a31cd..4e1469be24f 100644 --- a/chromium/components/download/public/common/BUILD.gn +++ b/chromium/components/download/public/common/BUILD.gn @@ -108,6 +108,7 @@ if (is_android) { deps = [ "//base:base_java", + "//components/download/internal/common:internal_java", "//third_party/android_deps:androidx_annotation_annotation_java", ] } diff --git a/chromium/components/download/public/common/download_features.cc b/chromium/components/download/public/common/download_features.cc index 41ec09e2715..38ed21f0d74 100644 --- a/chromium/components/download/public/common/download_features.cc +++ b/chromium/components/download/public/common/download_features.cc @@ -34,6 +34,9 @@ const base::Feature kDownloadLater{"DownloadLater", base::FEATURE_DISABLED_BY_DEFAULT}; #if defined(OS_ANDROID) +const base::Feature kSmartSuggestionForLargeDownloads{ + "SmartSuggestionForLargeDownloads", base::FEATURE_DISABLED_BY_DEFAULT}; + const base::Feature kRefreshExpirationDate{"RefreshExpirationDate", base::FEATURE_ENABLED_BY_DEFAULT}; #endif diff --git a/chromium/components/download/public/common/download_features.h b/chromium/components/download/public/common/download_features.h index 55a1097789e..1a29aabae05 100644 --- a/chromium/components/download/public/common/download_features.h +++ b/chromium/components/download/public/common/download_features.h @@ -16,6 +16,10 @@ namespace features { // network. constexpr char kDownloadLaterRequireCellular[] = "require_cellular"; +// The Finch parameter for download later feature to enable only in lite +// mode(data saver). +constexpr char kDownloadLaterRequireLiteMode[] = "require_lite_mode"; + // Whether offline content provider should be used for the downloads UI.. COMPONENTS_DOWNLOAD_EXPORT extern const base::Feature kUseDownloadOfflineContentProvider; @@ -33,6 +37,10 @@ COMPONENTS_DOWNLOAD_EXPORT extern const base::Feature kDownloadLater; #if defined(OS_ANDROID) // Whether download expiration date will be refreshed on resumption. COMPONENTS_DOWNLOAD_EXPORT extern const base::Feature kRefreshExpirationDate; + +// Whether to enable smart suggestion for large downloads +COMPONENTS_DOWNLOAD_EXPORT extern const base::Feature + kSmartSuggestionForLargeDownloads; #endif // Whether in-progress download manager will be used to initialize download diff --git a/chromium/components/download/public/common/download_stats.h b/chromium/components/download/public/common/download_stats.h index dc25996957c..3c7f34ef01a 100644 --- a/chromium/components/download/public/common/download_stats.h +++ b/chromium/components/download/public/common/download_stats.h @@ -14,7 +14,6 @@ #include <vector> #include "base/callback.h" -#include "base/optional.h" #include "build/build_config.h" #include "components/download/public/common/download_content.h" #include "components/download/public/common/download_danger_type.h" @@ -23,7 +22,6 @@ #include "components/download/public/common/download_source.h" #include "net/base/network_change_notifier.h" #include "net/http/http_response_info.h" -#include "ui/base/page_transition_types.h" #include "url/gurl.h" namespace base { @@ -220,21 +218,6 @@ enum class ParallelDownloadCreationEvent { COUNT, }; -// Reason for download to restart during resumption. These enum values are -// persisted to logs, and should therefore never be renumbered nor removed. -enum class ResumptionRestartCountTypes { - // The download is restarted due to server response. - kRequestedByServerCount = 0, - - // Strong validator changes. - kStrongValidatorChangesCount = 1, - - // No strong validators are present. - kMissingStrongValidatorsCount = 2, - - kMaxValue = kMissingStrongValidatorsCount -}; - // Events for user scheduled downloads. Used in histograms, don't reuse or // remove items. Keep in sync with DownloadLaterEvent in enums.xml. enum class DownloadLaterEvent { @@ -429,9 +412,6 @@ COMPONENTS_DOWNLOAD_EXPORT void RecordDownloadConnectionSecurity( const GURL& download_url, const std::vector<GURL>& url_chain); -COMPONENTS_DOWNLOAD_EXPORT void RecordDownloadSourcePageTransitionType( - const base::Optional<ui::PageTransition>& transition); - COMPONENTS_DOWNLOAD_EXPORT void RecordDownloadHttpResponseCode( int response_code, bool is_background_mode); @@ -450,9 +430,6 @@ COMPONENTS_DOWNLOAD_EXPORT void RecordResumptionRestartReason( COMPONENTS_DOWNLOAD_EXPORT void RecordResumptionStrongValidators( DownloadInterruptReason reason); -COMPONENTS_DOWNLOAD_EXPORT void RecordResumptionRestartCount( - ResumptionRestartCountTypes type); - COMPONENTS_DOWNLOAD_EXPORT void RecordDownloadManagerCreationTimeSinceStartup( base::TimeDelta elapsed_time); |