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

Unified Diff: chrome/android/java/src/org/chromium/chrome/browser/crash/CrashFileManager.java

Issue 2416963005: Fix chrome_java FindBugs errors found when switching to n sdk. (Closed)
Patch Set: rebase Created 4 years, 2 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
Index: chrome/android/java/src/org/chromium/chrome/browser/crash/CrashFileManager.java
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/crash/CrashFileManager.java b/chrome/android/java/src/org/chromium/chrome/browser/crash/CrashFileManager.java
index 82bcb700c037624dcbae605c6aa9367ee4abd6ac..f7c4679b3a2c2179a2c66aa8f9d95d44d717789c 100644
--- a/chrome/android/java/src/org/chromium/chrome/browser/crash/CrashFileManager.java
+++ b/chrome/android/java/src/org/chromium/chrome/browser/crash/CrashFileManager.java
@@ -4,6 +4,8 @@
package org.chromium.chrome.browser.crash;
+import android.support.annotation.Nullable;
+
import org.chromium.base.Log;
import org.chromium.base.VisibleForTesting;
@@ -102,7 +104,7 @@ public class CrashFileManager {
}
public File[] getMinidumpWithoutLogcat() {
- return getMatchingFiles(MINIDUMP_FIRST_TRY_PATTERN);
+ return listCrashFiles(MINIDUMP_FIRST_TRY_PATTERN);
}
public static boolean isMinidumpMIMEFirstTry(String path) {
@@ -239,35 +241,12 @@ public class CrashFileManager {
}
/**
- * Returns all minidump files that could still be uploaded through the normal pipeline.
- * I.e. forced uploads are not included. Only returns files that we have tried to upload less
- * than {@param maxTries} number of times.
- */
- public File[] getAllMinidumpFiles(int maxTries) {
- return getFilesBelowMaxTries(getMatchingFiles(MINIDUMP_PATTERN), maxTries);
- }
-
- /**
* Returns all minidump files that could still be uploaded, sorted by modification time stamp.
* Forced uploads are not included. Only returns files that we have tried to upload less
* than {@param maxTries} number of times.
*/
- public File[] getAllMinidumpFilesSorted(int maxTries) {
- File[] minidumps = getAllMinidumpFiles(maxTries);
- Arrays.sort(minidumps, sFileComparator);
- return minidumps;
- }
-
- @VisibleForTesting
- protected File[] getAllFilesSorted() {
- File crashDir = getCrashDirectoryIfExists();
- if (crashDir == null) {
- return new File[] {};
- }
-
- File[] files = crashDir.listFiles();
- Arrays.sort(files, sFileComparator);
- return files;
+ public File[] getAllMinidumpFiles(int maxTries) {
+ return getFilesBelowMaxTries(listCrashFiles(MINIDUMP_PATTERN), maxTries);
}
public void cleanOutAllNonFreshMinidumpFiles() {
@@ -279,7 +258,7 @@ public class CrashFileManager {
}
Set<String> recentCrashes = new HashSet<String>();
- for (File f : getAllFilesSorted()) {
+ for (File f : listCrashFiles(null)) {
// The uploads.log file should always be preserved, as it stores the metadata that
// powers the chrome://crashes UI.
if (f.getName().equals(CRASH_DUMP_LOGFILE)) {
@@ -313,7 +292,7 @@ public class CrashFileManager {
*/
@VisibleForTesting
static File[] getFilesBelowMaxTries(File[] unfilteredFiles, int maxTries) {
- List<File> filesBelowMaxTries = new ArrayList<>();
+ List<File> filesBelowMaxTries = new ArrayList<>(unfilteredFiles.length);
Ilya Sherman 2016/10/15 00:02:53 nit: This change seems unrelated to the rest of th
for (File file : unfilteredFiles) {
if (readAttemptNumber(file.getName()) < maxTries) {
filesBelowMaxTries.add(file);
@@ -323,26 +302,30 @@ public class CrashFileManager {
}
@VisibleForTesting
- File[] getMatchingFiles(final Pattern pattern) {
- // Get dump dir and get all files with specified suffix. The path
- // constructed here must match chrome_paths.cc (see case
- // chrome::DIR_CRASH_DUMPS).
- File crashDir = getCrashDirectoryIfExists();
- if (crashDir == null) {
+ File[] listCrashFiles(@Nullable final Pattern pattern) {
Ilya Sherman 2016/10/15 00:02:53 What does the "crash" in this method name mean?
Ilya Sherman 2016/10/15 00:02:53 Please add documentation for this method. In part
+ File crashDir = getCrashDirectory();
+
+ FilenameFilter filter = null;
+ if (pattern != null) {
+ filter = new FilenameFilter() {
+ @Override
+ public boolean accept(File dir, String filename) {
+ return pattern.matcher(filename).find();
+ }
+ };
+ }
+ File[] minidumps = crashDir.listFiles(filter);
Ilya Sherman 2016/10/15 00:02:53 It's not really correct to name this variable "min
+ if (minidumps == null) {
+ Log.w(TAG, crashDir.getAbsolutePath() + " does not exist or is not a directory");
return new File[] {};
}
- File[] minidumps = crashDir.listFiles(new FilenameFilter() {
- @Override
- public boolean accept(File dir, String filename) {
- return pattern.matcher(filename).find();
- }
- });
+ Arrays.sort(minidumps, sFileComparator);
return minidumps;
}
@VisibleForTesting
File[] getAllUploadedFiles() {
- return getMatchingFiles(UPLOADED_MINIDUMP_PATTERN);
+ return listCrashFiles(UPLOADED_MINIDUMP_PATTERN);
}
@VisibleForTesting
@@ -350,20 +333,6 @@ public class CrashFileManager {
return new File(mCacheDir, CRASH_DUMP_DIR);
}
- @VisibleForTesting
- File getCrashDirectoryIfExists() {
- File crashDirectory = getCrashDirectory();
- if (!crashDirectory.exists()) {
- Log.w(TAG, crashDirectory.getAbsolutePath() + " does not exist!");
- return null;
- }
- if (!crashDirectory.isDirectory()) {
- Log.w(TAG, crashDirectory.getAbsolutePath() + " is not a directory!");
- return null;
- }
- return crashDirectory;
- }
-
public File createNewTempFile(String name) throws IOException {
File f = new File(getCrashDirectory(), name);
if (f.exists()) {
@@ -390,7 +359,7 @@ public class CrashFileManager {
* @return The matching File, or null if no matching file is found.
*/
File getCrashFileWithLocalId(String localId) {
- for (File f : getAllFilesSorted()) {
+ for (File f : listCrashFiles(null)) {
// Only match non-uploaded or previously skipped files. In particular, do not match
// successfully uploaded files; nor files which are not minidump files, such as logcat
// files.
@@ -413,6 +382,6 @@ public class CrashFileManager {
}
private File[] getAllTempFiles() {
- return getMatchingFiles(TMP_PATTERN);
+ return listCrashFiles(TMP_PATTERN);
}
}

Powered by Google App Engine
This is Rietveld 408576698