Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(763)

Unified Diff: components/offline_items_collection/core/android/java/src/org/chromium/components/offline_items_collection/LegacyHelpers.java

Issue 2768953002: Initial work to move downloads to ContentIds (Closed)
Patch Set: Rebase because of a conflict... with a single. import. :( Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: components/offline_items_collection/core/android/java/src/org/chromium/components/offline_items_collection/LegacyHelpers.java
diff --git a/components/offline_items_collection/core/android/java/src/org/chromium/components/offline_items_collection/LegacyHelpers.java b/components/offline_items_collection/core/android/java/src/org/chromium/components/offline_items_collection/LegacyHelpers.java
new file mode 100644
index 0000000000000000000000000000000000000000..e2c797148f4e537260948a9da818ab16260ec18e
--- /dev/null
+++ b/components/offline_items_collection/core/android/java/src/org/chromium/components/offline_items_collection/LegacyHelpers.java
@@ -0,0 +1,53 @@
+// 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.offline_items_collection;
+
+import android.text.TextUtils;
+
+/**
+ * Legacy helper information meant to help with the migration process to OfflineItems.
+ */
+public class LegacyHelpers {
+ // These are legacy namespaces for the purpose of ID generation that will only affect the UI.
+ public static final String LEGACY_DOWNLOAD_NAMESPACE = "LEGACY_DOWNLOAD";
+ public static final String LEGACY_OFFLINE_PAGE_NAMESPACE = "LEGACY_OFFLINE_PAGE";
+
+ /**
+ * Helper to build a {@link ContentId} based on a single GUID for old offline content sources
+ * (downloads and offline pages).
+ * @param isOfflinePage Whether or not {@code guid} is for an offline page or a download.
+ * @param guid The {@code guid} of the download.
+ * @return A new {@link ContentId} instance.
+ */
+ public static ContentId buildLegacyContentId(boolean isOfflinePage, String guid) {
+ String namespace =
+ isOfflinePage ? LEGACY_OFFLINE_PAGE_NAMESPACE : LEGACY_DOWNLOAD_NAMESPACE;
+ return new ContentId(namespace, guid);
+ }
+
+ /**
+ * Helper to determine if a {@link ContentId} was created from
+ * {@link #buildLegacyContentId(boolean, String)} for a download ({@code false} for {@code
+ * isOfflinePage}).
+ * @param id The {@link ContentId} to inspect.
+ * @return Whether or not {@code id} was built for a traditional download.
+ */
+ public static boolean isLegacyDownload(ContentId id) {
+ return TextUtils.equals(LEGACY_DOWNLOAD_NAMESPACE, id.namespace);
+ }
+
+ /**
+ * Helper to determine if a {@link ContentId} was created from
+ * {@link #buildLegacyContentId(boolean, String)} for an offline page ({@code true} for {@code
+ * isOfflinePage}).
+ * @param id The {@link ContentId} to inspect.
+ * @return Whether or not {@code id} was built for a traditional offline page.
+ */
+ public static boolean isLegacyOfflinePage(ContentId id) {
+ return TextUtils.equals(LEGACY_OFFLINE_PAGE_NAMESPACE, id.namespace);
+ }
+
+ private LegacyHelpers() {}
+}

Powered by Google App Engine
This is Rietveld 408576698