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 * Asynchronously loads and registers the native libraries associated with Blimp
. |
| 18 */ |
| 19 @JNINamespace("blimp") |
| 20 public final class BlimpLibraryLoader { |
| 21 /** |
| 22 * A callback interface that is notified with the native library load result
s. |
| 23 */ |
| 24 public interface Callback { |
| 25 /** |
| 26 * Called when the load attempt is finished (regardless of whether or no
t it was |
| 27 * successful). |
| 28 * @param success Whether or not the native library was successfully loa
ded. |
| 29 */ |
| 30 void onStartupComplete(boolean success); |
| 31 } |
| 32 |
| 33 /** |
| 34 * Disallow instantiation of this class. |
| 35 */ |
| 36 private BlimpLibraryLoader() {} |
| 37 |
| 38 /** |
| 39 * Starts asynchronously loading and registering the native libraries. |
| 40 * @param context A {@link Context} object. |
| 41 * @param callback A {@link BlimpLibraryLoader.Callback} to be
notified upon |
| 42 * completion. |
| 43 * @throws ProcessInitException |
| 44 */ |
| 45 public static void startAsync(final Context context, final Callback callback
) |
| 46 throws ProcessInitException { |
| 47 ResourceExtractor extractor = ResourceExtractor.get(context); |
| 48 extractor.startExtractingResources(); |
| 49 |
| 50 LibraryLoader.get(LibraryProcessType.PROCESS_BROWSER).ensureInitialized(
context); |
| 51 |
| 52 extractor.addCompletionCallback(new Runnable() { |
| 53 @Override |
| 54 public void run() { |
| 55 final boolean initResult = nativeInitializeBlimp(context.getAppl
icationContext()); |
| 56 new Handler().post(new Runnable() { |
| 57 @Override |
| 58 public void run() { |
| 59 // Only run nativeStartBlimp if we properly initialized
native. |
| 60 boolean startResult = initResult && nativeStartBlimp(); |
| 61 if (callback != null) callback.onStartupComplete(startRe
sult); |
| 62 } |
| 63 }); |
| 64 } |
| 65 }); |
| 66 } |
| 67 |
| 68 // Native Methods |
| 69 private static native boolean nativeInitializeBlimp(Context context); |
| 70 private static native boolean nativeStartBlimp(); |
| 71 } |
OLD | NEW |