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 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
43 import org.chromium.chrome.browser.download.ui.DownloadHistoryItemWrapper; | 43 import org.chromium.chrome.browser.download.ui.DownloadHistoryItemWrapper; |
44 import org.chromium.chrome.browser.feature_engagement_tracker.FeatureEngagementT
rackerFactory; | 44 import org.chromium.chrome.browser.feature_engagement_tracker.FeatureEngagementT
rackerFactory; |
45 import org.chromium.chrome.browser.offlinepages.DownloadUiActionFlags; | 45 import org.chromium.chrome.browser.offlinepages.DownloadUiActionFlags; |
46 import org.chromium.chrome.browser.offlinepages.OfflinePageBridge; | 46 import org.chromium.chrome.browser.offlinepages.OfflinePageBridge; |
47 import org.chromium.chrome.browser.offlinepages.OfflinePageUtils; | 47 import org.chromium.chrome.browser.offlinepages.OfflinePageUtils; |
48 import org.chromium.chrome.browser.offlinepages.downloads.OfflinePageDownloadBri
dge; | 48 import org.chromium.chrome.browser.offlinepages.downloads.OfflinePageDownloadBri
dge; |
49 import org.chromium.chrome.browser.profiles.Profile; | 49 import org.chromium.chrome.browser.profiles.Profile; |
50 import org.chromium.chrome.browser.tab.Tab; | 50 import org.chromium.chrome.browser.tab.Tab; |
51 import org.chromium.chrome.browser.tabmodel.TabModel.TabLaunchType; | 51 import org.chromium.chrome.browser.tabmodel.TabModel.TabLaunchType; |
52 import org.chromium.chrome.browser.tabmodel.document.TabDelegate; | 52 import org.chromium.chrome.browser.tabmodel.document.TabDelegate; |
| 53 import org.chromium.chrome.browser.util.ConversionUtils; |
53 import org.chromium.chrome.browser.util.IntentUtils; | 54 import org.chromium.chrome.browser.util.IntentUtils; |
54 import org.chromium.components.feature_engagement_tracker.EventConstants; | 55 import org.chromium.components.feature_engagement_tracker.EventConstants; |
55 import org.chromium.components.feature_engagement_tracker.FeatureEngagementTrack
er; | 56 import org.chromium.components.feature_engagement_tracker.FeatureEngagementTrack
er; |
56 import org.chromium.components.offline_items_collection.OfflineItem.Progress; | 57 import org.chromium.components.offline_items_collection.OfflineItem.Progress; |
57 import org.chromium.components.offline_items_collection.OfflineItemProgressUnit; | 58 import org.chromium.components.offline_items_collection.OfflineItemProgressUnit; |
58 import org.chromium.content.browser.BrowserStartupController; | 59 import org.chromium.content.browser.BrowserStartupController; |
59 import org.chromium.content_public.browser.DownloadState; | 60 import org.chromium.content_public.browser.DownloadState; |
60 import org.chromium.content_public.browser.LoadUrlParams; | 61 import org.chromium.content_public.browser.LoadUrlParams; |
61 import org.chromium.ui.base.DeviceFormFactor; | 62 import org.chromium.ui.base.DeviceFormFactor; |
62 import org.chromium.ui.widget.Toast; | 63 import org.chromium.ui.widget.Toast; |
(...skipping 24 matching lines...) Expand all 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 (ConversionUtils.bytesToMegabytes(bytes) < 1) { |
773 resourceId = stringSet[0]; | 770 resourceId = stringSet[0]; |
774 bytesInCorrectUnits = bytes / (float) BYTES_PER_KILOBYTE; | 771 bytesInCorrectUnits = bytes / (float) ConversionUtils.BYTES_PER_KILO
BYTE; |
775 } else if (bytes < BYTES_PER_GIGABYTE) { | 772 } else if (ConversionUtils.bytesToGigabytes(bytes) < 1) { |
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 |