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

Unified Diff: base/android/java/src/org/chromium/base/ApkAssets.java

Issue 1180693002: Update from https://crrev.com/333737 (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: rebased Created 5 years, 6 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: base/android/java/src/org/chromium/base/ApkAssets.java
diff --git a/base/android/java/src/org/chromium/base/ApkAssets.java b/base/android/java/src/org/chromium/base/ApkAssets.java
new file mode 100644
index 0000000000000000000000000000000000000000..329660f6216de0a212949ce545b93dddd85c91ff
--- /dev/null
+++ b/base/android/java/src/org/chromium/base/ApkAssets.java
@@ -0,0 +1,45 @@
+// 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.base;
+
+import android.content.Context;
+import android.content.res.AssetFileDescriptor;
+import android.content.res.AssetManager;
+import android.util.Log;
+
+import java.io.IOException;
+
+/**
+ * A utility class to retrieve references to uncompressed assets insides the apk. A reference is
+ * defined as tuple (file descriptor, offset, size) enabling direct mapping without deflation.
+ * This can be used even within the renderer process, since it just dup's the apk's fd.
+ */
+@JNINamespace("base::android")
+public class ApkAssets {
+ private static final String LOGTAG = "ApkAssets";
+
+ @CalledByNative
+ public static long[] open(Context context, String fileName) {
+ AssetFileDescriptor afd = null;
+ try {
+ AssetManager manager = context.getAssets();
+ afd = manager.openNonAssetFd(fileName);
+ return new long[] { afd.getParcelFileDescriptor().detachFd(),
+ afd.getStartOffset(),
+ afd.getLength() };
+ } catch (IOException e) {
+ Log.e(LOGTAG, "Error while loading asset " + fileName + ": " + e);
+ return new long[] {-1, -1, -1};
+ } finally {
+ try {
+ if (afd != null) {
+ afd.close();
+ }
+ } catch (IOException e2) {
+ Log.e(LOGTAG, "Unable to close AssetFileDescriptor", e2);
+ }
+ }
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698