Chromium Code Reviews| Index: blimp/client/android/java/src/org/chromium/blimp/BlimpLibraryLoader.java |
| diff --git a/blimp/client/android/java/src/org/chromium/blimp/BlimpLibraryLoader.java b/blimp/client/android/java/src/org/chromium/blimp/BlimpLibraryLoader.java |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..17ce169186a17a3d1deb9a2e6af2618c19257e33 |
| --- /dev/null |
| +++ b/blimp/client/android/java/src/org/chromium/blimp/BlimpLibraryLoader.java |
| @@ -0,0 +1,72 @@ |
| +// Copyright 2015 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.blimp; |
| + |
| +import android.content.Context; |
| +import android.os.Handler; |
| + |
| +import org.chromium.base.ResourceExtractor; |
| +import org.chromium.base.annotations.JNINamespace; |
| +import org.chromium.base.library_loader.LibraryLoader; |
| +import org.chromium.base.library_loader.LibraryProcessType; |
| +import org.chromium.base.library_loader.ProcessInitException; |
| + |
| +/** |
| + * A simple utility class to asynchronously load and register the native libraries associated with |
|
Wez
2015/08/27 02:01:51
Given how awful this looks in codereview, and that
David Trainor- moved to gerrit
2015/08/28 01:23:45
Chromium java uses the Android style guide which e
Wez
2015/09/03 00:49:26
Three things:
1. Acknowledged. :P
2. *facepalm*
3.
David Trainor- moved to gerrit
2015/09/03 06:33:21
Re 3: Made me laugh out loud! :)
|
| + * Blimp. |
| + */ |
| +@JNINamespace("blimp") |
| +public final class BlimpLibraryLoader { |
| + /** |
| + * A callback interface that is notified with the native library load results. |
| + */ |
| + public interface Callback { |
| + /** |
| + * Called when the load attempt is finished (regardless of whether or not it was |
| + * successful). |
| + * @param success Whether or not the native library was successfully loaded. |
| + */ |
| + void onStartupComplete(boolean success); |
| + } |
| + |
| + /** |
| + * Disallow instantiation of this class. |
| + */ |
| + private BlimpLibraryLoader() {} |
| + |
| + /** |
| + * Starts asynchronously loading and registering the native libraries. |
| + * @param context A {@link Context} object. |
| + * @param callback A {@link BlimpLibraryLoader.Callback} to be notified upon |
| + * completion. |
| + * @throws ProcessInitException |
| + */ |
| + public static void startAsync(final Context context, final Callback callback) |
| + throws ProcessInitException { |
| + ResourceExtractor extractor = ResourceExtractor.get(context); |
| + extractor.startExtractingResources(); |
| + |
| + LibraryLoader.get(LibraryProcessType.PROCESS_BROWSER).ensureInitialized(context); |
| + |
| + extractor.addCompletionCallback(new Runnable() { |
| + @Override |
| + public void run() { |
| + final boolean initResult = nativeInitializeBlimp(context.getApplicationContext()); |
| + new Handler().post(new Runnable() { |
| + @Override |
| + public void run() { |
| + // Only run nativeStartBlimp if we properly initialized native. |
| + boolean startResult = initResult ? nativeStartBlimp() : false; |
|
Wez
2015/08/27 02:01:51
n00b: Can this not be just initResult && nativeSta
David Trainor- moved to gerrit
2015/08/28 01:23:45
Gah good point!
|
| + if (callback != null) callback.onStartupComplete(startResult); |
|
Wez
2015/08/27 02:01:51
nit: This if() needs braces according to style-gui
David Trainor- moved to gerrit
2015/08/28 01:23:45
Chromium Java uses the Android styleguide. http:/
Wez
2015/09/03 00:49:26
Acknowledged.
|
| + } |
| + }); |
| + } |
| + }); |
| + } |
| + |
| + // Native Methods ------------------------------------------------------------------------------ |
| + private static native boolean nativeInitializeBlimp(Context context); |
| + private static native boolean nativeStartBlimp(); |
| +} |