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

Unified Diff: content/public/android/java/src/org/chromium/content_public/resources/dynamics/DynamicResourceLoader.java

Issue 731133002: Upstream ResourceManager (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add generated enum class to BUILD.gn Created 6 years, 1 month 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: content/public/android/java/src/org/chromium/content_public/resources/dynamics/DynamicResourceLoader.java
diff --git a/content/public/android/java/src/org/chromium/content_public/resources/dynamics/DynamicResourceLoader.java b/content/public/android/java/src/org/chromium/content_public/resources/dynamics/DynamicResourceLoader.java
new file mode 100644
index 0000000000000000000000000000000000000000..d0b91be83c46a50a76f214313203a2ec88e400d5
--- /dev/null
+++ b/content/public/android/java/src/org/chromium/content_public/resources/dynamics/DynamicResourceLoader.java
@@ -0,0 +1,69 @@
+// Copyright 2014 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.content_public.resources.dynamics;
+
+import android.util.SparseArray;
+
+import org.chromium.content_public.resources.ResourceLoader;
+
+/**
+ * Handles managing dynamic resources. This is basically a list of dynamic resources that checks
+ * {@link DynamicResource#isDirty()} before notifying the {@link ResourceLoaderCallback}.
+ */
+public class DynamicResourceLoader extends ResourceLoader {
+ private final SparseArray<DynamicResource> mDynamicResources =
+ new SparseArray<DynamicResource>();
+
+ /**
+ * Builds a {@link DynamicResourceLoader} instance.
+ * @param resourceType The resource type this loader is responsible for loading.
+ * @param callback A {@link ResourceLoaderCallback} to be notified when the dynamic resource
+ * has changed. The callback will only be notified if
+ * {@link #loadResource(int)} is called.
+ */
+ public DynamicResourceLoader(int resourceType, ResourceLoaderCallback callback) {
+ super(resourceType, callback);
+ }
+
+ /**
+ * Registers a {@link DynamicResource} to be tracked and exposed by this class.
+ * @param resId The Android id to use. This should be an actual Android id (R.id.some_id).
+ * @param resource The {@link DynamicResource} to track and expose.
+ */
+ public void registerResource(int resId, DynamicResource resource) {
+ assert mDynamicResources.get(resId) == null;
+ mDynamicResources.put(resId, resource);
+ }
+
+ /**
+ * Unregisters a {@link DynamicResource} specified by {@code resId}.
+ * @param resId The Android id representing the {@link DynamicResource}.
+ */
+ public void unregisterResource(int resId) {
+ mDynamicResources.remove(resId);
+ }
+
+ /**
+ * Called when a {@link DynamicResource} was requested. This will notify the
+ * {@link ResourceLoaderCallback} if the resource has new contents.
+ * @param resId The Android id representing the {@link DynamicResource}.
+ */
+ @Override
+ public void loadResource(int resId) {
+ DynamicResource resource = mDynamicResources.get(resId);
+ if (resource == null) return;
+
+ if (resource.isDirty()) notifyLoadFinished(resId, resource);
+ }
+
+ /**
+ * Since this class relies solely on registration it does not support preloading resources.
+ */
+ @Override
+ public void preloadResource(int resId) {
+ // Not implemented.
+ assert false : "Preloading dynamic resources isn't supported.";
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698