| Index: components/minidump_uploader/android/java/src/org/chromium/components/minidump_uploader/MinidumpUploaderImpl.java
|
| diff --git a/android_webview/java/src/org/chromium/android_webview/crash/MinidumpUploaderImpl.java b/components/minidump_uploader/android/java/src/org/chromium/components/minidump_uploader/MinidumpUploaderImpl.java
|
| similarity index 64%
|
| rename from android_webview/java/src/org/chromium/android_webview/crash/MinidumpUploaderImpl.java
|
| rename to components/minidump_uploader/android/java/src/org/chromium/components/minidump_uploader/MinidumpUploaderImpl.java
|
| index 4395a3cc6ed0b1741bc93ef2b9454fa13317dacc..ae84b3b4dace8c695a3ba960b98a2e713145b43c 100644
|
| --- a/android_webview/java/src/org/chromium/android_webview/crash/MinidumpUploaderImpl.java
|
| +++ b/components/minidump_uploader/android/java/src/org/chromium/components/minidump_uploader/MinidumpUploaderImpl.java
|
| @@ -2,28 +2,16 @@
|
| // Use of this source code is governed by a BSD-style license that can be
|
| // found in the LICENSE file.
|
|
|
| -package org.chromium.android_webview.crash;
|
| +package org.chromium.components.minidump_uploader;
|
|
|
| -import android.content.Context;
|
| -import android.net.ConnectivityManager;
|
| -import android.net.NetworkInfo;
|
| -import android.webkit.ValueCallback;
|
| -
|
| -import org.chromium.android_webview.PlatformServiceBridge;
|
| -import org.chromium.android_webview.command_line.CommandLineUtil;
|
| -import org.chromium.base.CommandLine;
|
| import org.chromium.base.Log;
|
| import org.chromium.base.ThreadUtils;
|
| import org.chromium.base.VisibleForTesting;
|
| -import org.chromium.components.minidump_uploader.CrashFileManager;
|
| -import org.chromium.components.minidump_uploader.MinidumpUploadCallable;
|
| -import org.chromium.components.minidump_uploader.MinidumpUploader;
|
| -import org.chromium.components.minidump_uploader.util.CrashReportingPermissionManager;
|
|
|
| import java.io.File;
|
|
|
| /**
|
| - * Class in charge of uploading minidumps from WebView's data directory.
|
| + * Class in charge of uploading minidumps from their local data directory.
|
| * This class gets invoked from a JobScheduler job and posts the operation of uploading minidumps to
|
| * a privately defined worker thread.
|
| * Note that this implementation is state-less in the sense that it doesn't keep track of whether it
|
| @@ -32,8 +20,11 @@ import java.io.File;
|
| */
|
| public class MinidumpUploaderImpl implements MinidumpUploader {
|
| private static final String TAG = "MinidumpUploaderImpl";
|
| - private Context mContext;
|
| - private final ConnectivityManager mConnectivityManager;
|
| +
|
| + /**
|
| + * The delegate that performs embedder-specific behavior.
|
| + */
|
| + private final MinidumpUploaderDelegate mDelegate;
|
|
|
| /**
|
| * Manages the set of pending and failed local minidump files.
|
| @@ -51,18 +42,13 @@ public class MinidumpUploaderImpl implements MinidumpUploader {
|
| */
|
| private Thread mWorkerThread;
|
|
|
| - private boolean mPermittedByUser = false;
|
| -
|
| @VisibleForTesting
|
| public static final int MAX_UPLOAD_TRIES_ALLOWED = 3;
|
|
|
| @VisibleForTesting
|
| - public MinidumpUploaderImpl(Context context) {
|
| - mConnectivityManager =
|
| - (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
|
| - mContext = context;
|
| - File crashDir = CrashReceiverService.createWebViewCrashDir(context);
|
| - mFileManager = createCrashFileManager(crashDir);
|
| + public MinidumpUploaderImpl(MinidumpUploaderDelegate delegate) {
|
| + mDelegate = delegate;
|
| + mFileManager = createCrashFileManager(mDelegate.createCrashDir());
|
| if (!mFileManager.ensureCrashDirExists()) {
|
| Log.e(TAG, "Crash directory doesn't exist!");
|
| }
|
| @@ -84,63 +70,7 @@ public class MinidumpUploaderImpl implements MinidumpUploader {
|
| @VisibleForTesting
|
| public MinidumpUploadCallable createMinidumpUploadCallable(File minidumpFile, File logfile) {
|
| return new MinidumpUploadCallable(
|
| - minidumpFile, logfile, createWebViewCrashReportingManager());
|
| - }
|
| -
|
| - /**
|
| - * Utility method to allow us to test the logic of this class by injecting
|
| - * a test-specific PlatformServiceBridge.
|
| - */
|
| - @VisibleForTesting
|
| - public PlatformServiceBridge createPlatformServiceBridge() {
|
| - return PlatformServiceBridge.getInstance(mContext);
|
| - }
|
| -
|
| - @VisibleForTesting
|
| - protected CrashReportingPermissionManager createWebViewCrashReportingManager() {
|
| - return new CrashReportingPermissionManager() {
|
| - @Override
|
| - public boolean isClientInMetricsSample() {
|
| - // We will check whether the client is in the metrics sample before
|
| - // generating a minidump - so if no minidump is generated this code will
|
| - // never run and we don't need to check whether we are in the sample.
|
| - // TODO(gsennton): when we switch to using Finch for this value we should use the
|
| - // Finch value here as well.
|
| - return true;
|
| - }
|
| - @Override
|
| - public boolean isNetworkAvailableForCrashUploads() {
|
| - // JobScheduler will call onStopJob causing our upload to be interrupted when our
|
| - // network requirements no longer hold.
|
| - NetworkInfo networkInfo = mConnectivityManager.getActiveNetworkInfo();
|
| - if (networkInfo == null || !networkInfo.isConnected()) return false;
|
| - return !mConnectivityManager.isActiveNetworkMetered();
|
| - }
|
| - @Override
|
| - public boolean isCrashUploadDisabledByCommandLine() {
|
| - return false;
|
| - }
|
| - /**
|
| - * This method is already represented by isClientInMetricsSample() and
|
| - * isNetworkAvailableForCrashUploads().
|
| - */
|
| - @Override
|
| - public boolean isMetricsUploadPermitted() {
|
| - return true;
|
| - }
|
| - @Override
|
| - public boolean isUsageAndCrashReportingPermittedByUser() {
|
| - return mPermittedByUser;
|
| - }
|
| - @Override
|
| - public boolean isUploadEnabledForTests() {
|
| - // Note that CommandLine/CommandLineUtil are not thread safe. They are initialized
|
| - // on the main thread, but before the current worker thread started - so this thread
|
| - // will have seen the initialization of the CommandLine.
|
| - return CommandLine.getInstance().hasSwitch(
|
| - CommandLineUtil.CRASH_UPLOADS_ENABLED_FOR_TESTING_SWITCH);
|
| - }
|
| - };
|
| + minidumpFile, logfile, mDelegate.createCrashReportingPermissionManager());
|
| }
|
|
|
| /**
|
| @@ -211,12 +141,11 @@ public class MinidumpUploaderImpl implements MinidumpUploader {
|
| new UploadRunnable(uploadsFinishedCallback), "MinidumpUploader-WorkerThread");
|
| mCancelUpload = false;
|
|
|
| - createPlatformServiceBridge().queryMetricsSetting(new ValueCallback<Boolean>() {
|
| - public void onReceiveValue(Boolean enabled) {
|
| + mDelegate.prepareToUploadMinidumps(new Runnable() {
|
| + @Override
|
| + public void run() {
|
| ThreadUtils.assertOnUiThread();
|
|
|
| - mPermittedByUser = enabled;
|
| -
|
| // Note that the upload job might have been canceled by this time. However, it's
|
| // important to start the worker thread anyway to try to make some progress towards
|
| // uploading minidumps. This is to ensure that in the case where an app is crashing
|
|
|