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

Side by Side Diff: base/android/java/src/org/chromium/base/library_loader/LibraryLoader.java

Issue 1879013002: 🍈 Unify application context usage. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix caller/callee relationship in resource_provider. Created 4 years, 8 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 unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 package org.chromium.base.library_loader; 5 package org.chromium.base.library_loader;
6 6
7 import android.annotation.TargetApi; 7 import android.annotation.TargetApi;
8 import android.content.Context; 8 import android.content.Context;
9 import android.content.pm.ApplicationInfo; 9 import android.content.pm.ApplicationInfo;
10 import android.content.pm.PackageInfo; 10 import android.content.pm.PackageInfo;
11 import android.os.AsyncTask; 11 import android.os.AsyncTask;
12 import android.os.Build; 12 import android.os.Build;
13 import android.os.SystemClock; 13 import android.os.SystemClock;
14 14
15 import org.chromium.base.CommandLine; 15 import org.chromium.base.CommandLine;
16 import org.chromium.base.ContextUtils;
16 import org.chromium.base.Log; 17 import org.chromium.base.Log;
17 import org.chromium.base.PackageUtils; 18 import org.chromium.base.PackageUtils;
18 import org.chromium.base.TraceEvent; 19 import org.chromium.base.TraceEvent;
19 import org.chromium.base.annotations.CalledByNative; 20 import org.chromium.base.annotations.CalledByNative;
20 import org.chromium.base.annotations.JNINamespace; 21 import org.chromium.base.annotations.JNINamespace;
21 import org.chromium.base.metrics.RecordHistogram; 22 import org.chromium.base.metrics.RecordHistogram;
22 23
23 import java.util.concurrent.atomic.AtomicBoolean; 24 import java.util.concurrent.atomic.AtomicBoolean;
24 25
25 import javax.annotation.Nullable; 26 import javax.annotation.Nullable;
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
125 mLibraryProcessType = libraryProcessType; 126 mLibraryProcessType = libraryProcessType;
126 mPrefetchLibraryHasBeenCalled = new AtomicBoolean(); 127 mPrefetchLibraryHasBeenCalled = new AtomicBoolean();
127 } 128 }
128 129
129 /** 130 /**
130 * This method blocks until the library is fully loaded and initialized. 131 * This method blocks until the library is fully loaded and initialized.
131 * 132 *
132 * @param context The context in which the method is called. 133 * @param context The context in which the method is called.
133 */ 134 */
134 public void ensureInitialized(Context context) throws ProcessInitException { 135 public void ensureInitialized(Context context) throws ProcessInitException {
136 // TODO(wnwen): Move this call appropriately down to the tests that need it.
137 ContextUtils.initApplicationContext(context.getApplicationContext());
135 synchronized (sLock) { 138 synchronized (sLock) {
136 if (mInitialized) { 139 if (mInitialized) {
137 // Already initialized, nothing to do. 140 // Already initialized, nothing to do.
138 return; 141 return;
139 } 142 }
140 loadAlreadyLocked(context); 143 loadAlreadyLocked(context);
141 initializeAlreadyLocked(); 144 initializeAlreadyLocked();
142 } 145 }
143 } 146 }
144 147
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after
353 // This must happen after the code is loaded and after JNI is ready (since a fter the 356 // This must happen after the code is loaded and after JNI is ready (since a fter the
354 // switch the Java CommandLine will delegate all calls the native CommandLin e). 357 // switch the Java CommandLine will delegate all calls the native CommandLin e).
355 private void ensureCommandLineSwitchedAlreadyLocked() { 358 private void ensureCommandLineSwitchedAlreadyLocked() {
356 assert mLoaded; 359 assert mLoaded;
357 if (mCommandLineSwitched) { 360 if (mCommandLineSwitched) {
358 return; 361 return;
359 } 362 }
360 nativeInitCommandLine(CommandLine.getJavaSwitchesOrNull()); 363 nativeInitCommandLine(CommandLine.getJavaSwitchesOrNull());
361 CommandLine.enableNativeProxy(); 364 CommandLine.enableNativeProxy();
362 mCommandLineSwitched = true; 365 mCommandLineSwitched = true;
366
367 // Ensure that native side application context is loaded and in sync wit h java side. Must do
368 // this here so webview also gets its application context set before ful ly initializing.
369 ContextUtils.initApplicationContextForNative();
363 } 370 }
364 371
365 // Invoke base::android::LibraryLoaded in library_loader_hooks.cc 372 // Invoke base::android::LibraryLoaded in library_loader_hooks.cc
366 private void initializeAlreadyLocked() throws ProcessInitException { 373 private void initializeAlreadyLocked() throws ProcessInitException {
367 if (mInitialized) { 374 if (mInitialized) {
368 return; 375 return;
369 } 376 }
370 377
371 // Setup the native command line if necessary. 378 ensureCommandLineSwitchedAlreadyLocked();
372 if (!mCommandLineSwitched) {
373 nativeInitCommandLine(CommandLine.getJavaSwitchesOrNull());
374 }
375 379
376 if (!nativeLibraryLoaded()) { 380 if (!nativeLibraryLoaded()) {
377 Log.e(TAG, "error calling nativeLibraryLoaded"); 381 Log.e(TAG, "error calling nativeLibraryLoaded");
378 throw new ProcessInitException(LoaderErrors.LOADER_ERROR_FAILED_TO_R EGISTER_JNI); 382 throw new ProcessInitException(LoaderErrors.LOADER_ERROR_FAILED_TO_R EGISTER_JNI);
379 } 383 }
380 384
381 // The Chrome JNI is registered by now so we can switch the Java
382 // command line over to delegating to native if it's necessary.
383 if (!mCommandLineSwitched) {
384 CommandLine.enableNativeProxy();
385 mCommandLineSwitched = true;
386 }
387
388 // From now on, keep tracing in sync with native. 385 // From now on, keep tracing in sync with native.
389 TraceEvent.registerNativeEnabledObserver(); 386 TraceEvent.registerNativeEnabledObserver();
390 387
391 // From this point on, native code is ready to use and checkIsReady() 388 // From this point on, native code is ready to use and checkIsReady()
392 // shouldn't complain from now on (and in fact, it's used by the 389 // shouldn't complain from now on (and in fact, it's used by the
393 // following calls). 390 // following calls).
394 // Note that this flag can be accessed asynchronously, so any initializa tion 391 // Note that this flag can be accessed asynchronously, so any initializa tion
395 // must be performed before. 392 // must be performed before.
396 mInitialized = true; 393 mInitialized = true;
397 } 394 }
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
484 481
485 // Finds the ranges corresponding to the native library pages, forks a new 482 // Finds the ranges corresponding to the native library pages, forks a new
486 // process to prefetch these pages and waits for it. The new process then 483 // process to prefetch these pages and waits for it. The new process then
487 // terminates. This is blocking. 484 // terminates. This is blocking.
488 private static native boolean nativeForkAndPrefetchNativeLibrary(); 485 private static native boolean nativeForkAndPrefetchNativeLibrary();
489 486
490 // Returns the percentage of the native library code page that are currently reseident in 487 // Returns the percentage of the native library code page that are currently reseident in
491 // memory. 488 // memory.
492 private static native int nativePercentageOfResidentNativeLibraryCode(); 489 private static native int nativePercentageOfResidentNativeLibraryCode();
493 } 490 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698