Chromium Code Reviews| Index: chrome/android/java/src/org/chromium/chrome/browser/crash/ChromeMinidumpUploaderDelegate.java |
| diff --git a/chrome/android/java/src/org/chromium/chrome/browser/crash/ChromeMinidumpUploaderDelegate.java b/chrome/android/java/src/org/chromium/chrome/browser/crash/ChromeMinidumpUploaderDelegate.java |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..7bbe5bc2e25d2bc50e2cdf25a0b676b28f4ac983 |
| --- /dev/null |
| +++ b/chrome/android/java/src/org/chromium/chrome/browser/crash/ChromeMinidumpUploaderDelegate.java |
| @@ -0,0 +1,107 @@ |
| +// Copyright 2017 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| +package org.chromium.chrome.browser.crash; |
| + |
| +import android.annotation.TargetApi; |
| +import android.content.Context; |
| +import android.net.ConnectivityManager; |
| +import android.net.NetworkInfo; |
| +import android.os.Build; |
| +import android.os.PersistableBundle; |
| + |
| +import org.chromium.components.minidump_uploader.MinidumpUploaderDelegate; |
| +import org.chromium.components.minidump_uploader.util.CrashReportingPermissionManager; |
| + |
| +import java.io.File; |
| + |
| +/** |
| + * Chrome-specific implementations for minidump uploading logic. |
| + */ |
| +@TargetApi(Build.VERSION_CODES.LOLLIPOP) |
| +public class ChromeMinidumpUploaderDelegate implements MinidumpUploaderDelegate { |
| + // PersistableBundle keys: |
| + static final String IS_CLIENT_IN_METRICS_SAMPLE = "isClientInMetricsSample"; |
| + static final String IS_CRASH_UPLOAD_DISABLED_BY_COMMAND_LINE = |
| + "isCrashUploadDisabledByCommandLine"; |
| + static final String IS_USAGE_AND_CRASH_REPORTING_PERMITTED_BY_USER = |
| + "isUsageAndCrashReportingPermittedByUser"; |
| + static final String IS_UPLOAD_ENABLED_FOR_TESTS = "isUploadEnabledForTests"; |
| + |
| + /** |
| + * The application context in which minidump uploads are running. |
| + */ |
| + private final Context mContext; |
| + |
| + /** |
| + * The cached crash reporting permissions. These are cached because the upload job might run |
| + * outside of a context in which the original permissions are easily accessible. |
| + */ |
| + private final PersistableBundle mPermissions; |
| + |
| + /** |
| + * The system connectivity manager service, used to determine the network state. |
| + */ |
| + private final ConnectivityManager mConnectivityManager; |
| + |
| + /** |
| + * Constructs a new Chrome-specific minidump uploader delegate. |
| + * @param context The application context in which minidump uploads are running. |
| + * @param permissions The cached crash reporting permissions. |
| + */ |
| + ChromeMinidumpUploaderDelegate(Context context, PersistableBundle permissions) { |
| + mContext = context; |
| + mPermissions = permissions; |
| + mConnectivityManager = |
| + (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); |
| + } |
| + |
| + @Override |
| + public File getCacheDir() { |
| + return mContext.getCacheDir(); |
| + } |
| + |
| + @Override |
| + public CrashReportingPermissionManager createCrashReportingPermissionManager() { |
| + return new CrashReportingPermissionManager() { |
| + // Note: getBoolean is only available in API level 22, so the data is serialized via |
| + // ints instead. |
| + @Override |
| + public boolean isClientInMetricsSample() { |
| + return mPermissions.getInt(IS_CLIENT_IN_METRICS_SAMPLE, 1) == 1; |
| + } |
| + @Override |
| + public boolean isNetworkAvailableForCrashUploads() { |
| + // TODO(isherman): This code should really be shared with the Android Webview |
| + // implementation, which tests whether the connection is metered, rather than |
| + // testing the type of the connection. Implement this change in M59 -- for M58, it's |
| + // more important to maintain consistency with the previous implementation. When |
| + // changing this, note that forced uploads do *not* require unmetered connections. |
| + NetworkInfo networkInfo = mConnectivityManager.getActiveNetworkInfo(); |
| + if (networkInfo == null || !networkInfo.isConnected()) return false; |
| + return networkInfo.getType() == ConnectivityManager.TYPE_WIFI |
| + || networkInfo.getType() == ConnectivityManager.TYPE_ETHERNET; |
| + } |
| + @Override |
| + public boolean isCrashUploadDisabledByCommandLine() { |
| + return mPermissions.getInt(IS_CRASH_UPLOAD_DISABLED_BY_COMMAND_LINE, 0) == 1; |
| + } |
| + @Override |
| + public boolean isUsageAndCrashReportingPermittedByUser() { |
| + // TODO(isherman): Is it okay to use a cached value here? Ideally, we'd only use the |
| + // cached value if Chrome is no longer running -- and update the cached value |
| + // periodically. How hard would that be to implement? |
|
Ilya Sherman
2017/03/13 03:12:09
Maria and Gustav, WDYT? Do either of you know how
gsennton
2017/03/13 17:57:17
When implementing the usage-and-diagnostics check
Ilya Sherman
2017/03/14 02:18:55
Okay, it does seem like it's safe to directly call
gsennton
2017/03/14 18:17:28
When is PrivacyPreferencesManager being created (t
Maria
2017/03/14 19:03:32
I went and read the documentation. Jobs do run wit
Ilya Sherman
2017/03/15 02:13:34
I think you're both correct, and that makes a lot
|
| + return mPermissions.getInt(IS_USAGE_AND_CRASH_REPORTING_PERMITTED_BY_USER, 0) == 1; |
| + } |
| + @Override |
| + public boolean isUploadEnabledForTests() { |
| + return mPermissions.getInt(IS_UPLOAD_ENABLED_FOR_TESTS, 0) == 1; |
| + } |
| + }; |
| + } |
| + |
| + @Override |
| + public void prepareToUploadMinidumps(final Runnable startUploads) { |
| + startUploads.run(); |
| + } |
| +} |