Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 package org.chromium.chrome.browser.download; | 5 package org.chromium.chrome.browser.download; |
| 6 | 6 |
| 7 import android.app.Activity; | 7 import android.app.Activity; |
| 8 import android.app.PendingIntent; | 8 import android.app.PendingIntent; |
| 9 import android.content.ActivityNotFoundException; | 9 import android.content.ActivityNotFoundException; |
| 10 import android.content.Context; | 10 import android.content.Context; |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 26 import org.chromium.base.ContextUtils; | 26 import org.chromium.base.ContextUtils; |
| 27 import org.chromium.base.FileUtils; | 27 import org.chromium.base.FileUtils; |
| 28 import org.chromium.base.Log; | 28 import org.chromium.base.Log; |
| 29 import org.chromium.base.VisibleForTesting; | 29 import org.chromium.base.VisibleForTesting; |
| 30 import org.chromium.base.library_loader.LibraryProcessType; | 30 import org.chromium.base.library_loader.LibraryProcessType; |
| 31 import org.chromium.base.metrics.RecordHistogram; | 31 import org.chromium.base.metrics.RecordHistogram; |
| 32 import org.chromium.base.metrics.RecordUserAction; | 32 import org.chromium.base.metrics.RecordUserAction; |
| 33 import org.chromium.chrome.R; | 33 import org.chromium.chrome.R; |
| 34 import org.chromium.chrome.browser.ChromeActivity; | 34 import org.chromium.chrome.browser.ChromeActivity; |
| 35 import org.chromium.chrome.browser.ChromeTabbedActivity; | 35 import org.chromium.chrome.browser.ChromeTabbedActivity; |
| 36 import org.chromium.chrome.browser.ConversionUtils; | |
| 36 import org.chromium.chrome.browser.IntentHandler; | 37 import org.chromium.chrome.browser.IntentHandler; |
| 37 import org.chromium.chrome.browser.UrlConstants; | 38 import org.chromium.chrome.browser.UrlConstants; |
| 38 import org.chromium.chrome.browser.customtabs.CustomTabIntentDataProvider; | 39 import org.chromium.chrome.browser.customtabs.CustomTabIntentDataProvider; |
| 39 import org.chromium.chrome.browser.document.ChromeLauncherActivity; | 40 import org.chromium.chrome.browser.document.ChromeLauncherActivity; |
| 40 import org.chromium.chrome.browser.download.ui.BackendProvider; | 41 import org.chromium.chrome.browser.download.ui.BackendProvider; |
| 41 import org.chromium.chrome.browser.download.ui.BackendProvider.DownloadDelegate; | 42 import org.chromium.chrome.browser.download.ui.BackendProvider.DownloadDelegate; |
| 42 import org.chromium.chrome.browser.download.ui.DownloadFilter; | 43 import org.chromium.chrome.browser.download.ui.DownloadFilter; |
| 43 import org.chromium.chrome.browser.download.ui.DownloadHistoryItemWrapper; | 44 import org.chromium.chrome.browser.download.ui.DownloadHistoryItemWrapper; |
| 44 import org.chromium.chrome.browser.feature_engagement_tracker.FeatureEngagementT rackerFactory; | 45 import org.chromium.chrome.browser.feature_engagement_tracker.FeatureEngagementT rackerFactory; |
| 45 import org.chromium.chrome.browser.offlinepages.DownloadUiActionFlags; | 46 import org.chromium.chrome.browser.offlinepages.DownloadUiActionFlags; |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 87 | 88 |
| 88 private static final String TAG = "download"; | 89 private static final String TAG = "download"; |
| 89 | 90 |
| 90 private static final String DEFAULT_MIME_TYPE = "*/*"; | 91 private static final String DEFAULT_MIME_TYPE = "*/*"; |
| 91 private static final String MIME_TYPE_DELIMITER = "/"; | 92 private static final String MIME_TYPE_DELIMITER = "/"; |
| 92 private static final String MIME_TYPE_VIDEO = "video"; | 93 private static final String MIME_TYPE_VIDEO = "video"; |
| 93 | 94 |
| 94 private static final String EXTRA_IS_OFF_THE_RECORD = | 95 private static final String EXTRA_IS_OFF_THE_RECORD = |
| 95 "org.chromium.chrome.browser.download.IS_OFF_THE_RECORD"; | 96 "org.chromium.chrome.browser.download.IS_OFF_THE_RECORD"; |
| 96 | 97 |
| 97 private static final long BYTES_PER_KILOBYTE = 1024; | |
| 98 private static final long BYTES_PER_MEGABYTE = 1024 * 1024; | |
| 99 private static final long BYTES_PER_GIGABYTE = 1024 * 1024 * 1024; | |
| 100 | |
| 101 @VisibleForTesting | 98 @VisibleForTesting |
| 102 static final long SECONDS_PER_MINUTE = TimeUnit.MINUTES.toSeconds(1); | 99 static final long SECONDS_PER_MINUTE = TimeUnit.MINUTES.toSeconds(1); |
| 103 @VisibleForTesting | 100 @VisibleForTesting |
| 104 static final long SECONDS_PER_HOUR = TimeUnit.HOURS.toSeconds(1); | 101 static final long SECONDS_PER_HOUR = TimeUnit.HOURS.toSeconds(1); |
| 105 @VisibleForTesting | 102 @VisibleForTesting |
| 106 static final long SECONDS_PER_DAY = TimeUnit.DAYS.toSeconds(1); | 103 static final long SECONDS_PER_DAY = TimeUnit.DAYS.toSeconds(1); |
| 107 | 104 |
| 108 @VisibleForTesting | 105 @VisibleForTesting |
| 109 static final String ELLIPSIS = "\u2026"; | 106 static final String ELLIPSIS = "\u2026"; |
| 110 | 107 |
| (...skipping 651 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 762 * resource. | 759 * resource. |
| 763 * @param context Context to use. | 760 * @param context Context to use. |
| 764 * @param stringSet The string resources for displaying bytes in KB, MB and GB. | 761 * @param stringSet The string resources for displaying bytes in KB, MB and GB. |
| 765 * @param bytes Number of bytes. | 762 * @param bytes Number of bytes. |
| 766 * @return A formatted string to be displayed. | 763 * @return A formatted string to be displayed. |
| 767 */ | 764 */ |
| 768 public static String getStringForBytes(Context context, int[] stringSet, lon g bytes) { | 765 public static String getStringForBytes(Context context, int[] stringSet, lon g bytes) { |
| 769 int resourceId; | 766 int resourceId; |
| 770 float bytesInCorrectUnits; | 767 float bytesInCorrectUnits; |
| 771 | 768 |
| 772 if (bytes < BYTES_PER_MEGABYTE) { | 769 if (bytes < ConversionUtils.BYTES_PER_MEGABYTE) { |
| 773 resourceId = stringSet[0]; | 770 resourceId = stringSet[0]; |
| 774 bytesInCorrectUnits = bytes / (float) BYTES_PER_KILOBYTE; | 771 bytesInCorrectUnits = bytes / (float) ConversionUtils.BYTES_PER_KILO BYTE; |
|
Theresa
2017/06/02 15:40:22
Let's have ConversionUtils expose methods for #byt
Ted C
2017/06/02 16:16:40
Agreed
| |
| 775 } else if (bytes < BYTES_PER_GIGABYTE) { | 772 } else if (bytes < ConversionUtils.BYTES_PER_GIGABYTE) { |
| 776 resourceId = stringSet[1]; | 773 resourceId = stringSet[1]; |
| 777 bytesInCorrectUnits = bytes / (float) BYTES_PER_MEGABYTE; | 774 bytesInCorrectUnits = bytes / (float) ConversionUtils.BYTES_PER_MEGA BYTE; |
| 778 } else { | 775 } else { |
| 779 resourceId = stringSet[2]; | 776 resourceId = stringSet[2]; |
| 780 bytesInCorrectUnits = bytes / (float) BYTES_PER_GIGABYTE; | 777 bytesInCorrectUnits = bytes / (float) ConversionUtils.BYTES_PER_GIGA BYTE; |
| 781 } | 778 } |
| 782 | 779 |
| 783 return context.getResources().getString(resourceId, bytesInCorrectUnits) ; | 780 return context.getResources().getString(resourceId, bytesInCorrectUnits) ; |
| 784 } | 781 } |
| 785 | 782 |
| 786 /** | 783 /** |
| 787 * Abbreviate a file name into a given number of characters with ellipses. | 784 * Abbreviate a file name into a given number of characters with ellipses. |
| 788 * e.g. "thisisaverylongfilename.txt" => "thisisave....txt". | 785 * e.g. "thisisaverylongfilename.txt" => "thisisave....txt". |
| 789 * @param fileName File name to abbreviate. | 786 * @param fileName File name to abbreviate. |
| 790 * @param limit Character limit. | 787 * @param limit Character limit. |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 880 public static Date getDateAtMidnight(long timestamp) { | 877 public static Date getDateAtMidnight(long timestamp) { |
| 881 Calendar cal = Calendar.getInstance(); | 878 Calendar cal = Calendar.getInstance(); |
| 882 cal.setTimeInMillis(timestamp); | 879 cal.setTimeInMillis(timestamp); |
| 883 cal.set(Calendar.HOUR_OF_DAY, 0); | 880 cal.set(Calendar.HOUR_OF_DAY, 0); |
| 884 cal.set(Calendar.MINUTE, 0); | 881 cal.set(Calendar.MINUTE, 0); |
| 885 cal.set(Calendar.SECOND, 0); | 882 cal.set(Calendar.SECOND, 0); |
| 886 cal.set(Calendar.MILLISECOND, 0); | 883 cal.set(Calendar.MILLISECOND, 0); |
| 887 return cal.getTime(); | 884 return cal.getTime(); |
| 888 } | 885 } |
| 889 } | 886 } |
| OLD | NEW |