| 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.text.TextUtils; | 7 import android.text.TextUtils; |
| 8 | 8 |
| 9 import org.chromium.base.Log; | 9 import org.chromium.base.Log; |
| 10 import org.chromium.base.VisibleForTesting; | 10 import org.chromium.base.VisibleForTesting; |
| (...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 258 if (!isValidGUID(stringGuid)) return INVALID_ENTRY; | 258 if (!isValidGUID(stringGuid)) return INVALID_ENTRY; |
| 259 if (TextUtils.isEmpty(stringNamespace)) return INVALID_ENTRY; | 259 if (TextUtils.isEmpty(stringNamespace)) return INVALID_ENTRY; |
| 260 | 260 |
| 261 return new DownloadSharedPreferenceEntry(new ContentId(stringNamespace,
stringGuid), | 261 return new DownloadSharedPreferenceEntry(new ContentId(stringNamespace,
stringGuid), |
| 262 notificationId, offTheRecord, metered, stringFileName, autoResum
e, false); | 262 notificationId, offTheRecord, metered, stringFileName, autoResum
e, false); |
| 263 } | 263 } |
| 264 | 264 |
| 265 static DownloadSharedPreferenceEntry parseFromVersion6(String string) { | 265 static DownloadSharedPreferenceEntry parseFromVersion6(String string) { |
| 266 String[] entries = string.split(",", 9); | 266 String[] entries = string.split(",", 9); |
| 267 if (entries.length != 9) return INVALID_ENTRY; | 267 if (entries.length != 9) return INVALID_ENTRY; |
| 268 // VERSION,NOTIFICATIONID,NAMESPACE,GUID,OFFTHERECORD,METEREDOK,AUTORESU
MEOK,ISTRANSIENT, | 268 // VERSION,NOTIFICATIONID,NAMESPACE,ID,OFFTHERECORD,METEREDOK,AUTORESUME
OK,ISTRANSIENT, |
| 269 // FILENAME | 269 // FILENAME |
| 270 String stringVersion = entries[0]; | 270 String stringVersion = entries[0]; |
| 271 String stringNotificationId = entries[1]; | 271 String stringNotificationId = entries[1]; |
| 272 String stringNamespace = entries[2]; | 272 String stringNamespace = entries[2]; |
| 273 String stringGuid = entries[3]; | 273 String stringId = entries[3]; |
| 274 String stringOffTheRecord = entries[4]; | 274 String stringOffTheRecord = entries[4]; |
| 275 String stringMetered = entries[5]; | 275 String stringMetered = entries[5]; |
| 276 String stringAutoResume = entries[6]; | 276 String stringAutoResume = entries[6]; |
| 277 String stringTransient = entries[7]; | 277 String stringTransient = entries[7]; |
| 278 String stringFileName = entries[8]; | 278 String stringFileName = entries[8]; |
| 279 | 279 |
| 280 boolean offTheRecord = "1".equals(stringOffTheRecord); | 280 boolean offTheRecord = "1".equals(stringOffTheRecord); |
| 281 boolean metered = "1".equals(stringMetered); | 281 boolean metered = "1".equals(stringMetered); |
| 282 boolean autoResume = "1".equals(stringAutoResume); | 282 boolean autoResume = "1".equals(stringAutoResume); |
| 283 boolean isTransient = "1".equals(stringTransient); | 283 boolean isTransient = "1".equals(stringTransient); |
| 284 int version; | 284 int version; |
| 285 int notificationId; | 285 int notificationId; |
| 286 try { | 286 try { |
| 287 version = Integer.parseInt(stringVersion); | 287 version = Integer.parseInt(stringVersion); |
| 288 notificationId = Integer.parseInt(stringNotificationId); | 288 notificationId = Integer.parseInt(stringNotificationId); |
| 289 } catch (NumberFormatException ex) { | 289 } catch (NumberFormatException ex) { |
| 290 return INVALID_ENTRY; | 290 return INVALID_ENTRY; |
| 291 } | 291 } |
| 292 | 292 |
| 293 if (version != 6) return INVALID_ENTRY; | 293 if (version != 6) return INVALID_ENTRY; |
| 294 if (!isValidGUID(stringGuid)) return INVALID_ENTRY; | 294 if (TextUtils.isEmpty(stringId)) return INVALID_ENTRY; |
| 295 if (TextUtils.isEmpty(stringNamespace)) return INVALID_ENTRY; | 295 if (TextUtils.isEmpty(stringNamespace)) return INVALID_ENTRY; |
| 296 | 296 |
| 297 return new DownloadSharedPreferenceEntry(new ContentId(stringNamespace,
stringGuid), | 297 return new DownloadSharedPreferenceEntry(new ContentId(stringNamespace,
stringId), |
| 298 notificationId, offTheRecord, metered, stringFileName, autoResum
e, isTransient); | 298 notificationId, offTheRecord, metered, stringFileName, autoResum
e, isTransient); |
| 299 } | 299 } |
| 300 | 300 |
| 301 /** | 301 /** |
| 302 * @return a string for the DownloadSharedPreferenceEntry instance to be ins
erted into | 302 * @return a string for the DownloadSharedPreferenceEntry instance to be ins
erted into |
| 303 * SharedPrefs. | 303 * SharedPrefs. |
| 304 */ | 304 */ |
| 305 String getSharedPreferenceString() { | 305 String getSharedPreferenceString() { |
| 306 String serialized = ""; | 306 String serialized = ""; |
| 307 serialized += VERSION + ","; | 307 serialized += VERSION + ","; |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 371 hash = 37 * hash + (isOffTheRecord ? 1 : 0); | 371 hash = 37 * hash + (isOffTheRecord ? 1 : 0); |
| 372 hash = 37 * hash + (canDownloadWhileMetered ? 1 : 0); | 372 hash = 37 * hash + (canDownloadWhileMetered ? 1 : 0); |
| 373 hash = 37 * hash + (isAutoResumable ? 1 : 0); | 373 hash = 37 * hash + (isAutoResumable ? 1 : 0); |
| 374 hash = 37 * hash + notificationId; | 374 hash = 37 * hash + notificationId; |
| 375 hash = 37 * hash + id.hashCode(); | 375 hash = 37 * hash + id.hashCode(); |
| 376 hash = 37 * hash + fileName.hashCode(); | 376 hash = 37 * hash + fileName.hashCode(); |
| 377 hash = 37 * hash + (isTransient ? 1 : 0); | 377 hash = 37 * hash + (isTransient ? 1 : 0); |
| 378 return hash; | 378 return hash; |
| 379 } | 379 } |
| 380 } | 380 } |
| OLD | NEW |