OLD | NEW |
(Empty) | |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 package org.chromium.blimp; |
| 6 |
| 7 import android.content.Context; |
| 8 import android.os.Handler; |
| 9 |
| 10 import org.chromium.base.ResourceExtractor; |
| 11 import org.chromium.base.annotations.JNINamespace; |
| 12 import org.chromium.base.library_loader.LibraryLoader; |
| 13 import org.chromium.base.library_loader.LibraryProcessType; |
| 14 import org.chromium.base.library_loader.ProcessInitException; |
| 15 |
| 16 /** |
| 17 * A simple utility class to asynchronously load and register the native librari
es associated with |
| 18 * Blimp. |
| 19 */ |
| 20 @JNINamespace("blimp") |
| 21 public final class BlimpLibraryLoader { |
| 22 /** |
| 23 * A callback interface that is notified with the native library load result
s. |
| 24 */ |
| 25 public interface Callback { |
| 26 /** |
| 27 * Called when the load attempt is finished (regardless of whether or no
t it was |
| 28 * successful). |
| 29 * @param success Whether or not the native library was successfully loa
ded. |
| 30 */ |
| 31 void onStartupComplete(boolean success); |
| 32 } |
| 33 |
| 34 /** |
| 35 * Disallow instantiation of this class. |
| 36 */ |
| 37 private BlimpLibraryLoader() {} |
| 38 |
| 39 /** |
| 40 * Starts asynchronously loading and registering the native libraries. |
| 41 * @param context A {@link Context} object. |
| 42 * @param callback A {@link BlimpLibraryLoader.Callback} to be
notified upon |
| 43 * completion. |
| 44 * @throws ProcessInitException |
| 45 */ |
| 46 public static void startAsync(final Context context, final Callback callback
) |
| 47 throws ProcessInitException { |
| 48 ResourceExtractor extractor = ResourceExtractor.get(context); |
| 49 extractor.startExtractingResources(); |
| 50 |
| 51 LibraryLoader.get(LibraryProcessType.PROCESS_BROWSER).ensureInitialized(
context); |
| 52 |
| 53 extractor.addCompletionCallback(new Runnable() { |
| 54 @Override |
| 55 public void run() { |
| 56 final boolean initResult = nativeInitializeBlimp(context.getAppl
icationContext()); |
| 57 new Handler().post(new Runnable() { |
| 58 @Override |
| 59 public void run() { |
| 60 // Only run nativeStartBlimp if we properly initialized
native. |
| 61 boolean startResult = initResult ? nativeStartBlimp() :
false; |
| 62 if (callback != null) callback.onStartupComplete(startRe
sult); |
| 63 } |
| 64 }); |
| 65 } |
| 66 }); |
| 67 } |
| 68 |
| 69 // Native Methods ----------------------------------------------------------
-------------------- |
| 70 private static native boolean nativeInitializeBlimp(Context context); |
| 71 private static native boolean nativeStartBlimp(); |
| 72 } |
OLD | NEW |