Commit 82ecc71c authored by dtrainor's avatar dtrainor Committed by Commit bot

Remove the GUID requirement from the ContentId

In Java persisting the ContentId required it to be a guid.  This removes
that dependency.  Note that legacy downloads still have their own checks
for requiring the id to be a guid, but if the download isn't associated
with a legacy download the checks should not occur.

BUG=691805

Review-Url: https://codereview.chromium.org/2843073002
Cr-Commit-Position: refs/heads/master@{#467929}
parent 56f4702d
...@@ -1016,7 +1016,7 @@ public class DownloadNotificationService extends Service { ...@@ -1016,7 +1016,7 @@ public class DownloadNotificationService extends Service {
/** /**
* Add a download failed notification. * Add a download failed notification.
* @param id The {@link ContentId} of the download. * @param id The {@link ContentId} of the download.
* @param fileName GUID of the download. * @param fileName Filename of the download.
* @param icon A {@link Bitmap} to be used as the large icon for display. * @param icon A {@link Bitmap} to be used as the large icon for display.
*/ */
@VisibleForTesting @VisibleForTesting
...@@ -1354,7 +1354,7 @@ public class DownloadNotificationService extends Service { ...@@ -1354,7 +1354,7 @@ public class DownloadNotificationService extends Service {
} }
ContentId id = getContentIdFromIntent(intent); ContentId id = getContentIdFromIntent(intent);
if (id == null || !DownloadSharedPreferenceEntry.isValidGUID(id.id)) return false; if (id == null) return false;
return true; return true;
} }
......
...@@ -265,12 +265,12 @@ public class DownloadSharedPreferenceEntry { ...@@ -265,12 +265,12 @@ public class DownloadSharedPreferenceEntry {
static DownloadSharedPreferenceEntry parseFromVersion6(String string) { static DownloadSharedPreferenceEntry parseFromVersion6(String string) {
String[] entries = string.split(",", 9); String[] entries = string.split(",", 9);
if (entries.length != 9) return INVALID_ENTRY; if (entries.length != 9) return INVALID_ENTRY;
// VERSION,NOTIFICATIONID,NAMESPACE,GUID,OFFTHERECORD,METEREDOK,AUTORESUMEOK,ISTRANSIENT, // VERSION,NOTIFICATIONID,NAMESPACE,ID,OFFTHERECORD,METEREDOK,AUTORESUMEOK,ISTRANSIENT,
// FILENAME // FILENAME
String stringVersion = entries[0]; String stringVersion = entries[0];
String stringNotificationId = entries[1]; String stringNotificationId = entries[1];
String stringNamespace = entries[2]; String stringNamespace = entries[2];
String stringGuid = entries[3]; String stringId = entries[3];
String stringOffTheRecord = entries[4]; String stringOffTheRecord = entries[4];
String stringMetered = entries[5]; String stringMetered = entries[5];
String stringAutoResume = entries[6]; String stringAutoResume = entries[6];
...@@ -291,10 +291,10 @@ public class DownloadSharedPreferenceEntry { ...@@ -291,10 +291,10 @@ public class DownloadSharedPreferenceEntry {
} }
if (version != 6) return INVALID_ENTRY; if (version != 6) return INVALID_ENTRY;
if (!isValidGUID(stringGuid)) return INVALID_ENTRY; if (TextUtils.isEmpty(stringId)) return INVALID_ENTRY;
if (TextUtils.isEmpty(stringNamespace)) return INVALID_ENTRY; if (TextUtils.isEmpty(stringNamespace)) return INVALID_ENTRY;
return new DownloadSharedPreferenceEntry(new ContentId(stringNamespace, stringGuid), return new DownloadSharedPreferenceEntry(new ContentId(stringNamespace, stringId),
notificationId, offTheRecord, metered, stringFileName, autoResume, isTransient); notificationId, offTheRecord, metered, stringFileName, autoResume, isTransient);
} }
......
...@@ -220,23 +220,23 @@ public class DownloadSharedPreferenceEntryTest { ...@@ -220,23 +220,23 @@ public class DownloadSharedPreferenceEntryTest {
@Test @Test
@Feature({"Download"}) @Feature({"Download"})
public void testParseFromStringVersion6() { public void testParseFromStringVersion6() {
String uuid = newUUID(); String id1 = newUUID();
String notificationString = "6,2,test_namespace," + uuid + ",0,1,1,1,test,2.pdf"; String notificationString = "6,2,test_namespace," + id1 + ",0,1,1,1,test,2.pdf";
DownloadSharedPreferenceEntry entry = DownloadSharedPreferenceEntry entry =
DownloadSharedPreferenceEntry.parseFromString(notificationString); DownloadSharedPreferenceEntry.parseFromString(notificationString);
assertEquals(2, entry.notificationId); assertEquals(2, entry.notificationId);
assertEquals(new ContentId("test_namespace", uuid), entry.id); assertEquals(new ContentId("test_namespace", id1), entry.id);
assertFalse(entry.isOffTheRecord); assertFalse(entry.isOffTheRecord);
assertTrue(entry.canDownloadWhileMetered); assertTrue(entry.canDownloadWhileMetered);
assertTrue(entry.isAutoResumable); assertTrue(entry.isAutoResumable);
assertTrue(entry.isTransient); assertTrue(entry.isTransient);
assertEquals("test,2.pdf", entry.fileName); assertEquals("test,2.pdf", entry.fileName);
String uuid2 = newUUID(); String id2 = "notaguidhurray";
notificationString = "6,3,test_namespace," + uuid + ",1,0,0,0,test,4.pdf"; notificationString = "6,3,test_namespace," + id2 + ",1,0,0,0,test,4.pdf";
entry = DownloadSharedPreferenceEntry.parseFromString(notificationString); entry = DownloadSharedPreferenceEntry.parseFromString(notificationString);
assertEquals(3, entry.notificationId); assertEquals(3, entry.notificationId);
assertEquals(new ContentId("test_namespace", uuid), entry.id); assertEquals(new ContentId("test_namespace", id2), entry.id);
assertTrue(entry.isOffTheRecord); assertTrue(entry.isOffTheRecord);
assertFalse(entry.canDownloadWhileMetered); assertFalse(entry.canDownloadWhileMetered);
assertFalse(entry.isAutoResumable); assertFalse(entry.isAutoResumable);
...@@ -475,10 +475,16 @@ public class DownloadSharedPreferenceEntryTest { ...@@ -475,10 +475,16 @@ public class DownloadSharedPreferenceEntryTest {
entry = DownloadSharedPreferenceEntry.parseFromString(notificationString); entry = DownloadSharedPreferenceEntry.parseFromString(notificationString);
assertEquals(DownloadSharedPreferenceEntry.INVALID_ENTRY, entry); assertEquals(DownloadSharedPreferenceEntry.INVALID_ENTRY, entry);
// Not able to parse GUID in version 6. // Able to load an invalid GUID in version 6.
notificationString = "6,2,test_namespace,xxx,0,1,1,1,test,2.pdf"; notificationString = "6,2,test_namespace,xxx,0,1,1,1,test,2.pdf";
entry = DownloadSharedPreferenceEntry.parseFromString(notificationString); entry = DownloadSharedPreferenceEntry.parseFromString(notificationString);
assertEquals(DownloadSharedPreferenceEntry.INVALID_ENTRY, entry); assertEquals(2, entry.notificationId);
assertEquals(new ContentId("test_namespace", "xxx"), entry.id);
assertFalse(entry.isOffTheRecord);
assertTrue(entry.canDownloadWhileMetered);
assertTrue(entry.isAutoResumable);
assertTrue(entry.isTransient);
assertEquals("test,2.pdf", entry.fileName);
} }
@Test @Test
......
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