Chromium Code Reviews| Index: chrome/android/java/src/org/chromium/chrome/browser/compositor/layouts/content/TabContentManager.java |
| diff --git a/chrome/android/java/src/org/chromium/chrome/browser/compositor/layouts/content/TabContentManager.java b/chrome/android/java/src/org/chromium/chrome/browser/compositor/layouts/content/TabContentManager.java |
| index 0d14ddee919f809d359ed9605e35452b0abed363..4db041fd0b61be09bd2825ac942458c588d936fd 100644 |
| --- a/chrome/android/java/src/org/chromium/chrome/browser/compositor/layouts/content/TabContentManager.java |
| +++ b/chrome/android/java/src/org/chromium/chrome/browser/compositor/layouts/content/TabContentManager.java |
| @@ -7,6 +7,7 @@ package org.chromium.chrome.browser.compositor.layouts.content; |
| import android.content.Context; |
| import android.graphics.Bitmap; |
| import android.graphics.Canvas; |
| +import android.os.AsyncTask; |
| import android.util.SparseArray; |
| import android.view.View; |
| @@ -24,6 +25,7 @@ import org.chromium.ui.base.DeviceFormFactor; |
| import java.io.File; |
| import java.util.ArrayList; |
| import java.util.List; |
| +import java.util.concurrent.ExecutionException; |
| /** |
| * The TabContentManager is responsible for serving tab contents to the UI components. Contents |
| @@ -33,10 +35,11 @@ import java.util.List; |
| public class TabContentManager { |
| private static final String THUMBNAIL_DIRECTORY = "textures"; |
| private final Context mContext; |
| - private final File mThumbnailsDir; |
| - private final float mThumbnailScale; |
| - private final int mFullResThumbnailsMaxSize; |
| private final ContentOffsetProvider mContentOffsetProvider; |
| + |
| + private File mThumbnailsDir; |
| + private float mThumbnailScale; |
| + private int mFullResThumbnailsMaxSize; |
| private int[] mPriorityTabIds; |
| private long mNativeTabContentManager; |
| @@ -57,6 +60,7 @@ public class TabContentManager { |
| new SparseArray<TabContentManager.DecompressThumbnailCallback>(); |
| private boolean mSnapshotsEnabled; |
| + private AsyncTask<Void, Void, Void> mNativeThumbnailCacheInitTask; |
| /** |
| * The Java interface for listening to thumbnail changes. |
| @@ -96,48 +100,59 @@ public class TabContentManager { |
| mContentOffsetProvider = contentOffsetProvider; |
| mSnapshotsEnabled = snapshotsEnabled; |
| - mThumbnailsDir = mContext.getDir(THUMBNAIL_DIRECTORY, Context.MODE_PRIVATE); |
| - String diskCachePath = mThumbnailsDir.getAbsolutePath(); |
| - |
| - // Override the cache size on the command line with --thumbnails=100 |
| - int defaultCacheSize = getIntegerResourceWithOverride(mContext, |
| - R.integer.default_thumbnail_cache_size, ChromeSwitches.THUMBNAILS); |
| - |
| - mFullResThumbnailsMaxSize = defaultCacheSize; |
| - |
| - int compressionQueueMaxSize = mContext.getResources().getInteger( |
| - R.integer.default_compression_queue_size); |
| - int writeQueueMaxSize = mContext.getResources().getInteger( |
| - R.integer.default_write_queue_size); |
| - |
| - // Override the cache size on the command line with |
| - // --approximation-thumbnails=100 |
| - int approximationCacheSize = getIntegerResourceWithOverride(mContext, |
| - R.integer.default_approximation_thumbnail_cache_size, |
| - ChromeSwitches.APPROXIMATION_THUMBNAILS); |
| - |
| - float thumbnailScale = 1.f; |
| - boolean useApproximationThumbnails; |
| - float deviceDensity = mContext.getResources().getDisplayMetrics().density; |
| - if (DeviceFormFactor.isTablet(mContext)) { |
| - // Scale all tablets to MDPI. |
| - thumbnailScale = 1.f / deviceDensity; |
| - useApproximationThumbnails = false; |
| - } else { |
| - // For phones, reduce the amount of memory usage by capturing a lower-res thumbnail for |
| - // devices with resolution higher than HDPI (crbug.com/357740). |
| - if (deviceDensity > 1.5f) { |
| - thumbnailScale = 1.5f / deviceDensity; |
| - } |
| - useApproximationThumbnails = true; |
| - } |
| - mThumbnailScale = thumbnailScale; |
| + mNativeTabContentManager = nativeInit(); |
| + |
| + mNativeThumbnailCacheInitTask = new AsyncTask<Void, Void, Void>() { |
| + @Override |
| + protected Void doInBackground(Void... unused) { |
| + mThumbnailsDir = mContext.getDir(THUMBNAIL_DIRECTORY, Context.MODE_PRIVATE); |
| + String diskCachePath = mThumbnailsDir.getAbsolutePath(); |
| + |
| + // Override the cache size on the command line with --thumbnails=100 |
| + int defaultCacheSize = getIntegerResourceWithOverride(mContext, |
| + R.integer.default_thumbnail_cache_size, ChromeSwitches.THUMBNAILS); |
| + |
| + mFullResThumbnailsMaxSize = defaultCacheSize; |
| + |
| + int compressionQueueMaxSize = mContext.getResources().getInteger( |
| + R.integer.default_compression_queue_size); |
| + int writeQueueMaxSize = mContext.getResources().getInteger( |
| + R.integer.default_write_queue_size); |
| + |
| + // Override the cache size on the command line with |
| + // --approximation-thumbnails=100 |
| + int approximationCacheSize = getIntegerResourceWithOverride(mContext, |
| + R.integer.default_approximation_thumbnail_cache_size, |
| + ChromeSwitches.APPROXIMATION_THUMBNAILS); |
| + |
| + float thumbnailScale = 1.f; |
| + boolean useApproximationThumbnails; |
| + float deviceDensity = mContext.getResources().getDisplayMetrics().density; |
| + if (DeviceFormFactor.isTablet(mContext)) { |
| + // Scale all tablets to MDPI. |
| + thumbnailScale = 1.f / deviceDensity; |
| + useApproximationThumbnails = false; |
| + } else { |
| + // For phones, reduce the amount of memory usage by capturing a lower-res |
| + // thumbnail for devices with resolution higher than HDPI (crbug.com/357740). |
| + if (deviceDensity > 1.5f) { |
| + thumbnailScale = 1.5f / deviceDensity; |
| + } |
| + useApproximationThumbnails = true; |
| + } |
| + mThumbnailScale = thumbnailScale; |
| + |
| + mPriorityTabIds = new int[mFullResThumbnailsMaxSize]; |
| - mPriorityTabIds = new int[mFullResThumbnailsMaxSize]; |
| + if (mNativeTabContentManager != 0) { |
| + nativeCreateThumbnailCache(mNativeTabContentManager, diskCachePath, |
|
David Trainor- moved to gerrit
2015/05/07 17:57:35
This doesn't look thread safe. What if someone ca
Peter Wen
2015/05/07 22:08:10
Done.
|
| + defaultCacheSize, approximationCacheSize, compressionQueueMaxSize, |
| + writeQueueMaxSize, useApproximationThumbnails); |
| + } |
| - mNativeTabContentManager = nativeInit(diskCachePath, defaultCacheSize, |
| - approximationCacheSize, compressionQueueMaxSize, writeQueueMaxSize, |
| - useApproximationThumbnails); |
| + return null; |
| + } |
| + }.executeOnExecutor(AsyncTask.SERIAL_EXECUTOR); |
| } |
| /** |
| @@ -151,6 +166,15 @@ public class TabContentManager { |
| } |
| @CalledByNative |
| + private void blockOnThumbnailCacheCreation() { |
| + try { |
| + mNativeThumbnailCacheInitTask.get(); |
| + } catch (InterruptedException e) { |
| + } catch (ExecutionException e) { |
| + } |
| + } |
| + |
| + @CalledByNative |
| private long getNativePtr() { |
| return mNativeTabContentManager; |
| } |
| @@ -331,8 +355,10 @@ public class TabContentManager { |
| * @param modelSelector The selector that answers whether a tab is currently present. |
| */ |
| public void cleanupPersistentData(TabModelSelector modelSelector) { |
| + if (mNativeTabContentManager == 0) return; |
| + |
| File[] files = mThumbnailsDir.listFiles(); |
| - if (files == null || mNativeTabContentManager == 0) return; |
| + if (files == null) return; |
| for (File file : files) { |
| try { |
| @@ -365,9 +391,10 @@ public class TabContentManager { |
| } |
| // Class Object Methods |
| - private native long nativeInit(String diskCachePath, int defaultCacheSize, |
| - int approximationCacheSize, int compressionQueueMaxSize, int writeQueueMaxSize, |
| - boolean useApproximationThumbnail); |
| + private native long nativeInit(); |
| + private native void nativeCreateThumbnailCache(long nativeTabContentManager, |
| + String diskCachePath, int defaultCacheSize, int approximationCacheSize, |
| + int compressionQueueMaxSize, int writeQueueMaxSize, boolean useApproximationThumbnail); |
| private native boolean nativeHasFullCachedThumbnail(long nativeTabContentManager, int tabId); |
| private native void nativeCacheTab(long nativeTabContentManager, Object tab, |
| Object contentViewCore, float thumbnailScale); |