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

Unified Diff: chrome/android/java/src/org/chromium/chrome/browser/compositor/layouts/content/TabContentManager.java

Issue 1124333002: Refactor TabContentManager to async create ThumbnailCache. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Native handle multiple calls. Created 5 years, 7 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | chrome/browser/android/compositor/tab_content_manager.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 4abd5e8480123815d1338d468a4c5082777cc9ad..6f0d66e9370306f9fdd1f8863093ce4535b98940 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, Long> mNativeThumbnailCacheInitTask;
/**
* The Java interface for listening to thumbnail changes.
@@ -96,48 +100,70 @@ 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();
+ startThumbnailCacheInitTask();
+ }
+
+ /**
+ *
+ */
+ private void startThumbnailCacheInitTask() {
+ mNativeThumbnailCacheInitTask = new AsyncTask<Void, Void, Long>() {
+ @Override
+ protected Long 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];
+ return nativeCreateThumbnailCache(diskCachePath, defaultCacheSize,
+ approximationCacheSize, compressionQueueMaxSize, writeQueueMaxSize,
+ useApproximationThumbnails);
+ }
- mNativeTabContentManager = nativeInit(diskCachePath, defaultCacheSize,
- approximationCacheSize, compressionQueueMaxSize, writeQueueMaxSize,
- useApproximationThumbnails);
+ @Override
+ protected void onPostExecute(Long resultThumbnailCache) {
+ if (mNativeTabContentManager != 0) {
+ nativeSetThumbnailCache(mNativeTabContentManager, resultThumbnailCache);
+ } else {
+ nativeDestroyThumbnailCache(resultThumbnailCache);
+ }
+ }
+ }.executeOnExecutor(AsyncTask.SERIAL_EXECUTOR);
}
/**
@@ -151,6 +177,16 @@ public class TabContentManager {
}
@CalledByNative
+ private long blockOnThumbnailCacheCreation() {
+ try {
+ return mNativeThumbnailCacheInitTask.get();
+ } catch (InterruptedException e) {
+ } catch (ExecutionException e) {
+ }
+ return 0;
+ }
+
+ @CalledByNative
private long getNativePtr() {
return mNativeTabContentManager;
}
@@ -331,8 +367,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 +403,13 @@ 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 static native long nativeCreateThumbnailCache(String diskCachePath,
+ int defaultCacheSize, int approximationCacheSize, int compressionQueueMaxSize,
+ int writeQueueMaxSize, boolean useApproximationThumbnail);
+ private static native void nativeDestroyThumbnailCache(long thumbnailCachePtr);
+ private native void nativeSetThumbnailCache(long nativeTabContentManager,
+ long thumbnailCachePtr);
private native boolean nativeHasFullCachedThumbnail(long nativeTabContentManager, int tabId);
private native void nativeCacheTab(long nativeTabContentManager, Object tab,
Object contentViewCore, float thumbnailScale);
« no previous file with comments | « no previous file | chrome/browser/android/compositor/tab_content_manager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698